saveas parameter understanding gcf

Provide direct saveas Matlab function may specify a block diagram of the figure or image is stored in simulink. saveas format is:
saveas (GCA, filename, fileformat), wherein the three parameters:
(. 1) GCA: graphics handle if the graphics window title bar is "Figure 3", the handler is 3; may be acquired directly gcf The current window handle.

(2) filename: single quotes string that specifies the file name
(3) fileformat: single quotes string specified storage format

Note: gcf is the current window handle acquired, if you say three to four display image, without adding

figure (1);
hold on;
figure (2);
hold on;
figure (3);
hold on;

The following situations occurs, that image is always saved the last displayed.
Here Insert Picture Description
As Figure: I_1 and I_4 are the same image, we did not reach our goal.

error code:


% 1. 看一下变量的类型和大小
% 
% 2. 用imshow命令显示图像,并截图下来提交作业;用saveas命令保存图像;
% 
% 3. 利用imresize命令将图像长宽分别缩小至1/4,以及扩大至4倍,保存图像;
% 
% 4. imbinarize(I),将灰度的lena图二值化,保存图像;
% 


%Q1:
I = imread('./lena_gray.jpg');
I3 = imread('./lena.bmp');
%Q2:
imshow(I);

imshow(I3);

%Q3:
I_1 = imresize(I3,0.25);
saveas(gcf,['image\','I_1.bmp']);
I_4=imresize(I3,4);
saveas(gcf,['image\','I_4.bmp']);

%Q4:
BW=imbinarize(I);
saveas(gcf,['image\','BW']);
%imshow(BW);
%Q5:
    

After trimming code:


% 1. 看一下变量的类型和大小
% 
% 2. 用imshow命令显示图像,并截图下来提交作业;用saveas命令保存图像;
% 
% 3. 利用imresize命令将图像长宽分别缩小至1/4,以及扩大至4倍,保存图像;
% 
% 4. imbinarize(I),将灰度的lena图二值化,保存图像;
% 


%Q1:
I = imread('./lena_gray.jpg');
I3 = imread('./lena.bmp');
%Q2:
figure(3);
imshow(I);
hold on;
imshow(I3);

%Q3:
I_1 = imresize(I3,0.25);
figure(1);
imshow(I_1);
hold on ;
saveas(gcf,['image\','I_1.jpg']);

I_4=imresize(I3,4);
figure(2);
imshow(I_4)
hold on;
saveas(gcf,['image\','I_4.jpg']);

%Q4:
BW=imbinarize(I);

figure(4);
imshow(BW);
hold on;
saveas(gcf,['image\','BW.jpg']);
%Q5:
    

Released nine original articles · won praise 13 · views 9511

Guess you like

Origin blog.csdn.net/ABV09876543210/article/details/104828260