How to Capture objects in big image and divided them to small images?

W
warinthorn_Kiadti · Aug 30, 2022 · 1.9K views
Question
Hi,   I stuck at my study now.   I have one example image.  From this image, I would like to separate these five small objects in the picture to be five small images.   How can I do this. I need your help please.   I am looking forward to hear from you. Thank you very much.
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Aug 17, 2026

This code works just for this image only

 

Irgb = imread('b653er.jpg');
Igray = rgb2gray(Irgb);
Ibw = im2bw(Igray,graythresh(Igray));
Ifill = imfill(Ibw,'holes');

%clear the lines
Ihor = imopen(Ifill,strel('line',5,0));
Iver = imopen(Ihor,strel('line',5,90));

Ilabel = bwlabel(Iver);
stat = regionprops(Ilabel,'BoundingBox');
for x = 1 : numel(stat)
    bb = stat(x).BoundingBox;
    Icrop{x} = imcrop(Irgb,bb);
    subplot(numel(stat),1,x); imshow(Icrop{x});
end

objects in big image

Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!