How would I segment this image of a tomato from its background? I tried the watershed method done by mathworks; unfortunately, some of the background is of the same intensity of the tomato and an edge is created between that background spot and a surrounding darker spot, so the tomato as well as some background is segmented together.
I tried to just find the gradient to reveal the outer edge of the tomato but not all of it is very defined, so it seems at some parts that it does not connect all the way around the tomato. My thought is that if I could connect that and fill in that entire boundary, I could effectively segment this tomato by pulling out just the filled in pixels from the original image. If anyone could help I would much appreciate it.
I included the picture of the original image and the gradient image, done with the commands below.
I = imread('Insert Image');
figure, imshow(I);
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
figure, imshow(gradmag,[]), title('Gradient magnitude (gradmag)')