Finding x,y coordinates of pixel by RGB color value
조회 수: 17 (최근 30일)
이전 댓글 표시
Hi, Is there a reverse impixel function? I want to find the x and y coordinates of pixels in a color image by searching for them only with a RGB color value. I have tried converting into a binary image and searching for the '1' values by using
BW = im2bw(RGB, level)
and then [rows,cols] = find(BW==1);
but I am confused on how to set a level to implement an RGB value so that only my specific color pixels will show up as white in the binary image.
Is there a better way to find the coordinates of pixels only by using RGB value?
thanks!
댓글 수: 0
채택된 답변
Image Analyst
2017년 5월 5일
Try this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Find where each color plane is your exact desired color value.
mask = redChannel == desiredRedValue && ...
greenChannel == desiredGreenValue & ...
blueChannel == desiredBlueChannel;
[rows, columns] = find(mask); % Note [rows, columns] = [y, x], NOT [x, y]
WHY do you want to do this. You probably don't need to and there is a better way if I just knew what you were going to do after this.
댓글 수: 4
Image Analyst
2017년 5월 6일
I don't know what a "false range" is.
If you want to know what coordinates have x between 10 and 20 and y between 90 and 100, then do
indexes = columns >= 10 & columns <= 20 & rows >= 90 & rows <= 100;
% Extract only those in the range
c2 = columns(indexes);
r2 = rows(indexes);
추가 답변 (1개)
Franklin Prashanth C
2018년 1월 22일
편집: Image Analyst
2018년 1월 23일
How can I get these xy coordinate values, so that I can use it.?
[rows, cols] = find(BW==1); or
[rows, columns] = find(mask);
댓글 수: 1
Image Analyst
2018년 1월 23일
It just depends on whether you want the columns called "col" or "columns" and whether your binary image is called BW or mask. The ==1 is not necessary and can get deleted.
참고 항목
카테고리
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!