image correlation, multiple occurance pattern

10 views (last 30 days)
Hi there,
i was trying to detect multiple occurrence of pattern in ma image, but i keep on getting error:
"Error using horzcatDimensions of arrays being concatenated are not consistent."
Here is the code:
imagePath = 'C:\Users\Mateusz\Desktop\Systemy wizyjne\labolatoria\matlab\Database\Patterns\multi.png';
patternPath1 = 'C:\Users\Mateusz\Desktop\Systemy wizyjne\labolatoria\matlab\Database\Patterns\multi_P1.png';
img = imread(imagePath);
imgGs = rgb2gray(img);
pattern1 = imread(patternPath1);
patternGs1 = rgb2gray(pattern1);
subplot(1, 4, 1)
imshow(imgGs)
subplot(3, 4, 6)
imshow(patternGs1)
corelation1 = normxcorr2(patternGs1, imgGs);
subplot(3, 4, 7)
surf(corelation1)
shading flat
subplot(1, 4, 4)
imshow(imgGs);
dvals = sort(corelation1(:), 'descend'); % 5 ekstrme
for i = 1 : 5
[ypeak, xpeak] = find(corelation1 == max(corelation1(:)));
yOffset = ypeak-size(patternGs1, 1);
xOffset = xpeak-size(patternGs1, 2);
hold on
imrect(gca, [xOffset+1, yOffset+1, size(patternGs1, 2), size(patternGs1, 1)]);
end
  2 Comments
Mateusz Fijak
Mateusz Fijak on 26 Apr 2019
error occurs inside the for loop in imrect method
Image Analyst
Image Analyst on 27 Apr 2019
Edited: Image Analyst on 27 Apr 2019
What are the values in this array:
[xOffset+1, yOffset+1, size(patternGs1, 2), size(patternGs1, 1)]
? And attach your two images (you forgot to in your original post).

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!