rotation and flip between images from Leginon and DM
Added by Zhiheng Yu over 10 years ago
Hi Anchi,
Most likely this was covered somewhere in the installation instruction. But I could not find it easily. The images from a K2 camera as recorded in Leginon has a rotation and flip relative to that taken in DigitalMicrograph. Where should I change the setting to make the Leginon image appear in the same orientation?
Thank you very much,
Zhiheng
Replies (3)
RE: rotation and flip between images from Leginon and DM - Added by Anchi Cheng over 10 years ago
You want to make leginon image the same orientation as your viewing screen or Flucam. Change the orientation in DM/Camera/Camera configuration.
See http://emg.nysbc.org/projects/leginon/wiki/Gatan_K2_installation_and_setup in the section of "Change Flag in pyscope/dmsem.py if you have DM 2.30 version and requires flip/rotation to give the Leginon orientation". This also applies to 2.31 version.
RE: rotation and flip between images from Leginon and DM - Added by Zhiheng Yu over 10 years ago
Hi Anchi,
On our two Krios, the camera configurations in DM were set after the K2 installation so that the images taken in DM have same orientation as those on the Flucam. The problem I was initially reporting was that the image taken in Leginon has different orientation compared to that taken in DM. The frames saved by Leginon is in another different orientation. Please see the three attached screenshots (details below). I was puzzled by this for a while and thus asked if there is a setting in Leginon to match the orientation. From your reply now I think it is most likely the DM2.30 flag in dmsem.py. We installed a pre 3.0 version and there is no entry for this flag even in dmsem.py. We will try to install the latest version of Leginon in the coming weeks and see if that fix the issue.
The first screenshot is a comparison between an image taken in Leginon and an image taken in DM (through acquire view which has the same orientation as on the Flucam). The second screenshot is between the integrated image taken in Leginon and the Leginon saved frames on the K2 computer. The third screenshot is between Leginon saved frames versus frames taken in DM 2.30 directly through dose fractionation aquire.
By the way, Leginon still works great in data collection despite this orientation issue. The only inconvenience occurs while applying gain correction to the Legion saved frames since the gain must be in the same orientation as the saved frames. We just needed to do one extra step of processing the gain image first to make it in the same orientation as the saved frame.
Zhiheng
RE: rotation and flip between images from Leginon and DM - Added by Anchi Cheng over 10 years ago
Zhiheng,
Sorry for late reply. What you pointed out is a development problem that I need to solve. The direct detection camera make, the microscope and position on which it is mounted, and in the case of K2, mode of data collection (classical or dose fractionation), as well as the version of software (DM and SerialEMCCD) affects the orientation of the integrated image returned, and independently the orientation of the movie frames. We developed on our scope/camera/software version combination, coded in the necessary transformation so that it work for our case, but as more installations are made, the variation has increased and I need to work on a more universal solution than relying on local changes made at each lab. Unfortunately, I can't test this new solution for another three weeks or so.
Your particular problem comes from the fact that K2 installed on Krios is oriented 180 degrees from how it is on Tecnai where our original, currently hard-coded, orientation came from.
While the upgrade to 3.0 will give you the flag, it will probably not solve the problem. The DM230 flag only solves a lower level orientation differences in how to tell DM to collect an 90 or 270 degree rotated dose fractionation image.
Until I get to implement the universal solution and put these variations in a configuration file or gui, you will need to find the code in pyscope/dmsem.py to change them. Here are the relevant parts:
The part that most likely to solve the problem for the frames is where we define the orientation to send to SerialEMCCD. This is in the function calculateFileSavingParams.
rotation = 270 # degrees flip = 0 # 0=none, 4=flip columns before rot, 8=flip after rot_flip = rotation / 90 + flip
Change the rotation line is likely to have the effect you want.
rotation = 90 # degrees
Make sure you removes .pyc file before trying the modification. I've seen cases where it was not recompiled on Windows. Concentrate on making the frames saved to be in the same orientation as in the Fluscreen (or DM while in acquire mode). I have not tested this thorough. It is possible that the frame orientation does not change through this parameter at all in your version of DM/SerialEMCCD. Beware that Leginon image display puts image origin at top-left, unlike Ximdisp or 3Dmod. Use the same display program when you play with this. If the frame orientation does not change with your code change, you do have to use the post-process option for transforming the gain reference or the frames as we do in Appion for some other direct detectors.
Once you are certain of the frames, you can adjust the transformation to the integrated image sent back to Leginon when dose fractionation mode is on.
This block of code deals with the orientation of the integrated image returned to Leginon when dose fractionation mode is on (i.e., when you have "save frame" checkbox activated).
# workaround dose fractionation image rotate-flip not applied problem if self.save_frames or self.align_frames: image_shape = image.shape # assume number of columns is less than rows image_dtype = image.dtype image = numpy.fliplr(numpy.rot90(image,1))
I think you need to change the last line to
image = numpy.fliplr(numpy.rot90(image,3))