Hello! I have a homework about pattern search using segmentation, and I got this error message: Array dimensions must match for binary array op. I only have the searching part of the code (or I hope this code do that).
Show older comments
img = imread('brickwall.jpg');
part = imread('brickwall_sample2.png');
[rows, cols] = size(img);
[part_row, part_col] = size(part);
diffimg = zeros(size(img));
minx = 1; miny = 1; minval = Inf;
for x=1:rows - part_row
for y=1:cols - part_col
cut = img(x:x+part_row-1, y:y+part_col-1);
diff = sum(sum( abs(cut - part) )); %this is where the problem occurs
diffimg(x,y) = diff;
if ( diff < minval )
minval = diff;
minx = x;
miny = y;
end
end
end
imshow(diffimg,[]);
result = zeros([rows, cols, 3],'uint8');
result(:,:,1) = img;
result(:,:,2) = img;
result(:,:,3) = img;
result(minx, miny:miny+part_col-1,1) = 255;
result(minx+part_row-1, miny:miny+part_col-1,1) = 255;
result(minx:minx+part_row-1, miny,1) = 255;
result(minx:minx+part_row-1, miny+part_col-1,1) = 255;
imshow(result,[]);
Thank you for the answers :)
And the two pictures are here:


Accepted Answer
More Answers (0)
Categories
Find more on Image Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!