How to change specific RGB value to another RGB value in a PNG uint8 image?
Show older comments
%I have the following code:
RGB = imread('image.png');
[r c z] = size(RGB);
for i=1:r
for j=1:c
if (RGB(i,j,1)==50 && RGB(i,j,2)==205 && RGB(i,j,3)==50)
RGB(i,j,1)=255; RGB(i,j,2)=255; RGB(i,j,3)=255;
elseif (RGB(i,j,1)==255 && RGB(i,j,2)==228 && RGB(i,j,3)==181)
RGB(i,j,1)=255; RGB(i,j,2)=255; RGB(i,j,3)=255;
elseif (RGB(i,j,1)==0 && RGB(i,j,2)==0 && RGB(i,j,3)==0) %MATLAB won't run this part
RGB(i,j,1)==255 && RGB(i,j,2)==255 && RGB(i,j,3)==255;
elseif (RGB(i,j,1)==250 && RGB(i,j,2)==250 && RGB(i,j,3)==250) %MATLAB also won't run this part
RGB(i,j,1)==255 && RGB(i,j,2)==255 && RGB(i,j,3)==255;
else
RGB(i,j,1)=0; RGB(i,j,2)=0; RGB(i,j,3)=0;
end
end
end
%So that's my code
My problem now is why MATLAB does not change the RGB values as indicated in the code comments? Also, is there a way to use operators to simplify the code instead of using so much elseifs? I shall be using this for one of my clustering algorithms. Thank you so much in advance for any help.
Accepted Answer
More Answers (0)
Categories
Find more on Images 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!