Pixel values to Image

4 views (last 30 days)
Nils Boden
Nils Boden on 24 Jan 2017
Edited: Benjamin Kraus on 24 Jan 2017
Hey,
Hopefully someone can help me with my problem, I cant seem to find a proper solution. I have a very big .txt file with depth values, one value per row. I want to create an image using these depth values, the grid has to be 170000x170000.
The color of each Pixel has to be dependend on the Value, so that I get a depth-map visualitsation from my Values.
I hope I described the problem good enough, thanks for any help.
  2 Comments
Jan
Jan on 24 Jan 2017
If you have "one value per row", how can the information about the X and Y position be obtained?
Nils Boden
Nils Boden on 24 Jan 2017
Because I have the resolution of the final image, from which the data comes. Its 170.000x170.000, so my .txt has 28.900.000.000 rows.

Sign in to comment.

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 24 Jan 2017
Edited: Benjamin Kraus on 24 Jan 2017
You need to read in your text file using one of the methods described on this doc page: Ways to Import Text Files. If your data is just a single column, most of those functions should work.
Once you've imported your data, you need to reshape the data to your square matrix.
Then you can call something like imagesc to make it into an image. You may want to adjust the colormap afterward.
Something like this:
vals = dlmread('bigdata.txt');
vals = reshape(vals, 170000, 170000);
imagesc(vals)
Note that MATLAB is column-major, so the first row of vals will be the first 170000, the second row will be the second 170000, etc. You can transpose the matrix if this isn't what you wanted by adding a single quote following the call to reshape:
vals = dlmread('bigdata.txt');
vals = reshape(vals, 170000, 170000)';
imagesc(vals)

More Answers (0)

Categories

Find more on Images 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!