How do I pass images through my neural network if they are contained in a tiff file as image stack?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have images containing particles at certain locations. I want to pass the images through my convolutional neural network, giving labels with the coordinates of the particles in my images. I want my neural network to recognize images and give the coordinates of the particles. The images are contained in a tiff file which contains a stack of 60x60x1x3000 images (height x width x channel x numberImages).
The problem is, I don't know how to pass these images through my neural network to train it, since it is contained in an image stack inside a tiff file. I also want to give the coordinates of the particles in every image so the network can train on the correct coordinates.
I have tried using imds, which I did not succeed.
Loading in the array of the tiff file, I tried this: (I actually dont want this, since I want to use the tiff file itself using imds)
net = trainNetwork(imageStack(:,:,1:2500),[60x60x1x2500],layers,options)
If I use an imageInputLayer it says the dimensions cannot be 60x60x1x2500].
If i use an image3DInputLayer it says it will use filters in the 3rd dimension. But I don't want that, as it it not a single 3D image but a stack of 2D images.
I also have no idea how to give the correct coordinates with every image.
I have been reading documentations all day and I cannot figure it out. All help would be appreciated! Thanks!
0 comentarios
Respuestas (1)
T.Nikhil kumar
el 11 de Oct. de 2023
Hello Kevin,
I understand that you have a set of images with particles in random locations and want to train a Convolutional Neural Network to detect the coordinates of particles in your images. You want to pass your images that are stored in a multi-image ‘.tiff’ file to the network and also want to provide correct coordinates data for training.
For reading individual image files as a 4D array object (height x width x channel x numberImages), I would suggest you use the ‘imread’ function and loop through the number of images in your stack and concatenate into a new array along the 4th dimension using the ‘cat’ function. You can use the below code as reference:
XTrain=imread("stackexample.tif",1); %% Creating a new array (XTrain) that is going to be the 4D image array
for i=2:5
XTrain=cat(4,XTrain,imread("stackexample.tif",i)); %%Concatenating each image file in the .tiff stack along the 4th dimension of new array
end
For creating the ground truth data i.e. the coordinates of particles on images you can use the ‘Image Labeler’ app and manually mark the coordinates on each image.
In case you already have your coordinates data in any format, convert it into a categorical column vector containing the labels for each image. You can name it ‘YTrain’.
Now, you can create ‘arrayDatastore’ type objects for both the image data and the label data after which you can combine them as a ‘combinedDatastore’ type object. You can use the below code as reference:
%Creating array datastores
adsXTrain=arrayDatastore(XTrain);
adsYTrain=arrayDatastore(YTrain);
%Combining them into a combined Datastore
cmds=combine(adsXTrain,adsYTrain);
You can now use this ‘combinedDatastore’ object as an input for training using ‘trainNetwork’ function. You can set your own training options and can use ‘imageInputLayer’ with a size of one of your images (60X60X1) as the first layer.
net = trainNetwork(cmds,layers,options);
1.You can refer to the following documentation to understand more about reading data from ‘tiff’ files:
2.You can refer to the following documentation to understand more about ‘cat function:
3.Documentation about Image Labeler App:
4.You can refer to the following documentation to understand about inputs to ‘trainNetwork’ function
Hope this helps you to proceed further.
0 comentarios
Ver también
Categorías
Más información sobre Image Data Workflows 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!