How to convert the text file (1x290400) to image as shown as below?
Show older comments

After I done simulatation, ModelSim gives me an output image file in text file format when doing the convolution neutral network.
However, the output image in text file is 1 column vector. (1x290400)
Community have an example codes to convert the 1 column vector text file to become an image like above (55x55x96)?There is 96 pictures in 1 output picture and each size is 55x55
Please help me and thank a lot..
9 Comments
Walter Roberson
on 18 Aug 2019
data = uint8(load('output_data_1.txt'));
d4 = permute( reshape(data, [], 55, 55), [3 2 1]);
montage(d4)
Tham Wei Jian
on 19 Aug 2019
Walter Roberson
on 19 Aug 2019
I need to see the complete error message.
The code worked when I tested it.
Tham Wei Jian
on 20 Aug 2019
Walter Roberson
on 20 Aug 2019
data = uint8(load('output_data_1.txt'));
d4 = permute( reshape(data, [], 55, 55), [3 2 4 1]);
montage(d4)
Tham Wei Jian
on 21 Aug 2019
Edited: Tham Wei Jian
on 21 Aug 2019
KALYAN ACHARJYA
on 21 Aug 2019
Its a dimension order
Detail read here
Walter Roberson
on 21 Aug 2019
Imagine that you were to take all of the data for your images and arrange it into a 3D cuboid. Now with that cuboid start numbering pixels consecutively.
For any particular x and z, number all of the y in increasing distance from the x axis (the first column of data). Once the first column is done, continue numbering from the beginning of the second column near the x axis and getting further from x axis
Y5+ 5 10 15
Y4+ 4 9 14
Y3+ 3 8 13
Y2+ 2 7 12
Y1+ 1 6 11
+++++++++
X1 X2 X3
That would be for Z1. Now continue with Z2 which would continue the same pattern but the entries would be numbered 15 higher in this example.
You can take consecutive pixels from the input file and order them in this way to build a 3d array of images. Though in your case each image would be 55 x 55 instead of the 5 x 3 that I show in this example.
Now that we have seen how pixels can be taken from a serial data and rearranged into 3d with each z slice being a different image, I want you to imagine taking the cuboid and turning it. Now take the rotated cuboid and number them using the same system as before. All of the same data is there but a different order.
The permute call effectively tells you which axes order you need to read the data to get ordering that matlab expects. [3 2 1] is ttracing along the z axis then the x axis then the y axes. The 4 in 3 2 4 1 acts to introduce an axis that is length 1 that is needed for technical reasons
Tham Wei Jian
on 22 Aug 2019
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!