What is wrong with the following piece of code? Im trying to detect light and dark green vegetation. It just displays a black empty image
Show older comments
Image1 = im2double(imread('image\test.png'));
g=rgb2gray(Image1);
b=imread('image\1.jpg');
imshow(b);
[row column page] = size(Image1)
for i = row
for j = column
if (Image1 (i, j, 2) > Image1(i, j, 1) && Image1(i, j, 2) > Image1(i, j, 3))
Image2 (i, j, 1) = Image1 (i, j, 1);
Image2 (i, j, 2) = Image1 (i, j, 2);
Image2 (i, j, 3) = Image1 (i, j, 3);
else
Image2 (i, j, 1) = 0;
Image2 (i, j, 2) = 0;
Image2 (i, j, 3) = 0;
end
end
end
[row column page] = size(Image1)
for i = row
for j = column
Green = Image1 (i, j, 2) + 20;
if (Green > Image1(i, j, 1) && Green > Image1(i, j, 3))
Image2 (i, j, 1) = Image1 (i, j, 1);
Image2 (i, j, 2) = Image1 (i, j, 2);
Image2 (i, j, 3) = Image1 (i, j, 3);
else
Image2 (i, j, 1) = 0;
Image2 (i, j, 2) = 0;
Image2 (i, j, 3) = 0;
end
end
end
[row column page] = size(Image2)
imshow(Image2);
Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!