How to extract images from groundTruth object?

3 ビュー (過去 30 日間)
Rummy18
Rummy18 2018 年 2 月 7 日
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!
  1 件のコメント
Joel  Borja
Joel Borja 2019 年 12 月 3 日
I would like to find an answer to this too.

サインインしてコメントする。

回答 (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
  1 件のコメント
Jose Agustin Barrachina
Jose Agustin Barrachina 2022 年 4 月 28 日
This is ALMOST what I need, but I have polygones and not rectangles... Any idea there?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage 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