Aut Correcting stack of images with differing zoom factors

imagej
plugin

#1

Hi All

I’m a noob at this so sorry if it’s a dumb question. I’ve spent some time searching and can’t find the answer.

I’m taking stacks of photos with my microscope and as the lens moves closer to the image, the result is a small movement to the right and a slightly larger image for each of the pictures.

The horizontal shift is easily fixed using Plugins>Registration>Liner stack alignment with SIFT. This does a great job.

This leaves the differing zoom factors for each image in the stack. The last image is about 30% bigger than the 1st and so after focus stacking the halos are quite bad.

Is there a plugin that will analyze the images and convert them all to the same size based on the object it finds?

Thanks for reading…

Steve


#2

I suspect that your stage is out of centre. It can probably be fixed but you need to have the microscope seen by a technician or if you feel confident, dismantle the stage from the body (usually just one screw), then clean carefully the joining mechanism (usually it is a sliding piece of metal forming a dove-tail-like join) and reassemble it.
What kind of microscope is this? 30% difference? I find that figure very odd unless it has a “zoom” kind of optics. Please post some photos. Are you sure you are imaging the same slides? If your image is exactly focused on the same specimen, you cannot get a “30% larger image”; the focal point is fixed by the lens design, and so you should be at exactly the same distance of the object.


#3

Good day Gabriel,

as far as I remember, the OP uses a smart-phone camera (see here).

I have no idea how the OP operates this camera on a microscope but I’m pretty sure that exactly this problem causes the described effects.

Greetings

Herbie


#4

I see, well in that case it will be very difficult to do any robust imaging out of it.


#5

Hi both

Thanks for your replies. Herbie is correct I’m photographing with a 16MP mobile phone camera connected to one eyepiece of a Nikon SMZ-2B binocular inspection microscope. I’m using the eyepiece as it’s not a trinocular model.

The microscope has a 0.8 -5x zoom and I’m using a 10x eyepiece.

I’ve attached a couple of photos from the stack to show the lateral movement and zoom issues. These are the first and last images of an 81 image stack.

I’m sure some are rolling their eyes at my setup, but I’d really appreciate if anyone knows if there is an auto-resize plugin as per my original question that would be very helpful.

Thanks

Steve


#6

Steve,

there are ways to do this in principle but due to the fact that the scale changes are accompanied by defocussing, you’ll have to live with limited accuracy.

I would correlated the image pairs for various scale factors and do the minimization by the “Golden Section”-method. This requires some coding but an ImageJ-macro will do.

Good luck

Herbie


#7

Hi Herbie

Thanks for the tip. I’ve not used ImageJ macros before, but have plenty experience of coding so hopefully it won’t be too painful :slight_smile:
I’ll report back in 5 years when I’ve mastered macros :slight_smile:

Cheers

Steve


#8

I’ll report back in 5 years

Let’s hope I’m still alive …

Herbie


#9

Lol I hope so. Have to do some boring work now but I’ll have a go tonight.

Cheers

Steve


#10

Hi Both

After playing a little I managed to write a macro that first aligns the images and then corrects the increasing zoom factor in the stack.

It occurred to me that if the zoom factor on the final image in the 81 slice stack is 30%, I could decrease the zoom factor from slice 1 onwards by 0.3/81.

I ran the macro with these settings and stacked the images using Helicon Focus. The result was a BIG improvement in halos and worms.

So I guess what I’ve learnt is that although stacking software was options to allow lateral and zoom flexibility when analysing, the better the source images, the better the output and the lower the post processing.

So here’s the macro:

print(“Zoom Normaliser and Aligner”);

newScale = 1.0;
zoomDiff = 0.3; // Difference between 1st and last images (30%)
zoomDecrement = zoomDiff / nSlices;

for(currSlice=1; currSlice <= nSlices; currSlice++)
{
setSlice(currSlice);
run(“Scale…”, “x=&newScale y=&newScale z=1.0 depth=81 interpolation=None”);
newScale -= zoomDecrement;
print(“Slice:” + getSliceNumber());
}

print("----------");
print(“All done.”);
print("----------");

Cheers

Steve


#11

Bummer I forgot to save it so the above version is incomplete. Version 2 coming up soon!


#12

OK here’s the proper one. By experiment, I’ve found that Helicon Focus works better if you align first and fix the zoom second:

/*
This macro compensates for errors in taking photographs through a
binocular microscope eyepiece. As the microscope lens travels down
the AOI wanders horizontally, vertically and the zoom factor increases
for every image.

Steve Mayall
13th November 2018

*/

print(“Zoom Normaliser and Aligner”);

newScale = 1.0;
zoomDiff = 0.315; // Difference between 1st and last images
zoomDecrement = zoomDiff / nSlices; // Calculate zoom factor for succesive slices

// Align entire stack
run(“Linear Stack Alignment with SIFT”, “initial_gaussian_blur=1.60 steps_per_scale_octave=3 minimum_image_size=64 maximum_image_size=1024 feature_descriptor_size=4 feature_descriptor_orientation_bins=8 closest/next_closest_ratio=0.92 maximal_alignment_error=25 inlier_ratio=0.05 expected_transformation=Rigid interpolate”);

// for every slice, reduce zoom factor incrementally
for(currSlice=1; currSlice <= nSlices; currSlice++)
{
setSlice(currSlice);
run(“Scale…”, “x=&newScale y=&newScale z=1.0 depth=81 interpolation=None”);
newScale -= zoomDecrement;
print(“Slice:” + getSliceNumber());
}

// back to the start…
setSlice(1);

print("----------");
print(“All done.”);
print("----------");

Cheers

Steve