Reputation: 385
I'm sorry, I'm a newby. I tried to copy the code find here
to obtain the same result, but it doesn't work (fault mine). I can not figure out how saveas
can understand which is the image that has to save. I've read that saveas
wants a Handle and a filename as input, and in the code that I fund in the link above I don't see these arguments:
saveas(sprintf('img%d.tif',num_picture))
Here is a short part of my code:
% Here a loop that transform aeach image inside the variable(cell array) 'immages'
for z = 1:length(immages) %images is a cell array contained the matrices of 100images
temp = immages{z}; %temp means temporary, that is the image to process
for i = 1:I % begin of cycle that process each pixel of the image(tmp)
for j = 1:J
if temp(i,j) == 0
temp(i,j) = 115;
else
temp(i,j) = 140;
end
end
end
cd(finalDest); %move into the directory whre I want to save the new image
figure;
imshow(temp);
saveas(sprintf('img%d.tif',z)); % HOW CAN I SAVE THE CURRENT IMAGE(TEMP) INSIDE 'FINALDEST'?
cd(initialDest); %return to the folder where the original images are contained
end
I encounter this error ERROR USING SAVEAS, line55: Requires handle to Figure or block diagram and filename.
Thank you so much.
Upvotes: 0
Views: 1220
Reputation: 46
You are right, saveas
needs a figure handle as first parameter, you can get one changing:
figure;
with
h = figure(z); //one figure per image
and
saveas(h, sprintf('img%d.tif',z));
or using gcf
to get a handle to the current figure:
saveas(gcf, sprintf('img%d.tif',z));
If you only want to save the information on the temp
matrix (not the entire figure) you should use IMWRITE:
imwrite(temp,sprintf('img%d.tif',z));
Upvotes: 2