How do I make an If statement for retrieving a colour from pixel values

I have a range of pixel values that I have for the indiviual squares and mate a range of these values that when I get the pixel value for a specific point it should return the colour of the original image before I converted it to grayscale but it keeps giving me the wrong colour each time?And help would be greatly appreciated
img = imread('noise_1.png'); % Read file
I = im2double(img);% Convert image to double data type
N = imnoise(I, 'salt & pepper', 0.03); % Add noise to the image
red_channel = N(:, :, 1); % Separating red channel
green_channel = N(:, :, 2); % Separating green channel
blue_channel = N(:, :, 3); % Separating blue channel
Ravg = mean2(red_channel); % Mean of red channel
Gavg = mean2(green_channel); % Mean of green channel
Bavg = mean2(blue_channel); % Mean of blue channel
disp('Average of red channel:');
disp(Ravg);
disp('Average of green channel:');
disp(Gavg);
disp('Average of blue channel:');
disp(Bavg);
% 2-D median filtering
red_channel2 = medfilt2(red_channel, [3 3]);
green_channel2 = medfilt2(green_channel, [3 3]);
blue_channel2 = medfilt2(blue_channel, [3 3]);
F = cat(3, red_channel2, green_channel2, blue_channel2); % Concatenating the channels along 3 dimensions
grey_scale = rgb2gray(F) % Converting RGB image into greyscale
h = imshow(grey_scale);
hp = impixelinfo;
set(hp,'Position',[5 1 300 20]);
wow = grey_scale(200, 200)
if 0 <= wow <= 0.53,
disp('Blue');
end
if 0.54 <= wow <= 0.75,
disp('Red');
end
if 0.75 <= wow <= 0.89,
disp('Green');
end
if 0.89 <= wow <= 0.96,
disp('Yellow');
end
if wow > 0.97,
disp('White');
end

1 Comment

Have a read here and here. It will greatly improve your chances of getting an answer.

Sign in to comment.

Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Asked:

on 16 Apr 2021

Commented:

Rik
on 16 Apr 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!