【问题标题】:How can I read specific images from TID2013 dataset in MATLAB?如何在 MATLAB 中从 TID2013 数据集中读取特定图像?
【发布时间】:2020-10-31 10:28:11
【问题描述】:

如何在 MATLAB 中从 TID2013 数据集中读取特定图像?我编写了以下代码,但它从列表的第一个到末尾开始。图像格式如下:ixx.yy.z.bmp 表示 xx 是图像数量,yy 是噪声模型,z 是噪声水平。我只想在 4,5 级使用模型 1,2,但我不知道该怎么做。请有人帮助我!顺便说一下,我在 info1.txt 、 info2.txt 、 info3.txt 中分别写了 25 个参考图像、24 个噪声模型和每个噪声模型的 5 个级别。

clc; clear; close all;
% read Original images
cd 'C:\Users\Desktop'
for NO1 = 1:25
    in1 = fopen('info1.txt');
    xx = fgets(in1);            
    A = imread(strcat('C:\Users\Desktop\reference_images\',xx,'.bmp'));
    A = rgb2gray(A);
end

% read distorted images
for NO1 = 1:25
    in1 = fopen('info1.txt');
    xx = fgets(in1);
    for NO2 = 1:24
        in2 = fopen('info2.txt');
        yy = fgets(in2);
        for NO3 = 1:5
            in3 = fopen('info3.txt');
            z = fgets(in3);
            B = imread(strcat('C:\Users\Desktop\distorted_images\',xx,yy,z,'.bmp'));
            B = rgb2gray(B);
            C = imadjust(B);
            % Write restored images
            imwrite(C,['C:\Users\Desktop\restored_images\','i',sprintf('%02d',NO1),'_',sprintf('%02d',NO2),'_',num2str(NO3),'.bmp']);
        end
    end
end

【问题讨论】:

    标签: matlab for-loop file-io


    【解决方案1】:

    您唯一需要做的就是更改 for 循环的值。请注意,在 matlab 中,与大多数其他语言相比,for-loops 不受特定步长的限制,可以是任何向量。

    imageNames = textread('info1.txt', '%s');
    noiseModels = textread('info2.txt', '%s');
    noiseLevels = textread('info3.txt', '%s');
    imageIndices = 1:25;
    modelIndices = [1, 2, 7:8];
    levelindices = [4 5];
    sourceDir = 'C:\Users\Desktop\distorted_images\';
    destDir  = 'C:\Users\Desktop\restored_images\';
    for ii = imageIndices
        name = imageNames{ii};
        for jj = modelIndices
            model = noiseModels{jj};
            for kk = levelindices
                level = noiseLevels{kk};
                sourcePath = sprintf('%s%s%s%s.bmp', sourceDir, name, model, level)
                destPath = sprintf('%si%02d_%02d_%02d.bmp', destDir, ii, jj, kk)
                B = imread(sourcePath);
                B = rgb2gray(B);
                C = imadjust(B);
                imwrite(C, destPath);
            end
        end
    end
    

    【讨论】:

      猜你喜欢
      • 2014-07-05
      • 1970-01-01
      • 2015-12-30
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      相关资源
      最近更新 更多