Finding a specific colour within a picture.
16 次查看(过去 30 天)
显示 更早的评论
hey guys. This is my approach but it doesn't work:
im = imread('img.jpg');
n = 1;
figure, imshow(im)
[x,y] = ginput(n);
x = floor(x);
y = floor(y);
colour = im(y,x,:);
[r,c,t] = size(im);
R = colour(1,1,1);
G = colour(1,1,2);
B = colour(1,1,3);
RGB = [R G B];
Red = im(:,:,1);
Green = im(:,:,2);
Blue = im(:,:,3);
%[i1 j1] = find(Red == colour(:,:,1));
%[i2 j2] = find(Green == colour(:,:,2));
%[i3 j3] = find(Blue == colour(:,:,3));
[i j] = find(im == colour); %This is the main problem
I get error: Array dimensions must match for binary array op. I also want to know if there is a way to find colors close to my color instead of exact match.
0 个评论
回答(3 个)
Walter Roberson
2011-11-4
[i j] = find(all(im == repmat(color,r,c,3),3));
Which is why it is easier to instead
[i j] = find(Red == R && Green == G && Blue == B);
The difficulty with finding colors "close" to a specific color, is in defining what "close" means for colors. Is medium-bright red "close" to bright red, or is medium-bright red "close" to medium-bright purple ?
One way that is as arbitrarily meaningful as any other:
[i j] = find( sqrt((double(Red) - R).^2 + (double(Green) - G).^2 + (double(Blue) - B).^2) <= COLORTOLERANCE );
0 个评论
Image Analyst
2011-11-5
Yes, that's a terrible way. Try my color segmentation demos. I have a few different (better) methods.
0 个评论
evin2165
2016-6-7
how to detection common rgb values in matlab ??
6 个评论
Image Analyst
2021-6-1
Yeah, just as I thought. I'm almost certain that what you asked to do is not what you really want to or need to do. Please post the original image, along with a marked up/annotated one that says what parts of the image you want to find and measure. And is the number of spots the same in all your images or does it vary? Is there a size range for your spots, or can they range from one single individual pixel up to the whole entire image area?
Valeriy
2021-6-2
移动:DGM
2023-2-12
>Yeah, just as I thought. I'm almost certain that what you asked to do is not what you really want to or need to do.
Sure, it was only part of the task. Now you know all.
>Please post the original image, along with a marked up/annotated one that says what parts of the image you want to find and measure.
I attached part of the image, which necessary to analyze. Blue channel is partly saturated, but this is test image to elaborate correct procedure. Complete image is bigger than allowed 5 Mb.
>And is the number of spots the same in all your images or does it vary?
It is variable, different for different images.
>Is there a size range for your spots, or can they range from one single individual pixel up to the whole entire image area?
As you can see from attached example, spots size is variable, and even worse, spot borders are not well determined, not well "focused". So expected "clouds" won't have sharp borders
Sorry to delay my reply. I was occupied to test version with loop along set of unique colors. Unfortunately, it is also rather long. For 330k unique color and image like I attached it took ~12 hours of calculations. 330k colors well corresponds to the similar value, which Color Inspector 3D shows, so I belive that my estimation of unique colors number now is correct.
I think to filter from unique colors list low repeating values like 1..3 and organize loop only for higher values. Hope it will decrease calculation time because such scan by such low values takes most of the time.
I appreciate a lot your valuable help and discussion, thank you.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!