Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Subpixel image shift

Hi Bruce -

 

You are definitely correct. This should not be this difficult.  The mystery certainly lies in the application of the shifts which is this piece of code below. 

 

Shift application code.JPG

Here are the centroid calculations which are a little strange.  The centroid in Y seems too large compared with shift.  Because of the way I set up the IMAQ buffers, the "after shift" centroid calculations are after the total shifts are done (regardless of where I place the IMAQ Centroid function).  I probably should put in a breakpoint and probes so I can capture right after the fractional shifts are applied.

 

Centroids.JPG

 

 

 

I probably just have to keep staring.  I appreciate the time you have already taken.

 

Something just hit me.  I think the image type must have to be SGL in the application of the shift since it is fractional.  Yikes, how could I miss this.  Let me try to change this.

0 Kudos
Message 31 of 39
(2,825 Views)

ps. .......No, check that, U8 should be fine since that is just Intensity specification, not spatial dimension-related.....Don

0 Kudos
Message 32 of 39
(2,822 Views)

Here is something interesting.  Just looking at Centroid calculation before and after fractional X shift, the Y centroid changes dramatically. I had assumed Y centroid would not change. Does this indicate that Y is shifting also and should we account for that in subsequent shifting?

 

Centroids Before and After FractionalX Shift.JPG

 

 

 

 

0 Kudos
Message 33 of 39
(2,821 Views)

Another mistake I need to correct.  Cannot use I32 here since it rounds to nearest integer.  I'll fix this.  I had not looked at the help on this function in probably 15 years and assumed it just took the integer portion.

0 Kudos
Message 34 of 39
(2,818 Views)

Eureka:

 

labview-alignment.JPG

 

The I32 issue was the big one that bit me causing all of the strange results after making the prior corrections from earlier posts.

 

Sincerely,

 

Don

0 Kudos
Message 35 of 39
(2,815 Views)

Greg - your spline interpolation pixel shifter works just fine as well and may operate faster than the filters due to several fewer operations.

 

 

gregs-pixel-shifter.JPG

 

 

 

Final steps include:

 

1) Loop1: Histogram matching of all of the images to a reference image

 

2) Loop2: Calculate difference (shift) between center points of circular images and reference image using IMAQ Find Circular Edge 2 which provides sub-pixel resolution.

 

3) Linear Curve fit the shifts of middle 60% to obtain slope (m) and offset (b).   Calculate corrected offset (b') to account for fact of only using middle 60% of data for curve fit.

 

4) Loop3: Calculate shift from linear curve fit equation (coefficients m and b') for each image.  Use interpolation either by filter or Bilinear Interpolation to achieve sub-pixel resolution of the fractional portion, convolve fractional portion results with the image, followed by applying integer shift to image to achieve aligned stack.

 

 

 

Guys - Thanks again for all your help.  It really helps sometimes to have folks to bounce things off of.  I think the code is now a great solution for the case of translation mis-alignment.  If I have anything more to add, I will post.

 

Don

 

0 Kudos
Message 36 of 39
(2,812 Views)

Don,

 

Glad it is working.

 

Just FYI, I didn't intend for you to transpose the image.  You are just supposed to transpose the 5x1 array used for convolution.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 37 of 39
(2,809 Views)
I'll make that modification. That should make a major difference in efficiency. Thanks for letting me know.....don
0 Kudos
Message 38 of 39
(2,806 Views)

Hi Bruce -

 

I made that change and verified that it does work to just transpose the kernel in your filter.

 

Also, your intuition regarding potential problems with the IMAQ Unwrap routine also came to light yesterday with both raw U8 and raw U16 files.  It did not show up when processing BMP files, and maybe that was just luck.

 

Here is the Unwrapped image I was getting with U16 raw data prior to alignment:

 

non-aligned.png

 

Here it is after alignment, showing that the gross gray scale variation has been removed, but the vertical lines remain:

 

aligned.png

I converted the images to SGL float prior to unwrapping, then converted back to U16, and that solved the problem:

 

alignedSGLFloat.png

 

 

I am starting to think that for most any image math operation, most specifically having to do with interpolation, it would probably be a good idea to convert first to SGL float and then convert back.

 

However, this should automatically be taken care of in the IMAQ routines if it is specified that the routine is compatible with these integer data types.

 

Don

0 Kudos
Message 39 of 39
(2,786 Views)