Save several images with the same colormap

조회 수: 4 (최근 30일)
Haimon
Haimon 2014년 6월 2일
댓글: Haimon 2014년 6월 4일
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에서 White에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by