How to perform multiple AND operations inside the loop?
4 ビュー (過去 30 日間)
古いコメントを表示
I have a binary image "I", and 40 binary images "test01" to "test40"...all the images have same resolution...I want to AND the image I with the 40 test images one by one and then take the sum to find out the maximum sum to get the best matching image...how to perform ANDing using loop instead of doing it multiple times...thanks in advance
3 件のコメント
採用された回答
Jon
2015 年 7 月 23 日
編集済み: Jon
2015 年 7 月 23 日
Why not just
sum(abs(imsubtract(im1,im2)))
which will return the number of pixels that are different between im1 and im2. There are much more sophisticated ways, but this is a decent start.
3 件のコメント
Jon
2015 年 7 月 24 日
If you can't figure that out, you might be in over your head. Just put it in a loop, e.g.
im_to_match = I; % the image for which you're looking for a best match
imsum(40) = 0; % preallocate solution
for i = 1:40
im2compare = yourimagestructure(i); % call the image you want to compare against
imsum(i) = sum(abs(imsubtract(im_to_match,im2))); % do the comparison
end
[~,best_match_i] = min(imsum); % returns the image with fewest differences (in a pixel-by-pixel sense)
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!