Creating mask Datastore for Mask R-CNN
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am working with 126 (size 512x512) grayscale images. Each image has atleast 10-100 object instances. I labeled polygon masks and bounding boxes with the use of the image labeler app. I exported the ground truth and separated the images and bbox in their own datastore. Now I am looking to create the imagedatastore for the masks by following the instructions on:
Create Datastore that Reads Data: Create an imageDatastore and specify a custom read function that returns mask data as a binary matrix
I went on to follow the steps of converting the polygons labels to maskstacks. The mask stacks I got were as expexted the mask (h,w,numobjects). For example one of my maststacks was a 512x512x39 logical .
How do I format these mask stacks into an image datastore to train the mask RCNN.
0 commentaires
Réponse acceptée
T.Nikhil kumar
le 12 Fév 2024
Hi Bryce,
According to the documentation you’re following, the next step for you is to create an ‘imageDatastore’ that reads the mask data as a binary matrix.
I would suggest you to try this possible solution for the same.
1. After converting polygon labels into binary masks, you can save each mask stack in a .mat file with a suitable name (For eg: maskStack1.mat for the first image). You can put all these individual mask stack files in a ‘MaskStackFolder’ folder.
2. Now, define a custom read function that should take a file path as input and return the binary mask stack in the expected format. Refer to the following code snippet:
function mask = customReadFcn(filename)
% Load the data from the .mat file
loadedData = load(filename);
% Assuming the variable containing the mask stack is named 'maskStack'
mask = loadedData.maskStack;
% Ensure you are using correct variable name as per your naming
end
3. You can now create an ‘imageDatastore’ with this folder and custom read function.
maskFolder = "C:\MATLAB\MaskStackFolder"; % Replace with the actual path to your mask stack folder
% Create an imageDatastore for the mask stacks
masksDatastore = imageDatastore(maskFolder, 'ReadFcn', @customReadFcn);
Ensure that the order of the mask stacks in the ‘imageDatastore’ corresponds to the actual order of the images in the previously create image datastore for images.
I hope this answer is able to help you!
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!