matlab读取多幅图片,并对读取的图片降采样和双三次插值

时间:2024-03-02 08:56:31
clear all
clc
  
im = {}; %%创建字典im以保存读取的图片
dis = dir(\'C:\Users\KCl\Documents\MATLAB\SRCNN\Set5\*.bmp\');
for i = 1:length(dis)
    path = strcat(\'C:\Users\KCl\Documents\MATLAB\SRCNN\Set5\\',dis(i).name);
    im{i} =imread(path); %%将读取到的图像存储在字典im中
    up_scale = 3; %%将降采样系数设为3,即图像缩小3倍
    if size(im{i},3)>1 %%如果图像不是单通道,则转化为灰度图
        im{i} = rgb2ycbcr(im{i});
        im{i} = im{i}(:, :, 1);
    end
     
    im_gnd{i} = modcrop(im{i}, up_scale);
    im_gnd{i} = single(im_gnd{i})/255;
 
%% bicubic interpolation
    im_l{i} = imresize(im_gnd{i}, 1/up_scale, \'bicubic\');
    im_b{i} = imresize(im_l{i}, up_scale, \'bicubic\');
 
    figure,imshow(im_l{i})
    figure,imshow(im_b{i}) %%为了同时显示多幅图片,不加figure的话只会显示一副图片,因为读入的第i副图片会被第i+1副图片覆盖
 
end
a = \'完成\'

转自:http://www.cnblogs.com/anyview/p/5057460.html