I have this code for calculating roundess
I = imread('http://energyfanatics.com/wp-content/uploads/2008/05/banana.jpg');
%I = imread('http://www.nyapplecountry.com/images/photosvarieties/redrome04.jpg');
pic = rgb2gray(I);
threshold = graythresh(pic);
bw = im2bw(pic,threshold);
fbw = ones(size(bw))-imfill(ones(size(bw))-bw);
invImg = ~fbw;
imshow(invImg);
f = bwlabel(invImg);
S = regionprops(f,'Area','Perimeter','centroid');
res = (min(sqrt([S.Area]),[S.Perimeter]/4)./(max(sqrt([S.Area]), [S.Perimeter]/4))).^2;
My problem is when i use the picture of banana i have multiple values in score, but when i use the other picture of an apple i get only one value. The problem lies in noise that is left behind. I was trying to use some edge detection methodes like sobel but I can't combine the edge detection with the black&white image.
So my question is how can i detect edge of an fruit so i get the whole fruit and how to get rid of noise. I just want to get the roundess of the fruit.