Problem about "normxcorr2"

8 次查看(过去 30 天)
palm prasong
palm prasong 2017-9-15
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 个评论
palm prasong
palm prasong 2017-9-16
edited
i just made a mistake when copy.
Walter Roberson
Walter Roberson 2017-9-17
Your code
I = im2double(dicomread('I.dcm'), 'frames',1 ));
is not right. You need
I = im2double(dicomread('I.dcm', 'frames', 1 ));

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2017-9-15
编辑:Walter Roberson 2017-9-15
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 个评论
palm prasong
palm prasong 2017-9-17
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 2017-9-17
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by