如何使用以下自动编码器相关代码缩小图像尺寸?

时间:2019-05-26 11:11:09

标签: matlab autoencoder

我制作了一个与自动编码器相关的MATLAB代码,我想减小图像的尺寸。输入了一些二进制图像。

我应该对以下matlab代码进行哪些更改?

 path1 = '/home/sanjay/Desktop/usable data/CASIA_B90PerfectCentrallyAlinged_Resized_with_140by140_Energy_Image/';    
save_path='/home/sanjay/Desktop/usable data/CASIA_B90PerfectCentrallyAlinged_Resized_with_140by140_Energy_ImageCompressed/';
list1 = dir(path1);
fName1 = {list1.name};
[~,y1]=size(fName1);
save_path
count=1;
xTrainImages = cell(0,0);
for f_no=3:y1
    path2=char(strcat(path1,fName1(f_no),'/'));
    list2 = dir(path2);
    fName2 = {list2.name};
    [~,y2]=size(fName2);
    %fName1(f_no)
    for ff_no=9:y2
        path3= char(strcat(path2,fName2(ff_no)));
        image = double(imread(path3));
        max1 = max(image(:));
        image = image/max1;
        xTrainImages{count} = image;
        count = count+1;
    end
end

rng('default');
hiddenSize1 = 12;

autoenc1 = trainAutoencoder(xTrainImages,hiddenSize1, 'MaxEpochs',20, 'L2WeightRegularization',0.04, 'SparsityRegularization',4, 'SparsityProportion',0.15, 'ScaleData', false);

figure()
plotWeights(autoenc1);

path = '/home/sanjay/Desktop/usable data/CASIA_B90PerfectCentrallyAlinged_Resized_with_140by140_Energy_Image/001/bg-01.png';
image = double(imread(path));
max1 = max(image(:));
image = image/max1;
figure,imshow(image);

Z = encode(autoenc1,image);

y = decode(autoenc1,Z);

figure, imshow(y{1});
size(y{1})

0 个答案:

没有答案