I'm using this code to capture the cap of a bottle. It's working if the cap is on the bottle, but it's not working when i remove the cap because by doing imcrop on the cap there is not a white area in the figure and therefore no level detection. What should I do to fix my error? Below is my code:
a=imread('emptybottle.png');
b=rgb2gray(a);
f1 = imcrop(b,[400 0 200 130]);
imhist(f1);
f2=im2bw(f1,0.78);
f3=~f2;
imshow(f3);
f4=bwareaopen(f3,250);
mask=strel('diamond',5);
f5=imopen(f4,mask);
imshow(f5);
g=bwareaopen(f5,8000);
imshow(g);
f6=regionprops(g)
level = f6.Area
level
4 Comments
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652748-insufficient-number-of-outputs#comment_1144828
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652748-insufficient-number-of-outputs#comment_1144828
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652748-insufficient-number-of-outputs#comment_1146228
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652748-insufficient-number-of-outputs#comment_1146228
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652748-insufficient-number-of-outputs#comment_1146418
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652748-insufficient-number-of-outputs#comment_1146418
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652748-insufficient-number-of-outputs#comment_1146698
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/652748-insufficient-number-of-outputs#comment_1146698
Sign in to comment.