Finding a specific colour within a picture.
29 ビュー (過去 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 で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!