How to get the coordinates of the peak from normxcorr2 between a ROI and a template
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
I am using normxcorr2() between a ROI and a binary template, e.g.
template = [ 0 1 0 0 ; 0 1 1 1; 0 1 0 0; 1 1 1 1]
My ROI is cropped from a full image with this bounding box :
BB = [x,y,w,h];
BB is the size of the bounding box of the ROI.
subImage = FullImage(BB(2):BB(2)+BB(4)-1, BB(1):BB(1)+BB(3)-1);
The size of the subImage is the same as the template.
I compute the correlation image between subImage, template:
subCorrelationImage = normxcorr2(subImage, template);
The resulting size of this subCorrelationImage is not the same as subImage and template size.
I'd like to get position of the maximum of the correlation in the full image.
I have:
[ypeak, xpeak] = find(subCorrelationImage==max(subCorrelationImage(:)));
I tried:
ypeak = ypeak + y
xpeak = xpeak + x
But it does not work.
Thank you for your help.
댓글 수: 0
답변 (2개)
Neha
2023년 9월 6일
Hi,
I understand that you want to obtain the position of the maximum correlation of the full image. After finding the peak, you also need to account for the padding that "normxcorr2" adds. Here's an updated version of your code that correctly calculates the position of the maximum correlation:
% Compute the correlation image between subImage and template
subCorrelationImage = normxcorr2(template, subImage);
% Calculate the position of the maximum correlation in subCorrelationImage
[ypeak, xpeak] = find(subCorrelationImage == max(subCorrelationImage(:)));
% Adjust the position to the full image coordinates
y = ypeak - size(template, 1);
x = xpeak - size(template, 2);
% y and x are the positions of the maximum correlation in the full image
You can refer to the following documentation link for more information on "normxcorr2":
Hope this helps!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!