Feature Extraction (Extract SIFT/MOPS Correspondences) via command line

Is there a way to run the mpicbg (Feature Extraction -> Extract SIFT/MOPS Correspondences) completely without GUI, say via command line? I guess that the landmarks would need to be stored and/or communicated for actual transformation/registration using another application.
Any ideas or help is highly appreciated. Thank you!

From the code here


I see you could write a script that calls what you need, here in Groovy
#@ImagePlus imp1
#@ImagePlus imp2

def initialSigma = 1.6f
def steps = 3
def minOctaveSize = 64
def maxOctaveSize = 1024
def fdSize = 4
def fdBins = 8
def rod = 0.92f
def maxEpsilon = 25.0f
def minInlierRatio = 0.05f 
def modelIndex = 1

import SIFT_ExtractPointRoi

def siftExtract = new SIFT_ExtractPointRoi()

// Execute the procedure
siftExtract.exec( imp1, imp2, initialSigma, steps, minOctaveSize, maxOctaveSize, fdSize, final int fdBins, rod, maxEpsilon, minInlierRatio,  modelIndex)


// Get the ROIs
def sift1 = imp1.getRoi()
def sift2 = imp2.getRoi()

// whateber else you need can be here

There is no way to recover the transform from this example of the code, but at least you get the ROIs which is what you wanted?

We can ping @axtimwalde in case there is a more elegant way to do this

In the meatime, perhaps you can tell us what you want to do with the correspondences and perhaps we can help you furtherā€¦

All the best

Oli

2 Likes

Many thanks for this, Oli.
I am currently looking at two options to proceed with the ROIā€™s:
(1) use them externally for image transformation (e.g. OpenCV)
(2) use them directly with a transform within the ImageJ/Fiji framework, such as as Landmark Correspondences (https://imagej.net/Landmark_Correspondences)

If I did (2), how would I directly pass the information to ā€œLandmark Correspondancesā€ and after registration of the moved image, save it to a specific path file (e.g. path/output.tif)?
Many thanks again,
Joe

Because you have the two images available after running sift, it should simply be a matter of showing them and running the plugin

imp1.show()
imp2.show()
IJ.run(imp1, "Landmark Correspondences", "source_image=["+imp1.getTitle()"+] template_image=["+imp2.getTitle()"+]  transformation_method=[Least Squares] alpha=1 mesh_resolution=32 transformation_class=Rigid interpolate show_matrix")

then to save the output, you could do an IJ.saveAs()

I would pink @imagejan to know if with the new Batch Processor, the last output can be automatically saved, and this step may not be needed bu I do not know right now how that could be done.

There are more elegant ways to do it, but the code here

is not readily accessible like in the example in my previous post, and would have to be rewritten as a script. Not too long but beyond the scope of what I can do here.

Best

Oli

2 Likes

Many thanks for your kind help, Oli!

Question on ā€œLandmark Correspondencesā€. There are two parameters called alpha (default: 1) and mesh resolution (default: 32). Could anyone elaborate on the exact meaning on this? The documentation on https://imagej.net/Landmark_Correspondences is a bit thin. Thank you!

These parameters are relevant for the non-affine Moving Least Squares transformation, alpha specifies the falloff of the radial wieght function around each landmark and the mesh resolution defines how fine the triangle tessellation for approximating the deformation should be (number of triangles per image width, it tries to make them approximately equilateral). For translation, rigid, similarity, affine and homograpohy, these parameters have no effect.

Check this video: https://www.youtube.com/watch?v=NwOxRmX03xs which will get you the idea.

2 Likes

Many thanks for this! Very clear.

One more question to this plugin: I see that the background is always set to RGB 0,0,0. Is there a way to edit the background to another value? Iā€™ve tried to set the color pickerā€™s foreground and background values to RGB 255,255,255 - which works for other functions in ImageJ/Fiji - but apparently is not applied for Landmark Correspondences. Thanks.

Good point, I think itā€™s not. The image is initialized as empty. This fixes it:

Ok, I uploaded this fix to the Fiji updater, please update and background should work.

1 Like

Thank you very much for this, Stefan. Works like a charm. Now itā€™s possible to literally set any color that we want. Great job!
Joe

Another question related to the background. I understood that ImageJ doesnā€˜t support transparency for RGB color mode. But if it DOES, would it be possible to do that and if, how in combo with your plugin? If not, are there alternatives to the extension of the image area (canvas), e.g. by layers or such?
The reason Iā€˜m asking is that we have to deal with the fixed and moving image to further crop it to a minimal/common area and our external code can handle very well with transparency regions. Many thanks for any suggestions you may have in advance.

ImageJ does not support transparency. The plugin code does support it in that it does not meddle with the background color. So if you manage to provide an int[] array filled with 0x00something instead of 0xffsomething as a target, you can render over transparent background, actually over all sorts of background. ImageJ does not save the transparency when you save as PNG. You will have to do a bit of scripting. Here is a tool that uses the same API to render with transparency:

Hope you find your way from here.

Cheers,
Stephan

I found another instructive piece of code:

but donā€™t do this with a script, itā€™s too slow.