Finding a specific colour within a picture.
조회 수: 18 (최근 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!