11-21-2011 10:15 AM - edited 11-21-2011 10:18 AM
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.
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.
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.
11-21-2011 10:29 AM
ps. .......No, check that, U8 should be fine since that is just Intensity specification, not spatial dimension-related.....Don
11-21-2011 11:02 AM
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?
11-21-2011 11:43 AM
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.
11-21-2011 12:48 PM
Eureka:
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
11-21-2011 02:17 PM
Greg - your spline interpolation pixel shifter works just fine as well and may operate faster than the filters due to several fewer operations.
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
11-21-2011 04:28 PM
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
11-21-2011 04:45 PM
11-30-2011 10:49 AM
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:
Here it is after alignment, showing that the gross gray scale variation has been removed, but the vertical lines remain:
I converted the images to SGL float prior to unwrapping, then converted back to U16, and that solved the problem:
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