How to extract images from groundTruth object?

6 visualizaciones (últimos 30 días)
Rummy18
Rummy18 el 7 de Feb. de 2018
Comentada: Jose Agustin Barrachina el 28 de Abr. de 2022
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!

Respuestas (2)

awezmm
awezmm el 3 de En. de 2020
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 comentarios
Theresa Pflüger
Theresa Pflüger el 21 de En. de 2020
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 el 24 de En. de 2020
Is this the actual labeled image? Can you please attach the labeled image after you export after labeling.

Iniciar sesión para comentar.


Rummy18
Rummy18 el 24 de En. de 2020
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 comentario
Jose Agustin Barrachina
Jose Agustin Barrachina el 28 de Abr. de 2022
This is ALMOST what I need, but I have polygones and not rectangles... Any idea there?

Iniciar sesión para comentar.

Categorías

Más información sobre Image and Video Ground Truth Labeling en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by