Setting pixel to maximum color values in grayscale image.
Show older comments
I have a grayscale image attached below. I want to make all the circular objects a true red color (255, 0 0). However, after I convert the the grayscale to rgb using:
gray_as_RGB = repmat(grayimg, [1 1 3]); the range of values is not between 0-255. I do NOT want to normalize the range to 0-255 and then change the values and then recombine.
This is my code so far with grayimg being the image I have attached
grayimg;
% thresholding to find ciruclar objects
level = graythresh(grayimg)
BW = imbinarize(grayimg,level);
% convert grayscale to rgb
gray_as_RGB = repmat(grayimg, [1 1 3]);
% get color channels
redc = gray_as_RGB(:,;,1);
greenc = gray_as_RGB(:,;,2);
bluec = gray_as_RGB(:,;,3);
% This is the part I am confused about. I want the circles to have a true red but I do not know what value to set since it is not in the range of 0-255.
% I do not want to normalize since I will lose data. Right now I am thinking to just set the red channcel values, in the appropriate area to some random high number hoping that it is going to be the maximum of the range
redc(BW) = 999999999999999999;
greenc(BW) = 0;
bluec(BW) = 0;
final_img == cat(3, redc, greenc, bluec);
%The red in the final image does not look like true red. What should I set redc(BW) to accomplish this.
I don’t want to convert any values to the 0-255 scale. How do I find the highest possible value in the range I am in?
Accepted Answer
More Answers (1)
gonzalo Mier
on 28 Jun 2019
You can use uint8 to saturate all the values between 0 and 255.
You can test it as:
gray_as_RGB = uint8(repmat(grayimg, [1 1 3]));
You can leave the other part of the code without more changes
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!