Trying to automatically crop an image into several smaller images based on segmentation
조회 수: 3(최근 30일)
표시 이전 댓글
댓글: Teshan Rezel 2020년 2월 18일
Apologies in advance, I'm not well versed in Matlab.
I'm trying to crop a segmented image into several smaller pieces that only contain the a segmented piece of the original image. For example, if an image has 3 apples and I'm interested in the apples, I am aiming to cut out each apple into a seperate image. The result I'm hoping for is 3 seperate images of apples, with anything else in the crop blackened (or whitened) out.
Why I'm trying to do this is so I can pass each resultant image into a CNN for analysis, as each segmented piece/cropped image is a type of object that needs to be classified.
Below is an image of mine that I'm trying to process. Any ideas would be useful! Thanks in advance.
댓글 수: 8
darova 2020년 2월 17일
Something like this
I = imread('image.jpeg');
I1 = im2bw(I);
I2 = imdilate(I1,ones(5)); % imdilate to close contours
I3 = imerode(I2,ones(4)); % restore thickness
[L,n] = bwlabel(I3); % label regions/areas
title('restore thickness of contours')
for i = 2:n
I4 = L==i; % select region
I5 = imfill(I4,'holes'); % fill contour/region
imshow(cat(3,I5*255,I3*255,I3*0)) % display
댓글 수: 3
Find more on Region and Image Properties 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!