Searching for Yellow Error, And is this the right way to write the 'if' Statement
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zachary Steinwachs
el 23 de Feb. de 2021
Respondida: Mahesh Taparia
el 27 de Feb. de 2021
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
0 comentarios
Respuesta aceptada
Mahesh Taparia
el 27 de Feb. de 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!
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!