Bug #4933
closednon-square images not displaying in web browser
Added by Gabriel Lander over 7 years ago. Updated over 6 years ago.
0%
Description
We recently updated to the trunk, and now none of the full size K2 images are showing in the image viewers. We now see this in place of the image:
"REDUX ERROR image dimensions 1023,3458 do not allow..."
If you click on the image, the micrograph shows up normally in the larger window, so this must have something to do with the scaling for display.
I recall Neil saying he changed something to fix the weird aliasing effects of scaling the non-square images to 512x512, I imagine this is related to this update.
Files
emweb_problems.png (100 KB) emweb_problems.png | Gabriel Lander, 05/17/2017 01:37 PM | ||
17mar10b_4s_b_00009gr_00005sq_v01_00013hl4_00006edhi-a.mrc (54.3 MB) 17mar10b_4s_b_00009gr_00005sq_v01_00013hl4_00006edhi-a.mrc | Gabriel Lander, 05/17/2017 01:40 PM | ||
DoG_picks Image viewer-01.jpg (469 KB) DoG_picks Image viewer-01.jpg | Gabriel Lander, 05/31/2017 12:26 AM |
Updated by Neil Voss over 7 years ago
I did not add any new warning messages, and did a grep for the warning you have and had no hits.
I only changed two lines of code and moved a section to a later part, commit:c7a84ce2 and commit:f8f8b6a7
Updated by Anchi Cheng over 7 years ago
- Affected Version changed from Appion/Leginon 3.2 to Appion/Leginon 3.3
I tested with simulator on my Mac, and it worked fine. However, Gabe's error suggests that myamiweb/inc/image.inc fed redux the wrong shape of image. Don't know how that happened, but I include here my redux.log that may help debugging:
REQUEST: pipeline=standard&filename=/Users/acheng/testdata/leginon/17apr28a/rawdata/17apr28a_00001en.mrc&shape=989x1024&scaletype=stdev&scalemin=-5&scalemax=5&oformat=JPEG&overlaycolor=0.35 Running Read(4383784400,{'info': False, 'filename': '/Users/acheng/testdata/leginon/17apr28a/rawdata/17apr28a_00001en.mrc'}) Running Shape(4383784336,{'shape': (989, 1024)}) Running Scale(4383784656,{'scalemin': -5.0, 'scalemax': 5.0, 'scaletype': 'stdev'}) Running Format(4383784464,{'oformat': 'JPEG', 'rgb': False, 'overlay': '', 'overlaycolor': 0.35})
I think the error message comes from numpy. Gabe, it may be a good idea to find and post here the redux.log from your webserver.
Updated by Anchi Cheng over 7 years ago
Got the complete error message from JC.
Running Read(335544656,{'info': False, 'filename': '/gpfs/group/em/leginon/csandate/17apr25a/rawdata/17apr25a_G3_00027gr_00016sq_v01_00031hl_00004ed.mrc'}) Running Shape(335544720,{'shape': (512, 494)}) REDUX ERROR 1493296147 image dimensions 1023,3458 do not allow binning by 2,7 ..... "/opt/applications/myami/current/lib/python2.6/site-packages/redux/pipes/shape.py", line 103, in run output = pyami.imagefun.bin(output, binfactors[0], binfactors[1]) File "/opt/applications/myami/current/lib/python2.6/site-packages/pyami/imagefun.py", line 434, in bin return numextension.bin(image, binning0, binning1) ValueError: image dimensions 1023,3458 do not allow binning by 2,7
Gabe, how can there be a full K2 image at this dimension ? You should restart DM. This happens to us some times. We ask K2 to work to hard, it gets confused some times.
Updated by Gabriel Lander over 7 years ago
this is definitely an issue with the code somehow, since we have this same error showing up when we try to view older datasets.
Updated by Anchi Cheng over 7 years ago
Redux log will help to sort this out. If you give an example, I happen to have a fresh installation that I can check against. Need the exact image height and width at the minimal.
Updated by Neil Voss over 7 years ago
If you could upload a single micrograph, I could test it as well.
Updated by Gabriel Lander over 7 years ago
- File emweb_problems.png emweb_problems.png added
- File 17mar10b_4s_b_00009gr_00005sq_v01_00013hl4_00006edhi-a.mrc 17mar10b_4s_b_00009gr_00005sq_v01_00013hl4_00006edhi-a.mrc added
attached is the error we see and an example micrograph
Updated by Anchi Cheng over 7 years ago
Gabe, Please post redux.log regarding the image. It should start with REQUEST and has the filepath. You should get two requests for the image, the first time is to get INFO of the image, the second time the actual image. The image request would have "oformat=JPEG" as an option. We need to know if it got the info wrong from the start.
Updated by Neil Voss over 7 years ago
This might be related to the binning code. I did not change it, but I saw that it was weird. It tries to find a separating bin values for each dimension (x,y), and doing this could cause your (3710x3838) image to possibly become (1023,3458) though I am not sure why.
binfactors = [] zoomfactors = [] for i in range(len(shape)): zoomfactors.append(float(shape[i])/float(input.shape[i])) ## for rgb, binning not implemented if is_rgb: binfactors.append(1) continue else: ## added int() to avoid future python 3 problems binfactors.append(int(input.shape[i] / shape[i])) # bin <1 not allowed (when output bigger than input) if binfactors[i] == 0: binfactors[i] = 1 # check original shape is divisible by new shape if input.shape[i] % shape[i]: # binning alone will not work, try initial bin, then interp start = binfactors[i] for trybin in range(start, 0, -1): if input.shape[i] % trybin: continue binfactors[i] = trybin zoomfactors[i] *= binfactors[i] break else: # just use bin zoomfactors[i] = 1.0
Updated by Anchi Cheng over 7 years ago
- Assignee changed from Neil Voss to Gabriel Lander
Gabe,
The old code bin first and then zoom, the new one zoom first and then bin. I think the number precision on your machine, probably associated with the scipy version is different from Neil's or mine.
Try run this test script:
import numpy import scipy.ndimage zoom = (float(512)/float(3838)) * 2 print 'zoom',zoom input = numpy.ones((3838,)) output = scipy.ndimage.zoom(input, zoom, order=1) print output.shape
On mine, I get
zoom 0.26680562793121415 1024
with python 2.7.13, scipy 0.15.1 on my MacBookPro. If I am right, you get 1023 at the end from rounding error.
Neil, you may have find a way to accomodate this rounding error.
By the way, To test redux pipe: Run this in redux/pipes in python command
import numpy import shape input_array= numpy.ones((3710,3838)) s = shape.Shape(shape=(512,512)) # The kwargs is needed but don't seem to be used in run command. output_array = s.run(input_array,(512,512)) print output_array.shape
Updated by Anchi Cheng over 7 years ago
Maybe changing the multiplication of binfactor should be done ab initial.
float(512*2)/float(3838)
Updated by Neil Voss over 7 years ago
Nice catch, I can try to fix, but it would have to wait until Monday. I am doing a Leginon 3.1 to 3.2 upgrade on the Northwestern JEOL today.
Updated by Anchi Cheng over 7 years ago
When I did the test I posted earlier (By the way, I fixed a typo there) from python command line, there is a warning;
/Users/acheng/miniconda/lib/python2.7/site-packages/scipy/ndimage/interpolation.py:549: UserWarning: From scipy 0.13.0, the output shape of zoom() is calculated with round() instead of int() - for these inputs the size of the returned array has changed. "the returned array has changed.", UserWarning)
Updated by Anchi Cheng over 7 years ago
JC reported back
On python2.7.11/ scipy 0.17.0 >>> output = scipy.ndimage.zoom(input,zoom,order=1) /opt/applications/python/2.7.11/gnu/lib/python2.7/site-packages/scipy/ndimage/interpolation.py:549: UserWarning: From scipy 0.13.0, the output shape of zoom() is calculated with round() instead of int() - for these inputs the size of the returned array has changed. "the returned array has changed.", UserWarning) >>> print output.shape (1024,) On python Python2.6.6 and scipy 0.7.2 >>> output = scipy.ndimage.zoom(input,zoom,order=1) >>> print output.shape (1023,)
Updated by Neil Voss over 7 years ago
Hi Anchi, I wrote a fix yesterday, but I want to test it more for speed before I push it to trunk.
I decided to use scipy.misc.imresize instead of scipy.ndimage.zoom because of the stupid rounding error:
output = scipy.misc.imresize(output, shape, interp='bilinear')
Updated by Neil Voss over 7 years ago
Hi Anchi, What is the status of openCV in CentOS 6, it seems to be much faster at this task than scipy:
https://www.kaggle.com/zfturbo/test-speed-cv2-vs-scipy
import time import numpy import shape input_array= numpy.ones((3710,3838)) s = shape.Shape(shape=(512,512)) t0 = time.time() output_array = s.run(input_array,(512,512)) print time.time() - t0 print output_array.shape
Updated by Neil Voss over 7 years ago
- Status changed from Assigned to In Test
Gabe and Anchi, please test latest commit commit:de2df87f If you have opencv-python installed it will be much faster as well!
I tested on CentOS6 and CentOS7 with various image types and sizes.
Updated by Sargis Dallakyan over 7 years ago
Hi Niel, thanks for the update. CentOS6 provides opencv-python.x86_64 2.0.0-12.el6 package. However, this package doesn't provide cv2. I've used opencv/2.4.13 module that we have available on SEMC cluster and added it on our redux server. I've added this piece of code in try/except to make sure it can import cv2:
import sys sys.stderr.write('\n**using cv2\n')
I've tested this on Gabe's image and overall timing results are not different between two versions.
[root@node02 dev]# time /root/dev/redux/bin/redux --filename=/gpfs/leginon/sargis/17mar10b/17mar10b_4s_b_00009gr_00005sq_v01_00013hl4_00006edhi-a.mrc --oformat=PNG --shape="(512,512)" > test.png *** Using custom copy of fftw3 wrapper calc_fftw3: 24 CPUs found, setting threads=24 **power thread lock in effectWarning: You have not configured Images path in leginon.cfg! Using current directory. NOT IN MEMORY: Format(83939664,{'oformat': 'PNG', 'rgb': False, 'overlay': '', 'overlaycolor': 0.10000000000000001}) IN FILE: Format(83939664,{'oformat': 'PNG', 'rgb': False, 'overlay': '', 'overlaycolor': 0.10000000000000001}) real 0m21.975s user 0m18.454s sys 0m3.495s [root@node02 dev]# export PYTHONPATH=/root/dev:${PYTHONPATH} [root@node02 dev]# time /root/dev/redux/bin/redux --filename=/gpfs/leginon/sargis/17mar10b/17mar10b_4s_b_00009gr_00005sq_v01_00013hl4_00006edhi-a.mrc --oformat=PNG --shape="(512,512)" > test.png *** Using custom copy of fftw3 wrapper calc_fftw3: 24 CPUs found, setting threads=24 **power thread lock in effect **using cv2 Warning: You have not configured Images path in leginon.cfg! Using current directory. NOT IN MEMORY: Format(24725136,{'oformat': 'PNG', 'rgb': False, 'overlay': '', 'overlaycolor': 0.10000000000000001}) IN FILE: Format(24725136,{'oformat': 'PNG', 'rgb': False, 'overlay': '', 'overlaycolor': 0.10000000000000001}) real 0m21.817s user 0m18.378s sys 0m3.410s [root@node02 dev]# time /root/dev/redux/bin/redux --filename=/gpfs/leginon/sargis/17mar10b/17mar10b_4s_b_00009gr_00005sq_v01_00013hl4_00006edhi-a.mrc --oformat=PNG --shape="(512,512)" > test.png *** Using custom copy of fftw3 wrapper calc_fftw3: 24 CPUs found, setting threads=24 **power thread lock in effect **using cv2 Warning: You have not configured Images path in leginon.cfg! Using current directory. NOT IN MEMORY: Format(24725136,{'oformat': 'PNG', 'rgb': False, 'overlay': '', 'overlaycolor': 0.10000000000000001}) IN FILE: Format(24725136,{'oformat': 'PNG', 'rgb': False, 'overlay': '', 'overlaycolor': 0.10000000000000001}) real 0m21.980s user 0m18.520s sys 0m3.432s [root@node02 dev]# time /root/dev/redux/bin/redux --filename=/gpfs/leginon/sargis/17mar10b/17mar10b_4s_b_00009gr_00005sq_v01_00013hl4_00006edhi-a.mrc --oformat=PNG --shape="(512,512)" > test.png *** Using custom copy of fftw3 wrapper calc_fftw3: 24 CPUs found, setting threads=24 **power thread lock in effect **using cv2 Warning: You have not configured Images path in leginon.cfg! Using current directory. NOT IN MEMORY: Format(24725136,{'oformat': 'PNG', 'rgb': False, 'overlay': '', 'overlaycolor': 0.10000000000000001}) IN FILE: Format(24725136,{'oformat': 'PNG', 'rgb': False, 'overlay': '', 'overlaycolor': 0.10000000000000001}) real 0m21.997s user 0m18.377s sys 0m3.594s
Updated by Neil Voss over 7 years ago
Hi Sargis, I did a try/except ImportError, so it should work if opencv/cv2 is not available.
Updated by Gabriel Lander over 7 years ago
Ok display working for 3840x3584 images, but not super resolution (7680x7168)
From JC:
ok. that has been quite painful...I downgraded fs to 0.4.0 (from 2.0.1), updated myami/trunk and installed opencv-python.
It is running now.
Still reporting some issues:
Running Read(139853629143824,{'info': False, 'filename': '/gpfs/group/em/leginon/cmurin/17may23e/rawdata/17may23e_A_00018gr_00034sq_v01_00002hl_00003ed.mrc'})
Running Shape(139853629144016,{'shape': (256, 247)})
REDUX ERROR 1495651571 image dimensions 3840,3584 do not allow binning by 14,15
Traceback (most recent call last):
File "/opt/applications/myami/trunk/lib/python2.7/site-packages/redux/server.py", line 37, in run_process
result = pipeline.process(**kwargs)
File "/opt/applications/myami/trunk/lib/python2.7/site-packages/redux/pipeline.py", line 144, in process
result = pipe(result)
File "/opt/applications/myami/trunk/lib/python2.7/site-packages/redux/pipe.py", line 163, in call
return self.run(input, **self.kwargs)
File "/opt/applications/myami/trunk/lib/python2.7/site-packages/redux/pipes/shape.py", line 58, in run
outputimg = pyami.imagefun.bin(outputimg, xbin, ybin)
File "/opt/applications/myami/trunk/lib/python2.7/site-packages/pyami/imagefun.py", line 434, in bin
return numextension.bin(image, binning0, binning1)
ValueError: image dimensions 3840,3584 do not allow binning by 14,15
Updated by Neil Voss over 7 years ago
Oops, I flipped the binning. See commit commit:53923384d
outputimg = pyami.imagefun.bin(outputimg, xbin, ybin)
should have been:
outputimg = pyami.imagefun.bin(outputimg, ybin, xbin)
Using new test set:
import time import numpy from redux.pipes import shape time.sleep(0.1) input_array = numpy.random.random((7680,7168)) s = shape.Shape(shape=(512,512)) t0 = time.time() output_array = s.run(input_array,(512,512)) print time.time() - t0 print output_array.shape
Not sure what 0.4.0 and 2.0.1 refer to.
Updated by Gabriel Lander over 7 years ago
Okay the images are now displaying properly. BUT there is an issue with displaying DoG picks in the Appion image viewer (haven't checked with template picks yet, but I imagine it's the same) where at the top of the image the pick and the particle align, but as you go to the bottom of the image, they are further separated.
Updated by Neil Voss over 7 years ago
Anchi, is the shape module supposed to preserve aspect ratio, because it is scaling (7680,7168) to (512,512) which be scaling differently in both x and y.
Updated by Anchi Cheng over 7 years ago
redux shape does not preserve aspect ratio. The shape input needs to give the right shape which is handled in myamiweb/inc/imageutil.inc.
However, I just checked with an image of 5120 x 3840.
The redux request is the same in trunk and 3.2 as
REQUEST: pipeline=standard&filename=/Users/acheng/testdata/leginon/17may31a/rawdata/17may31a_00001en.mrc&shape=512x384&scaletype=stdev&scalemin=-5&scalemax=5&oformat=JPEG&overlaycolor=0.35
But the trunk version gives back a 512x512 image. 3.2 gives back 512 x 384. There is a bug in your shape function.
Updated by Anchi Cheng over 7 years ago
- Status changed from In Test to Assigned
Updated by Neil Voss over 7 years ago
Fixed, there was a typo in one of the shapes, I also discovered that opencv uses a backwards shape, see commit commit:b1e5cb72
Using non-square request test set:
import time import numpy from redux.pipes import shape s = shape.Shape(shape=(512,478)) time.sleep(0.1) input_array = numpy.random.random((7680,7168)) t0 = time.time() output_array = s.run(input_array,(512,478)) print time.time() - t0 print output_array.shape input_array = numpy.random.random((7680,7168,3)) t0 = time.time() output_array = s.run(input_array,(512,478)) print time.time() - t0 print output_array.shape print "done"
Updated by Gabriel Lander over 6 years ago
- Status changed from Assigned to Closed