Save several images with the same colormap

2 次查看(过去 30 天)
Here is my problem:
I have N matrixes generated on MatLab (N could be 1, 100, 1000, etc). How I generated them and why is not important.
I want to save those matrixes as images, with names in a sequence.
So at first I showed them to me using this code:
figure;
image(rho); #rho is the name of the matrix with all variables
colormap(hsv(ceil((rhomax-rhomin))));
cbh = colorbar('location', 'SouthOutside');
set(cbh, 'Units', 'normal', 'Xtick',0:0.5:ceil(rhomax));
text(2.5, -1, 'Densidade(g/cm³)', 'Parent', cbh);
And I got this:
I then tried to save those images using this part of a code.
r = sprintf('rho%04d.tif',d);
imwrite(rho,hsv((ceil(rhomax-rhomin))),r,'tif')
I use 'd' so I can later save another image with a number inside a sequence, for example, rho0001, rho0002, and so on.
And I got this:
As you can probably see, they are different, but they shouldn't be, because I'm using the same map - or, at least, I think I am.
So I think there is probably three possible answers to this problem:
1 - save the figures, with colorbars.
2 - find a colorbar to the second one
3 - solve this "puzzle" and have them be the same in the end.
Does anyone know how to do any of those 3? I don't know how to save those images with colorbars automatically. I also don't know how to find a colorbar for the 2nd image. And I'm still trying to figure out why those two images are different.

回答(1 个)

Image Analyst
Image Analyst 2014-6-2
if rho changes, hsv((ceil(rhomax-rhomin))) (your colormap) will change. Does that explain it?
To save the figures you can use export_fig() or getframe().
  5 个评论
Haimon
Haimon 2014-6-3
As of last time, the files are still big, so here is the link to a dropbox folder again:
https://www.dropbox.com/sh/4v66ly0m0ciezj2/AAAJ75GUFtcDSvcavp7KktMoa
One thing:
- the rho1 is the matrix after imshow, and rho2 is the matrix after imwrite. I also put in the folder the corresponding images for figure/colormap, imshow and imwrite, for the sake of comparison.
Haimon
Haimon 2014-6-4
I ended up using getframe to save the image.
I had to adapt with imshow to get all images, but at least now I can get them even with the colorbar included which also helps.
Also imshow seem to have better images, I'm not sure why.
However I really wanted to understand why the differences between the three options I mentioned. There's gotta be an explanation.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Red 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by