1、内容简介

501-可以交流、咨询、答疑

2、内容说明

clear

clc

close all

digitDatasetPath = './high_change_gray/';

imds = imageDatastore(digitDatasetPath, ...

   'IncludeSubfolders',true, ...

   'LabelSource','foldernames');

%%

imds.ReadSize = 8;

rng(0)

imds = shuffle(imds);

[imdsTrain,imdsVal,imdsTest] = splitEachLabel(imds,0.9,0.05);

dsTrainNoisy = transform(imdsTrain,@addNoiseS);

dsValNoisy = transform(imdsVal,@addNoiseS);

dsTestNoisy = transform(imdsTest,@addNoiseS);

dsTrain = combine(dsTrainNoisy,imdsTrain);

dsVal = combine(dsValNoisy,imdsVal);

dsTest = combine(dsTestNoisy,imdsTest);

%%=

dsTrain = transform(dsTrain,@Preprocess);

dsVal = transform(dsVal,@Preprocess);

dsTest = transform(dsTest,@Preprocess);

dsTrain = transform(dsTrain,@augmentImages);

%%=

exampleData = preview(dsTrain);

inputs = exampleData(:,1);

responses = exampleData(:,2);

minibatch = cat(2,inputs,responses);

figure

montage(minibatch','Size',[8 2])

title('输入 (左边) 和 输出 (右边)')

%%

imageLayer = imageInputLayer([400,400,1]);

% 下采样

encodingLayers = [ ...

   convolution2dLayer(3,64,'Padding','same'), ...

   reluLayer, ...

   maxPooling2dLayer(2,'Padding','same','Stride',2), ...

   convolution2dLayer(3,32,'Padding','same'), ...

   reluLayer, ...

   maxPooling2dLayer(2,'Padding','same','Stride',2)];

% 上采样

decodingLayers = [ ...

   UpsampleConvLayer(2,32), ...

   reluLayer, ...

   UpsampleConvLayer(2,64), ...

   reluLayer, ...

   convolution2dLayer(3,1,'Padding','same'), ...

   clippedReluLayer(0.9), ...

   regressionLayer];    

layers = [imageLayer,encodingLayers,decodingLayers];

options = trainingOptions('adam', ...

   'MaxEpochs',10, ...

   'MiniBatchSize',6, ...

   'ValidationData',dsVal, ...

   'Shuffle','every-epoch', ...

   'Plots','training-progress', ...

   'Verbose',false)

%%

% load("net1.mat")

net = trainNetwork(dsTrain,layers,options);

%%

% options = trainingOptions('ExecutionEnvironment','cpu');

ypred = predict(net,dsTest,'ExecutionEnvironment','cpu');

size(ypred)

inputImageExamples = preview(dsTest);

for num = 1:8

   figure

   montage({inputImageExamples{num},ypred(:,:,:,num)});

   imwrite(inputImageExamples{num},FILENAME)

end

%%

imds1 = imageDatastore("./pic", ...

   'IncludeSubfolders',true, ...

   'LabelSource','foldernames');

ypred = predict(net,imds1, 'ExecutionEnvironment','cpu');

%%

num = 3;

a = inputImageExamples{num};

b = ypred(:,:,:,num);

figure

montage({a, b});

title('origin')

temp = single(b);

temp = imresize(temp,[400,400]);

temp = rescale(temp);

figure

montage({a, temp});

title('augment')

% imwrite(inputImageExamples{num},'./3_origin.jpg')

% imwrite(ypred(:,:,:,num),'./3_predict.jpg')


3、仿真分析

matlab 深度学习黑暗图片画质增强_2d

matlab 深度学习黑暗图片画质增强_ide_02

4、参考论文