How can i extract all labeled objects in a image and save every object as an image?

3 vues (au cours des 30 derniers jours)
Toni Vukasinovic
Toni Vukasinovic le 21 Fév 2020
Commenté : Daniel Vieira le 26 Fév 2020
I have labeled 650 images in Image labeler. Now i want to save every object i have labeled as a 81X81 pixel image.How can i do that?

Réponses (1)

Daniel Vieira
Daniel Vieira le 21 Fév 2020
with the image labeler you made a table where the first column is the image file, and the others are each label, each cell containing the bounding boxes of each object. So:
% T -> your table
for k=1:height(T)
I=imread(T.file{k}); % I don't quite remember it the variable is "file", change it to the name of your 1st variable
for h=2:width(T)
for z=1:size(T{k,h},1)
subI=imresize(imcrop(I,)T{k,h}(z,:),[81 81]);
writeimage(subI,"file "+k+" "+h+" "+z+".png") % change this string to something suitable to you
end
end
end
  3 commentaires
Toni Vukasinovic
Toni Vukasinovic le 24 Fév 2020
I have done the following as you segested.
for k=1:height(gTruth)
I=imread(gTruth.LabelData{k}); % I don't quite remember it the variable is "file", change it to the name of your 1st variable
for h=2:width(gTruth)
for z=1:size(gTruth{k,h},1)
subI=imresize(imcrop(I,),gTruth{k,h}(z,:),[81 81]);
writeimage(subI,"file "+k+" "+h+" "+z+".png") % change this string to something suitable to you
end
end
end
But I get the following error
subI=imresize(imcrop(I,),gTruth{k,h}(z,:),[81 81]);
Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for
mismatched delimiters.
Daniel Vieira
Daniel Vieira le 26 Fév 2020
gTruth here is not a table, it's a groundTruth object, that's why the code above doesn't work for you. You either need the Image Labeler App to export things in table format instead of gTruth (almost sure it does it), or you need to access the inner properties of gTruth, make a table, and work with it.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by