imageDatastore for volumetric images

9 visualizaciones (últimos 30 días)
Memo Remo
Memo Remo el 5 de Feb. de 2023
Editada: Memo Remo el 11 de Feb. de 2023
I want to use the imageDatastore command to prepare the training set for training a volumetric convolutional neural network-based semantic segmentation model. I followed the instructions given on the MATLAB webpage below and provided my code with multilayered Tif files representing the input images and the labled input images (ground truth).
However, it seems imageDatastore just reads one of the layers (slices) and cannot process the volumetric images. Does anyone know how we should use this command for the volumetric image segmentation tasks? Or how can we prepare the training set for training a volumetric sementic segmentation model such as Unet 3D (https://www.mathworks.com/help/vision/ref/unet3dlayers.html)? Many thanks in advance.
  2 comentarios
NAVNEET NAYAN
NAVNEET NAYAN el 6 de Feb. de 2023
Can you please provide the details of the images like how did you save these images and also about the lines of code that you are having a problem?
Memo Remo
Memo Remo el 6 de Feb. de 2023
Editada: Memo Remo el 6 de Feb. de 2023
Dear Navneet,
Thanks for the reply.
I converted the images to a volume tif file using a MATLAB code that uses the imwrite command with the "append" writemode. I named this file as "Train_Vol".
Then I tried to use the code below to train my model:
-----------------------------------------------------------------------
Train_imds = blockedImage(Train_Tif_Dir);
classNames = ["L","BT"];
labelIDs = [255 0];
Train_pxds = pixelLabelDatastore(Train_LebelsDir,classNames,labelIDs);
Train_ds = combine(Train_imds,Train_pxds);
net = trainNetwork(Train_ds,lgraph)
----------------------------------------------------------------------
lgraph is the model architecture, and Train_LebelsDir is the directory in which I stored the volumetric tif file that contains labels for each training images in the Train_Vol tif file.

Iniciar sesión para comentar.

Respuesta aceptada

Ashish Uthama
Ashish Uthama el 7 de Feb. de 2023
Movida: Ashish Uthama el 8 de Feb. de 2023
blockedImage cannot convert the slices to a volumetric block on its own unfortunately! blockedImage is useful when you want to break one 'unit' into multiple logical sub-units (i.e one file into many constituting blocks). So its not useful for your workflow at this moment (especially, since it looks like your 'unit' of data will easily fit in memory).
Does this help?
You would replace the first argument of the constructors for imageDatastore and pixellabelDatastore with the list of files you have, their order ought to match to ensure images and labels are paired correctly!.
% Image data
im = uint8(magic(10));
imwrite(im,'vol.tif')
imwrite(im,'vol.tif','WriteMode','append')
imds = imageDatastore(["vol.tif"],'ReadFcn',@tiffreadVolume);
v = read(imds);
size(v)
% ans =
% 10 10 2
% Label data
labels = im>50;
imwrite(labels,'labels.tif')
imwrite(labels,'labels.tif','WriteMode','append')
lds = pixelLabelDatastore(["labels.tif"],["bg", "fg"], [0 1], 'ReadFcn',@tiffreadVolume);
% Combined data, where one read gives a data,label set:
cds = combine(imds, lds);
d = read(cds)
% d{1} will be image, d{2} will be corresponding labels.
  2 comentarios
Memo Remo
Memo Remo el 7 de Feb. de 2023
Movida: Ashish Uthama el 8 de Feb. de 2023
Yep! It works! Thank you so much, Ashish!
P.S. MATLAB forum doesn't let me accept your answer because it is posted under Rylan's answer. I think you should copy it into a new answer.
Memo Remo
Memo Remo el 11 de Feb. de 2023
Editada: Memo Remo el 11 de Feb. de 2023
When I want to train the model using this method, I get the following error. I can't understand what is missing here. Do you know how I may check for the error source?
Error using trainNetwork
Invalid or deleted object.
Error in UNet_Mine_V2_CW21_001RICA_TissueNice (line 916)
net = trainNetwork(Train_ds,lgraph,options)
Caused by:
Error using indexing
Invalid or deleted object.

Iniciar sesión para comentar.

Más respuestas (1)

Aylin
Aylin el 6 de Feb. de 2023
Hi Memo,
The blockedImage object (in Image Processing Toolbox) has documentation that mentions volumes within images:
A blockedImage object is an image made from discrete blocks. Use blocked images when an image or volume is too large to fit into memory. With a blocked image, you can perform processing without running out of memory.
There is an associated datastore which can be used to work with blockedImage called blockedImageDatastore.
Here is a list of examples which use blockedImageDatastore: https://www.mathworks.com/help/images/examples.html?category=large-image-files .
I hope this helps!
Rylan
  4 comentarios
Memo Remo
Memo Remo el 6 de Feb. de 2023
Editada: Memo Remo el 6 de Feb. de 2023
Dear Ashish,
I appreciate your help.
The subject I am working on is a very simple volumetric semantic segmentation task. Assume that I have five 256 by 256 greyscale images that represent consecutive parallel slices of a 3D object. I took these five images and manually marked the regions of interest in each of them (ground truth).
Now using the input slices and the labeled ones I want to train a volumetric segmentation model. To train such models we need to convert the five training slices and the five labeled slices to two volumetric images each with the dimensions of (256*256*5). Now we have the training and the labeled block.
I understood that the "blockedImage" can convert these slices to a volumetric block, but how can we use the "pixelLabelDatastore" and "combine" commands to link the pixels in the training block to their corresponding labels in the labeled block to train our segmentation model?
Memo Remo
Memo Remo el 6 de Feb. de 2023
I tried to the ReadFcn you mentioned. Unfortunately, it is not working. It just reads a single slice of the entire volume.
----------------------------
Train_imds = imageDatastore(Tissue_HL_Tif_Dir);
Train_imds.ReadFcn = @tiffreadVolume;
---------------------------
Where "Tissue_HL_Tif_Dir" is the location of volumetric tiff file.

Iniciar sesión para comentar.

Categorías

Más información sobre Deep Learning for Image Processing 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