Accurately detect total area of leaf in digital image in matlab

394 Views Asked by At

I have converted the image to binary( black and white). Here is the original image and binary image

Here is the code I have written

a=imread('image');
imshow(a);title('original image');
b=imresize(a,[200,250]);
figure,imshow(b);title('resized image');
c=im2bw(b);
figure,imshow(c); title(['Number of white pixels: ' int2str(nnz(c))]);
at=int2str(nnz(c));
disp(at)

I counted the white pixels to find the total area of leaf. But because of the folds in leaf some part of leaf area is covered with black pixels. How do I change the whole leaf area white? How do I take care of leaf folds? I am doing an image processing project in matlab where I will have to grade the leaf. It would be really helpful if someone could give me the code to take care of the folds of leaf in digital image. I'm using MATLAB 2009a.

1

There are 1 best solutions below

1
On BEST ANSWER

A first approach might be using rgb2gray() instead of im2bw(), like this:

c=rgb2gray(b);
figure,imshow(c);

where b is your resized picture (as in your code). The following picture will be displayed: enter image description here

And then you can just count the number of non-zero pixels (values in matrix c). Recall that 0 means black.

Although you must notice that even in the original picture the upper and left borders have a gray margin, which is white in this grayscale picture. Also the date in the bottom right corner will be counted as non-zero. For a better and more accurate results I suggest some sort of algorithm to detect the margin of the leaf, like Kass et al. "Snakes, active contour model". Such algorithm is described here.