Identify colour of each pixel using iterative statement
Show older comments
Hi Everyone,
Absolute begginer here.
I am looking to write an iterative statement (loop function) to identify pixels that are 'red', and change them to 'green' in a new image. Pixels that are not identified as 'red' need to be left alone. I understand this is not the best way to do this, but I need to explore the limitations of this process before moving to more advance image processing tools. Keep in mind that I don't have impixel() function as I don't have the image processing toolbox yet. I have a RGB 512 x 512 image.
My theshold would be that the pixel value is:
red > 180 && green < 50 (I'm not concerned with blue at the moment)
Logically the statement would read as follows:
If pixel red value > 180 and pixel green value < 50, then multiply red value by 0.5 and green value by 2.0.
The part I am having trouble with is actually building this into the code and creating a function that goes through pixel by pixel and creates a new image were the 'red' pixels are changed to 'green'
Thank you all in advance.
What I have so far is below:
% % % Code to import image and modify colour
% File name to call
filename = 'pepper.bmp';
% Function to call filename
OriginalImage = imread(filename);
% image(OriginalImage) % Displays Original Image (Discovered 'image'
% fucntion does not display as clear of a picture as 'imshow'
% Extract individual RGB colour channels
redChannel = OriginalImage(:, :, 1);
greenChannel = OriginalImage(:, :, 2);
blueChannel = OriginalImage(:, :, 3);
% Construct new image by analysing pixel by pixel
for
????
end
% Display both images side by side
subplot(1,2,1), imshow(OriginalImage)
title('Original Image');
subplot(1,2,2), imshow(ModifiedImage)
title('Modfied Image');
Accepted Answer
More Answers (1)
Kyle Robertson
on 11 Apr 2020
Categories
Find more on Image Preview and Device Configuration 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!