How to crop object in image automatically?
Show older comments

I want to count pixel (binary =1) in object (in this case It is a pill) but this picture have noise so I think I should to crop the image to count How can I automatically crop the circle. or new suggestion how to count pixel
Accepted Answer
More Answers (1)
I guess you figured it out since you accepted the answer but I'll offer a different way. Simply call imclearborder followed by bwareafilt
binaryImage = imread('pillsc.png');
subplot(2, 1, 1);
imshow(binaryImage);
% Get rid of blobs touching border.
binaryImage = imclearborder(binaryImage);
% Take the largest of the blobs that are left.
binaryImage = bwareafilt(binaryImage, 1);
subplot(2, 1, 2);
imshow(binaryImage);
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


