How to extract objects from a colored image and save them as separate images for future use?
Mostra commenti meno recenti
I have an image that contains numerous rice seeds laid on a coloured background and I want to separate the seed pixels from the image such that the i have the image of each rice seed saved as a separate picture. The reason i want to do that is that i want to extract features from each rice seed picture later to train a neural network to be able to identify to which variety the seed belongs to. The picture is attached, it isn't ideal but it is what i have to get started on developing an algo.

Risposta accettata
Più risposte (1)
Image Analyst
il 22 Dic 2020
Very easy. Just use the Color threshold on the apps tab of the tool ribbon to make a mask for the rice color. Then call regionprops() to get the bounding boxes. Then in a loop, call imcrop() to crop out each grain to it's own box. Let me know if you can't figure it out. Here's a start
[mask, maskedImage] = createMask(rgbImage); % From Color Thresholder
props = regionprops(mask, 'BoundingBox')
numRows = ceil(sqrt(length(props)));
hFig = figure;
hFig.WindowState = 'maximized'
for k = 1 : length(props)
thisBox = props(k).BoundingBox;
croppedImage = imcrop(rgbImage, thisBox);
subplot(numRows, numRows, k);
imshow(croppedImage);
end
Categorie
Scopri di più su Image Processing Toolbox in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

