MATLAB: Glass bottle edge detection using Matlab sofware.

edge detection glass bottleimage processingImage Processing Toolbox

Hi everyone..i have problem on how to detect the glass bottle by using edge detection method.
As a result..i cant get clear line of the glass bottle mouth and body.. can someone help by checking my code?
this is my code:
I=imread('red5.jpg');
figure, imshow(I);
threshold = graythresh(I);
bw1 = im2bw(I,threshold);
figure, imshow(bw1);
bw2 = bwareaopen(bw1,30);
se = strel('disk',4);
bw3 = imtophat(bw2,se);
figure, imshow(bw3);
d = edge(bw3,'sobel');
figure, imshow(d);
i still new with matlab..any very greatful for those who are helping me..

Best Answer

First of all your lighting is horrible. You shouldn't even think about doing anything until you fix your image capture situation . Use lighting that will eliminate shadows and give a nice high contrast edge. After that, it's just simple thresholding.
And I'm not sure what that algorithm is intended to do but it looks like just a bunch of random functions thrown together in random order - not something designed to "detect the glass bottle" like you asked for. I wouldn't do anything like that. I ought to know, since I've been working on image analysis of glasses and bottles for over 20 years (as part of my job).
Related Question