Effacer les filtres
Effacer les filtres

Save several images with the same colormap

3 vues (au cours des 30 derniers jours)
Haimon
Haimon le 2 Juin 2014
Commenté : Haimon le 4 Juin 2014
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.

Réponses (1)

Image Analyst
Image Analyst le 2 Juin 2014
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 commentaires
Haimon
Haimon le 3 Juin 2014
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 le 4 Juin 2014
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Red dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by