How to extract images from groundTruth object?

6 次查看(过去 30 天)
Hello all,
is there a way to extract (i.e. saving as separate images) all the individual objects/regions which were defined as ROI label with the Image Labeler app. and stored within a groundTruth object? The aim is to apply some batch-modifications (e.g. contrast or rotation) to these images to achieve a better result of the cascade object detector.
Thank you for your help!

回答(2 个)

awezmm
awezmm 2020-1-3
Rummy18 and Joel,
You can import the labeled images and mask at different class labels. Each element in a labeled image matrix is a number representing which class a pixel in the original image belongs to.
If you want to apply rotations or contrast for some type of learning, check out data augmentation:
  4 个评论
Theresa Pflüger
Theresa Pflüger 2020-1-21
Sure!
Below you can see one example of my labeled images from the ImageLabeler App.
Just to be clear again, I would like to save the four stomata as four separate images.
Label_image.png
awezmm
awezmm 2020-1-24
Is this the actual labeled image? Can you please attach the labeled image after you export after labeling.

请先登录,再进行评论。


Rummy18
Rummy18 2020-1-24
Hi Theresa,
you can export your labels using the "export labels" function from the Image Labeler App. If you choose to export the labels directly to your Matlab workspace, select "table" as the export format. Lets call this table "plant". The first column of this table indicates the path to your images used in the Image Labeler App and the second column (plant.Stomata) (=name of the table.name of your labels) shows the coordinates of your labeled rectangles (x,y,x',y'). x' and y' are the number of pixels you have to add to x and y, respectively, to describe the corners of your labeld rectangles.
You can now apply some loops and export the labels:
% set your directory to the folder, where you want to save the individual images
cd 'path/folder';
% to find the number of pictures in your table "plant" use e.g.:
number_pictures = height(plant);
% find the number of labeled rectangles:
for c = 1:number_pictures
number_rectangles = (numel(plant.Stomata{c,1})/4);
% export the rectangles as individual images
for d = 1:number_rectangles
name = plant.imageFilename{c}; % path to the image used in the Image Labeler session
picture = imread(plant.imageFilename{c}; % imports the image into Matlab
picture_crop = imcrop(picture,[plant.Stomata{c}(d,1),plant.Stomata{c}(d,2),plant.Stomata{c}(d,3),plant.Stomata{c}(d,4)]); % crops the individual label using the coordinates
imwrite(picture_cop,[name,num2str(d),'.jpg'],'Quality',100); % saves the rectangles as .jpg image to your directory
clear name
clear picture
clear picture_crop
clear number_rectangles
end
end
Hope this helps.
Rummy18

类别

Help CenterFile Exchange 中查找有关 Image and Video Ground Truth Labeling 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by