Save just image (and not full figure) in a loop without needing user input

조회 수: 1 (최근 30일)
Hi all,
I'm working on a program which generates lots of figures/images in a for-loop. As I want to creat up to 1000 images I would like to avoid any user input when saving the images (I just want the program to run).
My problem is that I do only want to save the image and not the full figure. With imsave I can save an image (after being asked to specify the file-name myself for each loop), with saveas I can save all figures withtout user input (just with an updated string) but not just the image. How could I combine this so that I end up with a command which saves just a (tiff)-image from the generated plot/figure without needing a user input every time?
My code for the loop is as follows (with lcn as given 3D array):
for slice = 1:100; h = imagesc(squeeze(lcn(slice,:,:))); name = num2str(slice) saveas(h,slice,'tif') end
/David

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 3월 14일
h is a handle to the figure and a scalar value. What you want is
for ...
name = ...
imwrite(squeeze(lcn(slice,:,:)),name,'tif');
end

추가 답변 (3개)

Laura Proctor
Laura Proctor 2011년 3월 14일
  댓글 수: 1
David
David 2011년 3월 14일
Dear Laura,
I tried to implement imwrite but I'm just getting blank images. Do you know what I could be doing wrong?
Ex:
for slice = 1:100;
h = imagesc(squeeze(lcn(slice,:,:)));
string = num2str(iter);
string2 = '.tif'
name = [string string2];
imwrite(h,name,'tif')
end

댓글을 달려면 로그인하십시오.


David
David 2011년 3월 14일
Sorry, but I'm just inserting my comment as an answer to keep the discussion going. Thanks again. /David ----------------------------------------------------- Dear Laura,
I tried to implement imwrite but I'm just getting blank images. Do you know what I could be doing wrong?
Ex:
for slice = 1:100; h = imagesc(squeeze(lcn(slice,:,:))); string = num2str(iter); string2 = '.tif' name = [string string2]; imwrite(h,name,'tif') end
/David

David
David 2011년 3월 15일
Well, the answer was actually as simple as that! imagesc is a handle to the figure or image being plotted!
Using your solution Sean works perfectly fine! Thanks for all the help!
All the best /David
  댓글 수: 1
Jan
Jan 2011년 3월 15일
Does this mean, that you accept his answer? Then please hit the corresponding button to mark this question as solved.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by