Save an intensity image created with imagesc with true resolution

85 views (last 30 days)
Hello,
I have a pixel array 2560*2160 with intensity values from 0 to 5070 and I want just an image file (with the true resolution of 2560*2160)(bmp,png,jpg, whatever) with a nice display of this array.
I can get a good image with:
imagesc(data,'CDataMapping','scaled');
but I fail to save the outputed image in true resolution. Saveas and print don't work because it gets really messy with dpi and papersize.
The only thing close to what I want is by using:
data=data/5070;
imwrite(data, 'filename.png')
but then my image is of course only in grayscale, because the colormap is wrong.
I think there is a way using parula and get the right colormap from the image created with imagesc, but I just cant figure out how to combine this with imwrite.
Thanks for your help!

Accepted Answer

Walter Roberson
Walter Roberson on 16 May 2017
imwrite( uint16(YourData), parula(5070), filename)
or
imwrite( ind2rgb(im2uint8(mat2gray(YourData)), parula(256)), filename)
  3 Comments
Simon Streit
Simon Streit on 16 May 2017
Your second line of code works! I just had no access to the image processing tool, but now it's all fine!
Thank you very much!

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 15 May 2017
I think you didn't look at the help for imwrite(). In there it says:
imwrite(A,map,filename) writes the indexed image in A and its associated colormap, map, to the file specified by filename.
So, don't divide your image by 5070, just pass in parula(256) for the map input.

Simon Streit
Simon Streit on 16 May 2017
Thank you for your answers!
I tried a lot of combinations, but none of them worked:
Just passing parula(256) doesn't get the colormap right for me, because the image gets just way to 'bright'.
Using uint16 conversion only helps if I use a .tif-file, which is not easy to handle. I don't know much about imagefile formats, so I am probably missing the point of my problem, but here are the results:
On the left is what my figure looks like and what i would like to have as an image, the second is picture is saved with parula(256) and the last one with parula(5070) (allwithout conversion to uint16 because it didn't change my output):
Thank you for your patience!
  4 Comments
Simon Streit
Simon Streit on 16 May 2017
Edited: Simon Streit on 16 May 2017
The class is double. Here should be the data:
Edit:I tried to download my own data but it looks currupted. Reupload did not fix the issue. Are you able to download it or is there any other way than attaching it to this post? If it doesn't work here is a dropbox link: data
Walter Roberson
Walter Roberson on 16 May 2017
In my test,
YourData = pixels;
filename = 'testmat.png';
imwrite( ind2rgb(im2uint8(mat2gray(YourData)), parula(256)), filename)
worked well, producing the same output as
imagesc(pixels);
colormap(parula(256));

Sign in to comment.

Categories

Find more on Image Processing Toolbox 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!