How to crop an portion fro image
Ältere Kommentare anzeigen
I have a code below
clc
clear all
close all
I = imread('rice.png');
imshow(I)
background = imopen(I,strel('disk',15));
I2 = I - background;
imshow(I2)
I3 = imadjust(I2);
imshow(I3);
level = graythresh(I3);
bw = im2bw(I3,level);
bw = bwareaopen(bw, 50);
imshow(bw)
cc = bwconncomp(bw, 4)
grain = false(size(bw));
grain(cc.PixelIdxList{50}) = true;
grain(cc.PixelIdxList{30}) = true;
grain(cc.PixelIdxList{80}) = true;
grain(cc.PixelIdxList{75}) = true;
grain(cc.PixelIdxList{70}) = true;
imshow(grain);
now want to crop the grains shown in binary image from original image ,kindly help
Akzeptierte Antwort
Weitere Antworten (1)
Siam
am 13 Nov. 2014
1 Stimme
You can try with imcrop()
4 Kommentare
nkumar
am 13 Nov. 2014
Siam
am 13 Nov. 2014
Your question was not clear as it says how to crop a portion from image. Not sure what actually you want to do? your code gives you 5 grains in white color and background in black. So why do you have to crop them? Can you explain a bit more?
nkumar
am 14 Nov. 2014
Guillaume
am 14 Nov. 2014
Doesn't my answer do what you want?
Note that crop is probably not the appropriate word. It sounds like what you want is to extract part of an image.
Kategorien
Mehr zu Color Segmentation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!