Searching for Yellow Error, And is this the right way to write the 'if' Statement
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Mahesh Taparia
2021년 2월 27일
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!