Save an invisible figure in an image matrix without priniting the matrix on the screen

3 次查看(过去 30 天)
Hello,
I've been working on this for days and I haven't found any satisfying solution yet. I am working on a script generating a lot of images in a for loop. I have to use tow figures because I need two different colormap. If there's a way of plotting the surf with the two different colormap in the same figure, it'll be much easier but I read that it's impossible.
After initialising two figures in invisible mode ('visible'='off') with explicit set of the resolution and compute all the variables I need, here is what I want to do inside the loop :
  1. plot some stuffs in both figures
  2. save an image of the first figure in matrix IMG1 with the same resolution as in the initialisation and save an image of the second figure in matrix IMG2 with the same resolution
  3. take a portion of the first matrix and a portion of the second matrix to make a new image matrix
  4. save the the final image with imwrite()
The only solution I found to do the 2. is to save each image in a file with print() and then store it with imread(). But it's awfully long. I need to generate approximately 800.000 images and for the moment, the script is approximately 8 days long 24/24.
Does anybody have a solution to do the 2. without writing the files on the disc? I tried with getframe but getframe make the figures appear and so make the script much much slower.
Thank you
ToM

回答(2 个)

Oleg Komarov
Oleg Komarov 2011-8-4
Is this what you're trying to do, superimpose two surf with two different colormaps?
h.f = figure;
h.a(1) = axes('Parent',h.f);
[x,y,z] = peaks(30);
surfc(h.a(1),x,y,z)
colormap hsv
axis([-3 3 -3 3 -10 5])
h.a(2) = axes('Parent',h.f);
k = 5;
n = 2^k-1;
[x,y,z] = sphere(n);
c = hadamard(2^k);
surf(h.a(2),x,y,z,c);
set(h.a(2),'Color','none','Xlim',[-3 3],'Ylim',[-3 3],'Zlim',[-10 5])

ToM
ToM 2011-8-5
Oleg Komarov : "Is this what you're trying to do, superimpose two surf with two different colormaps?"
Yes, actually it's exactly that. But your code doesn't work for a simple reason : colormap is a property of the figure and not of the axe so if you have 2 different axes inside one figure, a changing of the colormap affects both axes.
Anyway, thanks to you I looked deeper into the surf and surfc properties and I found a solution. But it's a bit complicated.
The solution I found is to do
surf(axeHandle,dataMatrix,cData);
where cData is a m-n-3 matrix (assuming dataMatrix is m-n) specifying the color values (in true color) for each point of dataMatrix. The color of this surf is then indepedant from the colormap of the figure. As one of my colormap is in grayscale, the value of cData is easy to compute and I choose a colormap for the other surf.
Thanks :)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by