Searching for Yellow Error, And is this the right way to write the 'if' Statement

1 visualizzazione (ultimi 30 giorni)
Im trying to have it search for the color yellow on a black background and this code doesn't function how I thought it would. The print statement was just a test so I could see if it was finding a yellow pixel but it seems to print out the statment regardless. Eventually I want it to be able to pick up a yellow ball with a little more chaotic of a background tho.
%Error in imageUpload (line 12)
% Red = [R(x,y)];
I = imread('yellow.jpg');
imshow(I)
A = imread('yellow.jpg');
R = A(:,:,1);
G = A(:,:,2);
B = A(:,:,3);
for x = 1:720
x = x+1;
for y = 1:720
y = y+1;
Red = [R(x,y)];
Gre = [G(x,y)];
Blu = [B(x,y)];
if Red > 150 && Gre > 150 && Blu < 150
fprintf("i")
else
end
end
end

Risposta accettata

Mahesh Taparia
Mahesh Taparia il 27 Feb 2021
Hi
I assume, you want to find the pixels which satisfy the condition mentioned in your code. You can change your code to the below code:
A = imread('yellow.jpg');
R = A(:,:,1);
G = A(:,:,2);
B = A(:,:,3);
finalImage = zeros(720,720);
for x = 1:720
for y = 1:720
Red = [R(x,y)];
Gre = [G(x,y)];
Blu = [B(x,y)];
finalImage(x,y) = (Red > 150)&&(Gre > 150)&&(Blu < 150);
end
end
Hope it will help!

Più risposte (0)

Categorie

Scopri di più su Data Import and Analysis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by