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

3 ビュー (過去 30 日間)
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

回答 (3 件)

Image Analyst
Image Analyst 2011 年 7 月 15 日
Perhaps you can set the bad pixels to NaN - MATLAB often seems to harmlessly ignore such values when it does computations.
  2 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 7 月 15 日
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{:});
Sean de Wolski
Sean de Wolski 2011 年 7 月 15 日
Though it should be easy enough to write nannormxcorr2

サインインしてコメントする。


Sean de Wolski
Sean de Wolski 2011 年 7 月 15 日
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 件のコメント
Shayan
Shayan 2011 年 7 月 15 日
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.

サインインしてコメントする。


bart
bart 2013 年 5 月 29 日
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!

Translated by