%% 实验一 1.1 使用 imshow 函数显示图片
clc
my_im_path = ('assets/');
picture1 = fullfile(my_im_path,'house.tiff');
picture2 = fullfile(my_im_path,'4.1.05.tiff');
picture3 = fullfile(my_im_path,'GPT-5_ResearchBlog_ArtCard_1x1.png');
figure('Color','white')
subplot(3,1,1);
imshow(imread(picture1));
subplot(3,1,2);
imshow(imread(picture2));
subplot(3,1,3);
imshow(imread(picture3));
%% 实验一 1.2 使用 subimage 函数显示图片
clc
my_im_path = ('assets/');
picture4 = fullfile(my_im_path,'footer-logo2.png');
picture5 = fullfile(my_im_path,'4.1.08.tiff');
picture6 = fullfile(my_im_path,'4.2.07.tiff');
figure('Color','white')
subplot(2, 2, 1), subimage(imread(picture4));
subplot(2, 2, 2), subimage(imread(picture5));
subplot(2, 2, 3), subimage(imread(picture6));

%% 实验一 2 制作GIF动画
clc
clear
my_im_path = 'assets/';

% 读取图像文件
picture1 = fullfile(my_im_path,'house.tiff');
picture2 = fullfile(my_im_path,'4.1.05.tiff');
picture3 = fullfile(my_im_path,'GPT-5_ResearchBlog_ArtCard_1x1.png');
picture4 = fullfile(my_im_path,'footer-logo2.png');
picture5 = fullfile(my_im_path,'4.1.08.tiff');
picture6 = fullfile(my_im_path,'4.2.07.tiff');

% 读取所有图像到cell数组
images = {
    imread(picture1);
    imread(picture2);
    imread(picture3);
    imread(picture4);
    imread(picture5);
    imread(picture6)
};

% 设置GIF文件名
filename = 'my_image_animation.gif';

% 逐帧制作GIF
for idx = 1:length(images)
    % 显示当前图像
    figure('Color','white', 'Visible', 'off'); % 不显示图形窗口
    imshow(images{idx});
    title(['图像 ' num2str(idx)]);
    
    % 捕获当前图窗作为帧
    frame = getframe(gcf);
    img = frame2im(frame);
    
    % 转换为索引图像
    [A, map] = rgb2ind(img, 256);
    
    % 写入GIF文件
    if idx == 1
        % 第一帧：创建GIF文件
        imwrite(A, map, filename, 'gif', ...
                'LoopCount', Inf, ...    % 无限循环
                'DelayTime', 1);         % 每帧显示1秒
    else
        % 后续帧：追加到GIF文件
        imwrite(A, map, filename, 'gif', ...
                'WriteMode', 'append', ... % 追加模式
                'DelayTime', 1);          % 每帧显示1秒
    end
    
    % 关闭当前图窗
    close(gcf);
end

% 显示完成信息
fprintf('GIF动画已成功生成：%s\n', filename);
fprintf('共包含 %d 帧图像\n', length(images));


