【发布时间】:2018-01-31 20:52:05
【问题描述】:
我正在尝试匹配图像中的 RGB 值。
% R G B
RGBset = [ 3 9 12;
4 8 13;
11 13 13;
8 3 2]
img(:,:,1) = [1 2 3
6 5 4
7 9 8
10 11 12];
img(:,:,2) = [3 4 8;
6 7 8;
11 10 9;
12 13 14];
img(:,:,3)= [3 7 2;
4 9 10;
5 11 12;
6 13 14]
在这张图片中,只有一个 RGB 值与 RGBset 匹配,即[11,13,13],因此预期输出为:
[0 0 0;
0 0 0;
0 0 0;
0 1 0]; % reshape(img(4,2,:),1,3) = [11, 13 13] is available in RGBset
% no other RGB value is present in the image
我已经编写了这段代码,但是对于较大的图像它非常慢。
matched= zeros(img(:,:,1));
for r=1:size(img(:,:,1),1)
for c=1:size(img(:,:,2),2)
matched(r,c)=ismember(reshape(img(r,c,:),1,3),RGBset,'rows');
end
end
更快的解决方案是什么?
【问题讨论】:
标签: matlab image-processing matrix multidimensional-array vectorization