How to exclude points when calculating the normalized cross correlation coefficients with normxcorr2?

2 views (last 30 days)
I am using the normalized cross correlation coefficients function; normxcorr2(template, A)
to to compute the normalized cross correlation coefficients. My two images have been gathered with microscope and bright white pixels(FillValue 1) represent no data. Is there a way I could utilize the normxcorr2 to get the normalized cross correlation coefficients for all pixels but excluding the bright white ones?
Thanks, Shayan

Answers (3)

Image Analyst
Image Analyst on 15 Jul 2011
Perhaps you can set the bad pixels to NaN - MATLAB often seems to harmlessly ignore such values when it does computations.
  2 Comments
Sean de Wolski
Sean de Wolski on 15 Jul 2011
That won't work because it expects the template to be finite:
A = magic(3);
B = padarray(magic(3),[10 10])
A(5) = nan
normxcorr2(A,B)
??? Error using ==> iptcheckinput
Function NORMXCORR2 expected its first input, T, to be finite.
Error in ==> normxcorr2>ParseInputs at 231
iptcheckinput(T,{'logical','numeric'},{'real','nonsparse','2d','finite'},mfilename,'T',1)
Error in ==> normxcorr2 at 55
[T, A] = ParseInputs(varargin{:});

Sign in to comment.


Sean de Wolski
Sean de Wolski on 15 Jul 2011
I think I would start by creating a second image with the bright white pixels interpolated over.
MORE
nxcorr formula
It should be easy enough to implement this formula using nanmean, nanstd, and nansum (either with stats toolbox or available here: fex:nan_suite. Slide the template over every possible combination using double- for-loops; calculate the nxcorr and then find the highest value.
  1 Comment
Shayan
Shayan on 15 Jul 2011
I can't do interpolation for percision reseans. Otherwise interpolation is the way to go. I actually tried it and i get the cross correlation coefficient to be almost 1.

Sign in to comment.


bart
bart on 29 May 2013
Hellò, I have a similar problem. I cannot use an interpolation solution for precision reason too. Anyone could post a nannormxcorr2 function? I'm neophyte with matlab and i've some difficult to modify normxcorr2.. I tried modifying with nanmean, nanstd, nansum, nancumsum, conv2nan etc.. but it doesn't work. I suppose that is not so simple.
Thanks, Berto.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!