How to Find the Pixel location using the known RGB values ?
1 view (last 30 days)
Show older comments
I know the RGB value of a certain pixel in a image , I want to know the location of that pixel. How to do it ?
Thank u.
0 Comments
Answers (1)
Image Analyst
on 17 Jul 2016
Edited: Image Analyst
on 18 Apr 2018
Make a mask then use find() to find out where the mask is true:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
mask = redChannel == redValue & ...
greenChannel == greenValue & ...
blueChannel == blueValue;
imshow(mask);
% Get (row, column) list
[rows, columns] = find(mask);
redValue, greenValue, and blueValue are your reference RGB values that you already know. mask is a binary image that says where that color occurs in the image. rows and columns will be the location of other pixels in the image that have that same color (exact R value, exact green value, and exact blue value).
11 Comments
Image Analyst
on 10 Sep 2021
Shannon, you'd have to do it in HSV color space. For the circle in the S plane, make the saturation 0 in the middle so it will be neutral, then 1 halfway out so the color will be 100% vivid, pure color, and then 0 out at the outer edge, meaning neutral again.
Then for the circle in the V plane, you'd have to make it go from 1 in the middle (white) to 0 at the outer perimeter (so it will be black instead of white).
Not too hard so give it a try.
Shannon Sumpter
on 10 Sep 2021
@Image Analyst I tried adding this to the code to do what you suggested, but now saturation is a 1002x334 double instead of a 1001x1001 double as it needs to be.
centerSaturation = zeros(round(size(hue)/3)); % neutral saturation
halfwaySaturation = ones(round(size(hue)/3)); %full saturation
outerSaturation = zeros(round(size(hue)/3)); % neutral saturation
saturation = cat(1,centerSaturation,halfwaySaturation,outerSaturation);
How would you go about doing this differently?
See Also
Categories
Find more on Blue in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!