Image Registration problems

fiji
imagej
registration
Tags: #<Tag:0x00007fa30b950280> #<Tag:0x00007fa30b957d28> #<Tag:0x00007fa30b957670>

#1

Hi all,

I have a sequence of images in a stack that I would like to match up. Each image has two points that were externally marked (bottom left and bottom right). If these two points could be matched up in all of the images, I would be able to establish a co-ordinate system applicable to all images in the stack.

I have used Plugins -> Registration -> Descriptor Based Series Registration on the Fiji plugin which is able to register simple images (example 1) I have created in MS Paint but will not work on the images I need it to work on (example 2). Any insight into why it is not working for the second set of images or any alternative method would be greatly appreciated.

Examples of the images I am using are below.

Cheers!

1
2

DP237%20and%20DP277%20(JPG)DP257%20and%20DP297%20(JPG)


#2

Good day David,

please let me ask some further questions regarding the second pair of images:

  1. Are these images realistic or sinply another kind of toy-example
  2. What kind of transformations are necessary (a priori knowledge) to match the images,
    pure translations or more complicated ones such as rotations, scale-changes, etc.
  3. Why do the images have such low contrast?

In any case please post typical raw images in the original TIF- or PNG-format. No JPG-format though, because JPG introduces artifacts! You may also post images as Zip-archives.

Regards

Herbie


#3

Hi Herbie,

Thank you for your prompt reply!

These images are realistic, I can increase the contrast if that would help.
The images only need a simple translation. The two black dots at the bottom left and bottom right are in a straight line at a known distance and it is the same in each image. Some examples of the images in TIF-format are below.

Film_measurements.zip (7.6 MB)


#4

David,

thanks for the images!

I shall soon present an ImageJ macro that does what you want.

Stay tuned

Herbie


#5

Thanks Herbie, that would be brilliant! Very much appreciated! :smile:


#6

Just some more questions David,

the stacks represent 16bit color images.

  1. From my point of view color doesn’t play a role for matching. Is that correct?
  2. The Zip-archive contains 13 16bit color images. Which one serves as a matching reference?
    Should all 13 images be aligend and to which reference image?

Regards

Herbie


#7

Hi Herbie,

You’re correct, the colour does not play any role in matching.

There is no real preference as to which image is used as the matching reference. The geometry of the dark dots should be the same in each image, just translated relative to each other. The first image is as good as any to use and all the images aligned to it if possible!

With thanks,

David


#8

Herbie is awesome and I am sure his/her solution will be great. Nonetheless, I just wanted to get my two cents in. You could also consider installing an using StackReg. You said they just need translation but based on the fact that you states the dots formed a line, I am guessing you might also want rotation? Regardless, you could use StackReg on a cropped stack with just the dots. Then use a macro to access the results table and transform the full-size stack.


#9

Good day David,

sorry for the delay, internet-connection was down here for half a day.

// imagej-macro "alignImages" (Herbie G., 11. July 2018)
requires( "1.52d" );
setForegroundColor(0, 0, 0);
src = getDirectory("Choose a directory!");
dst = File.getParent(src)+"/"+File.getName(src)+"_aligned/"
File.makeDirectory(dst);
setBatchMode(true);
f = getFileList(src);
mxLen = 0;
for ( i=0; i<f.length; i++ ) {
    len = File.length(src+f[i]);
    if (len>mxLen) { mxLen=len; idx = i; }
}
open(src+f[idx]);
h = getHeight(); w = getWidth();
close(f[idx]);
if (w>h) sz = w; else sz = h;
sz = nextPowerOfTwo( sz );
open(src+f[0]);
binarySpots( sz, "ref" );
selectImage(f[0]);
saveAs("tiff", dst+f[0]);
close(f[0]);
for ( i=1; i<f.length; i++ ) {
    open(src+f[i]);
    binarySpots( sz, "img" );
    align( sz, f[i] );
    saveAs("tiff", dst+f[i]);
    close(f[i]);
}
close("ref");
setBatchMode(false);
exit();
//
function nextPowerOfTwo( size ) {
    size--;
    for ( i = 1; i <= 32; i *= 2 ) { size = size | (size >> i); }
    size++;
    return size;
}
function getMarkers() {
    run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
    run("Select All");
    setKeyDown("alt");
    p = getProfile();
    Array.reverse(p);
    y = 0; i = 0;
    do {
        if (p[i]>0&&y==0) y = i;
        i++;
    } while (p[i]==0||y==0||i<y+5);
    run("Select None");
    return (y+i)*0.5;
}
function binarySpots( size, nme ) {
    run("Canvas Size...", "width="+size+" height="+size+" position=Center zero");
    run("Z Project...", "projection=[Sum Slices]");
    rename(nme);
    setAutoThreshold("Moments no-reset");
    run("Convert to Mask");
    run("Invert LUT");
    doWand(0, size*0.5);
    run("Make Inverse");
    fill();
    fillRect(0,0,size,size-getMarkers());
}
function align( size, nme ) {
    szH = 0.5*size;
    run("FD Math...", "image1=img operation=Correlate image2=ref result=Result do");
    getRawStatistics(N, mn, mi, mx);
    run("Find Maxima...", "noise="+(mx-1)+" output=[Point Selection] exclude");
    getSelectionCoordinates(x, y);
    err = x.length>1;
    x = szH-x[0]; y = szH-y[0];
    close("Result");
    close("img");
    selectImage(nme);
    if ( x<-szH*0.5||y<-szH*0.5||err ) {
        print("Could not align: "+nme);
    } else {
        run("Translate...", "x="+x+" y="+y+"  interpolation=None stack");
    }
}

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it.

Requirements etc:

  1. The macro assumes that all images (16bit color stacks) are in the same folder. Therefore it asks you first to choose this folder.
  2. The aligned images are stored in another folder having the same name plus a the suffix “_aligned”.
  3. Because your sample images are of different sizes, the aligned images all have the same size. (They are square sized with sides that are power of two.)
  4. Sample image “DP285 and DP235.tif” can’t be aligned because the right marker point fuses with the background. (It can’t be recognized.)
  5. If an image can’t be aligned, a message with its name is posted to the Log-window.

HTH

Herbie


#10

Good day Andrew,

let’s wait and see how awesome my result is this time …

I fear the very problem is not really suited for Registration plugins.

  1. The images are in fact 16 bit RGB-stacks.
  2. The images have different sizes.
  3. Most of the image content varies dramatically from image to image.

Positive: In fact translatory alignments are sufficient.

Regards

Herbie


#11

Hi Andrew, thank you for your contribution. I tried using StackReg but even on the ‘simple’ images it just seemed to freeze. I’m not very experienced with ImageJ so it is probably my own mistake. Thankfully Herbie’s method works but nonetheless thanks for your help!


#12

Hi Herbie,

Thank you so much for your help, it works perfectly! Its no problem to retake any of the images that can’t be aligned so that won’t be a major issue! I’m now able to combine the images in a stack and use the same origin which really increases the efficiency of what I’m trying to do!

Kind regards,

David