TransWikia.com

Remove Shadows from Contour of an Object (Grapes)

Signal Processing Asked by Alon Shmiel on November 23, 2021

I want to extract only the grapes from the images. Unfortunately, sometimes I don’t get the grapes exactly.

I have a code that doesn’t work well in all cases. Sometimes, it does not differentiate between the shadows and the grapes.

The example input image:

enter image description here

The result I’m getting:

enter image description here

And this is my code:

RGB = imread('DSC02807.JPG');
GRAY = rgb2gray(RGB);

threshold = graythresh(GRAY);
originalImage = im2bw(GRAY, threshold);

originalImage = bwareaopen(originalImage,250);

SE = strel('disk',10);
IM2 = imclose(originalImage,SE);

originalImage = IM2;

imshow(originalImage);

One Answer

This is what your code produces (using colormap(hot) with white boundaries that are obtained from IM2): enter image description here

I think the shadows are nicely treated, why are you thinking that your code doesn't notice between shadow to grapes?

This is the code used for producing this image

bw=IM2<1;
[B,L] = bwboundaries(bw,'noholes'); % fill any holes, so that regionprops can be used to estimate
imagesc(GRAY); hold on
for k = 1:length(B) 
    boundary = B{k};
    plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 1); hold on
end
colormap(hot(256))

Answered by bla on November 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP