MATLAB Answers

Help In Separation of objects in an image into different images

7 views (last 30 days)
verbose193
verbose193 on 30 Nov 2019
Answered: Satadru Mukherjee on 16 Jul 2020 at 17:04
Hi,
I have an image of multiple rice grains in jpg format. I need to separate the individual rice grains into a separate images. Need the code for this. Kindly help. The image is as below
The resultant images should contain individual rice as below:

  1 Comment

KALYAN ACHARJYA
KALYAN ACHARJYA on 30 Nov 2019
Is the segmented images must be equal size or resutant images can be any sizes?

Sign in to comment.

Answers (1)

Satadru Mukherjee
Satadru Mukherjee on 16 Jul 2020 at 17:04
Check this code:
clc
clear all
close all
x=imbinarize(rgb2gray(imread('Capture.JPG')));
imshow(x);
[L n]=bwlabel(x);
for i=1:n
[r c]=find(L==i);
rmin=min(r);
rmax=max(r);
cmin=min(c);
cmax=max(c);
output=x(rmin:rmax,cmin:cmax);
figure;imshow(output);
end

  0 Comments

Sign in to comment.