Problem about "normxcorr2"

7 views (last 30 days)
palm prasong
palm prasong on 15 Sep 2017
Commented: Image Analyst on 17 Sep 2017
I = im2double(dicomread('I.dcm'), 'frames',1 ));
T=imread('T.jpg');
c = normxcorr2(T,I);
[ypeak, xpeak] = find(c==max(c(:)));
---------------------------------------------------------
This is work I can get the correct ypeak, xpeak.
---------------------------------------------------------
I = im2double(dicomread('I.dcm'), 'frames',1 ));
T=imread('T.jpg');
c = normxcorr2(T,I);
i= 1
while i < 100
I = im2double(dicomread('I.dcm'), 'frames',i+1 ));
i = i+1;
c = normxcorr2(T,I);
[ypeak, xpeak] = find(c==max(c(:)));
End
-------------------------------------------------------------------
This is also work.
-------------------------------------------------------------------
However, when I use ypeak, xpeak to create a new template and use the templates in the loop is not work.
I = im2double(dicomread('I.dcm'), 'frames',1 ));
T=imread('T.jpg');
c = normxcorr2(T,I);
[ypeak, xpeak] = find(c==max(c(:)));
i= 1
while i < 100
I = im2double(dicomread('I.dcm'), 'frames',i+1 ));
i = i+1;
c = normxcorr2(T,I);
[ypeak, xpeak] = find(c==max(c(:)));
T = I(ypeak: ypeak+100,xpeak : xpeak+100,:);
End
It can create new templates, but ypeak, xpeak value is not update.
ypeak= 50;
xpeak= 50;
if I change
T = I(ypeak: ypeak+100,xpeak :xpeak+100,:);
to
T = I(50: 150,50:150,:);
ypeak, xpeak value can be updated.
I don't know why when I use ypeak, xpeak to create a new template normxcorr2 is seem stop working and return only the first value of ypeak, xpeak.
  3 Comments
palm prasong
palm prasong on 16 Sep 2017
edited
i just made a mistake when copy.
Walter Roberson
Walter Roberson on 17 Sep 2017
Your code
I = im2double(dicomread('I.dcm'), 'frames',1 ));
is not right. You need
I = im2double(dicomread('I.dcm', 'frames', 1 ));

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 15 Sep 2017
Edited: Walter Roberson on 15 Sep 2017
You have
[ypeak, xpeak] = find(c==max(c(:)));
T = I(ypeak: ypeak+100,xpeak : xpeak+100,:);
The only reason to use find comparing the array to its max() is for the case where there could be multiple matches against the max and you want to find all of them. But when that happens then you have problems with the ":" operator.
If you only expect and need a single max value, then
[~, idx] = max(c(:));
[ypeak, xpeak] = ind2sub(size(c), idx);
  2 Comments
palm prasong
palm prasong on 17 Sep 2017
thank , still have the same problem. When use variable ypeak, Variable xpeak to create a new template.
The new template can be created, but when use the new template to find ypeak, xpeak again ypeak, xpeak are not update.
There is no problem ,When I directly use the value of ypeak, xpeak to create a new template.
Image Analyst
Image Analyst on 17 Sep 2017
You still have the same problem because you're preventing people from helping you.
I asked you to supply the I and T images so we could run the code and try to fix it, but you have not done that, so your problem remains.
The best I can do for you is to just attach my normxcorr2() demo.
Good luck.

Sign in to comment.

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!