I have a color image of type RGB and I need to change the color of each point (red, yellow, orange) to green. I hope that there is a programmatic solution to this problem.
Suppose i have a picture of size 400x400. When i import it in MATLAB (using imread or directly) the matrix size will be 400x400x3 uint8. Now the 3rd dimension depicts R,G and B. Now you can apply conditions on these three colors for 1 pixel and change there values as you want
For example True red is [255 0 0], now apply a check that if this condition satisfies change pixel to
Looks like you switched x and y. Usually it's good not to go against well entrenched naming conventions or else confusion will result. Remember, arrays are indexed (row, column) which is (y, x), not (x,y).
Also you can do it without loops like this:
rgbImage = imread('peppers.png');
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Image', 'FontSize', 15);
% Split the RGB image into individual color channels.
[r, g, b] = imsplit(rgbImage);
% Define what is orange.
th = 20;
orangeMask = r > (g + th) & r > (b + th);
subplot(2, 2, 2);
imshow(orangeMask);
title('Orange Mask', 'FontSize', 15);
% Assign 0 to red and blue, and 255 to green to make those regions green.
r(orangeMask) = 0;
g(orangeMask) = 255;
b(orangeMask) = 0;
% Rebuild the RGB image from the individual color channels.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
5 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_927872
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_927872
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_927905
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_927905
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_927914
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_927914
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_927998
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_927998
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_928961
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/560777-how-can-i-change-pixel-color#comment_928961
Sign in to comment.