Load stitched image and targets into Leginon & submit them to next acquisition class
Added by Joel Lüthi almost 9 years ago
Hi everyone,
I am currently setting up a system to automatically detect DNA forks on EM grids. One of the critical steps is to acquire images at a screening resolution, do external processing and feed the results back into Leginon. Currently, I’m stuck at getting the data back into Leginon in a way that it can submit the target for the final acquisition.
We are working with a grid with many squares. To avoid boundary problems in the detection of DNA molecules, we need to export the acquired images of one square and stitch them together before detecting dna molecules.
As a targetfinder class to start the processing and take back the results, I modified a rasterfinder.py class (dnafinder.py). By using the metadata in the imagedata and information from the events triggering the targetfinding class, I can give the necessary information about the files to be processed to my python script doing the processing (mostly done in the "findTargets" function). I can also take the results back into leginon, but currently not in a form that they can be submitted for final high-mag acquisition.
Currently, I load my stitched image with the "self.readImage(filename)" function (which is using numpil.read to actually read in the image) and import the targets as a list of x,y tuples. I can display the targets on the image in Leginon by using the "self.setTargets(targets, 'acquisition', block=True)" function. They are then displayed on the correct location on the image that I loaded.
How can I either change the import or process the image in such a way, that I can then submit these targets to the next acquisition class?
Does my image need to be added to the Leginon database? Does the image or the target list need to be converted to a specific Leginon class?
How can I add the necessary metadata, especially the stage position (which I know from the images acquired before that were stitched together) to this new image, so that Leginon will know where these targets are on the grid?
Any help or examples would be much appreciated. I tried using existing targetfinder classes as examples, but couldn’t figure out this part.
Best,
Joel
I attached the dnafinder.py class and its GUI class DnaFinder.py for reference on how I implemented it so far.
dnafinder.py (5.05 KB) dnafinder.py | targetfinder class | ||
DnaFinder.py (9.88 KB) DnaFinder.py | GUI class |
Replies (5)
RE: Load stitched image and targets into Leginon & submit them to next acquisition class - Added by Anchi Cheng almost 9 years ago
I will need to think about this a bit.
Usually the targets are saved as they appear in the gui after setTarget on an image that has associated scope and camera meta data. Which is why it can
be published to the next node. You stitched image has no mata data at the moment, so we need to find a way of giving it one.
Is the stitching more than just putting the images together according to its stage position like the way Square Targeting node (MosaicClickTargetFinder class) does ? If so, an accurate targeting will require knowing the meta position so that targets will be moved locally on the sub-image, not just the center of the stitched image. The latter of course makes metadata association fairly straight forward if one of the sub image is centered.
RE: Load stitched image and targets into Leginon & submit them to next acquisition class - Added by Joel Lüthi almost 9 years ago
Hey Anchi,
Thanks for the quick response! Yes, setTarget already seems to work for me to apply the targets to the stitched image.
The stitching is actually a bit more complicated than the one in MosaicClickTargetFinder. I use a Fiji Plugin that repeatedly optimizes the alignment between adjacent tiles according to features in the image. The square always has 9 tiles (3x3), so it’s fairly simple. There is movement between all the squares, which is also recorded in a log file. But incorporating this should hopefully not be necessary. The average movement is below 1% of the image size and the final acquisition is not at that high a magnification (11000x, pixel size 1nm).
Thus, I suppose that if I can give the meta-information e.g. from the center acquired image to the complete stitched image, the targeting should hopefully be good enough for my purposes. But I couldn’t figure out so far how I would give the meta-information to an image that I’m just loading in Leginon. Does the image need to be in the database for this? Or can I just make it a specific class and assign the variables?
Oh, and how is the stage position saved in the meta-information? Is it the center of the image or a specific corner?
Best & thanks a lot for your help!
Joel
RE: Load stitched image and targets into Leginon & submit them to next acquisition class - Added by Anchi Cheng almost 9 years ago
The stage position is saved as part of the full scope condition when the image is acquired. The database entry of the image (AcquisitionImageData instance, and often named imagedata or imdata) has references to them.
I made an example node based on the simpler ClickTargetFinder class. Please take a look.
When I register the node and use it in "Exposure Targeting" node of any MSI application, it reads my local test.txt targets and produce processable targets on my fake image.
Basically, I am saving the fake mosaic_image into database based on center_imdata with a few necessary modification. This way the targets will be saved with an indirect reference to the center image scope condition. With the camera condition matchs mosaic_image, it also knows where to put the targets in the database record since it is done relative to the center of the image not corner as the targets you passed in from the text file.
In the code I pass center_imdata from processImageData under the condition I defined there. You will have to decide how you pass that information.
A simple query of filename , for example, with leginondata.AcquisitionImageData will give you an imagedata object that you need as center_imdata.
Note that you will not be able to do target adjustment with targets from this saved mosaic image because Leginon can not get similar image by reproducing the scope and camera condition saved with the imdata object.
The class is committed to leginon and logged as Issue #3870.
filetargetfinder.py (5.88 KB) filetargetfinder.py |
RE: Load stitched image and targets into Leginon & submit them to next acquisition class - Added by Joel Lüthi almost 9 years ago
Hi Anchi,
Thanks a lot! That was a great help!! :)
I adapted my script according to the explanations you gave here and I've now been able to let my application acquire images overnight, with all the targets published correctly and acquired nicely.
The meta-data of the center image was good enough for the whole square so that the targets were always in the published regions of interest.
Your demo code and explanations helped a lot in getting this done in a timely manner. So thank you very much for taking the time!
Best,
Joel
RE: Load stitched image and targets into Leginon & submit them to next acquisition class - Added by Anchi Cheng almost 9 years ago
I am very glad that it works out. It is great to have people extending Leginon's usage. Looking forward to your next idea.