Info

This question is closed. Reopen it to edit or answer.

How can I turn a 500x500x6 matrix into an image?

1 view (last 30 days)
Carlijn
Carlijn on 22 Jul 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
I have trained a neural network with images with corresponding 6 possible labels per pixel. So each pixel is annotated with one of the labels 1 to 6.
The output I have after applying the trained neural network to a new picture is the similarities of each label to each pixel. So when I feed a greyscale 500x500 image, I get a resulting 500x500x6 matrix.
I manage to display a picture of the indexes of the labels with the highest ownership per pixel. Now I would like to also be able to see if a pixel has a high similarity with multiple labels. As an example when you display an RGB image, the white pixels or yellow ones are what i'm interested in.
Any ideas on how to create a picture from a 500x5000x6 matrix?

Answers (1)

Image Analyst
Image Analyst on 22 Jul 2015
Why does it have 6 planes (slices)? It should have one. The image should be 500x500 with each pixel having the value of the class it was assigned. If you don't have this, but instead have planes that are all zero except that they're 1 in the plane where that pixel has been assigned that class, you can make the image simply by scanning the image.
[rows, columns, numberOfClasses] = size(nnImage);
classifiedImage = zeros(rows, columns);
for c = 1 : numberOfClasses
for col = 1 : columns
for row = 1 : rows
if nnImage(row, col, c) ~= 0
classifiedImage(row, col) = c;
end
end
end
end
imshow(classifiedImage, []);
colormap(jet(numberOfClasses));
colorbar;
  2 Comments
Carlijn
Carlijn on 23 Jul 2015
I think I am doing the same now by finding the label with the maximum value out of the six and putting the index of this label in the pixel. I suppose I should emphasize on the process of neural network as each pixel should ideally end up with one assigned label in the end.
Image Analyst
Image Analyst on 23 Jul 2015
I did not think so. My code gives you a classified image based on what I assumed the NN gave you. If that's not the case, then explain what is in each of the 6 planes that the NN gives you. Is it not all zeros except for a 1 in the plane of the class it thinks that pixel belongs to? Because that's what I assumed. If I'm wrong, tell me what it actually is.

Community Treasure Hunt

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

Start Hunting!