求基于BP神经网络的图像复原算法的matlab代码

硕士论文是这个方向,不知道谁有这方面的matlab代码或者例子,传一下给我,谢谢。

第1个回答  2018-04-14
function Solar_SAE
tic;
n = 300;
m=20;
train_x = [];
test_x = [];
for i = 1:n
%filename = strcat(['D:\Program Files\MATLAB\R2012a\work\DeepLearn\Solar_SAE\64_64_3train\' num2str(i,'%03d') '.bmp']);
%filename = strcat(['E:\matlab\work\c0\TrainImage' num2str(i,'%03d') '.bmp']);
filename = strcat(['E:\image restoration\3-(' num2str(i) ')-4.jpg']);
b = imread(filename);
%c = rgb2gray(b);
c=b;
[ImageRow ImageCol] = size(c);
c = reshape(c,[1,ImageRow*ImageCol]);
train_x = [train_x;c];
end
for i = 1:m
%filename = strcat(['D:\Program Files\MATLAB\R2012a\work\DeepLearn\Solar_SAE\64_64_3test\' num2str(i,'%03d') '.bmp']);
%filename = strcat(['E:\matlab\work\c0\TestImage' num2str(i+100,'%03d') '-1.bmp']);
filename = strcat(['E:\image restoration\3-(' num2str(i+100) ').jpg']);
b = imread(filename);
%c = rgb2gray(b);
c=b;
[ImageRow ImageCol] = size(c);
c = reshape(c,[1,ImageRow*ImageCol]);
test_x = [test_x;c];
end
train_x = double(train_x)/255;
test_x = double(test_x)/255;
%train_y = double(train_y);
%test_y = double(test_y);

% Setup and train a stacked denoising autoencoder (SDAE)
rng(0);
%sae = saesetup([4096 500 200 50]);
%sae.ae{1}.activation_function = 'sigm';
%sae.ae{1}.learningRate = 0.5;
%sae.ae{1}.inputZeroMaskedFraction = 0.0;

%sae.ae{2}.activation_function = 'sigm';
%sae.ae{2}.learningRate = 0.5
%%sae.ae{2}.inputZeroMaskedFraction = 0.0;

%sae.ae{3}.activation_function = 'sigm';
%sae.ae{3}.learningRate = 0.5;
%sae.ae{3}.inputZeroMaskedFraction = 0.0;

%sae.ae{4}.activation_function = 'sigm';
%sae.ae{4}.learningRate = 0.5;
%sae.ae{4}.inputZeroMaskedFraction = 0.0;

%opts.numepochs = 10;
%opts.batchsize = 50;
%sae = saetrain(sae, train_x, opts);
%visualize(sae.ae{1}.W{1}(:,2:end)');

% Use the SDAE to initialize a FFNN
nn = nnsetup([4096 1500 500 200 50 200 500 1500 4096]);
nn.activation_function = 'sigm';
nn.learningRate = 0.03;
nn.output = 'linear'; % output unit 'sigm' (=logistic), 'softmax' and 'linear'

%add pretrained weights
%nn.W{1} = sae.ae{1}.W{1};
%nn.W{2} = sae.ae{2}.W{1};
%nn.W{3} = sae.ae{3}.W{1};
%nn.W{4} = sae.ae{3}.W{2};
%nn.W{5} = sae.ae{2}.W{2};
%nn.W{6} = sae.ae{1}.W{2};
%nn.W{7} = sae.ae{2}.W{2};
%nn.W{8} = sae.ae{1}.W{2};

% Train the FFNN
opts.numepochs = 30;
opts.batchsize = 150;
tx = test_x(14,:);
nn1 = nnff(nn,tx,tx);
ty1 = reshape(nn1.a{9},64,64);

nn = nntrain(nn, train_x, train_x, opts);
toc;
tic;
nn2 = nnff(nn,tx,tx);
toc;
tic;
ty2 = reshape(nn2.a{9},64,64);
tx = reshape(tx,64,64);
tz = tx - ty2;
tz = im2bw(tz,0.1);
%imshow(tx);
%figure,imshow(ty2);
%figure,imshow(tz);
ty = cat(2,tx,ty2,tz);
montage(ty);
filename3 = strcat(['E:\image restoration\3.jpg']);
e=imread(filename3);

f= rgb2gray(e);
f=imresize(f,[64,64]);
%imshow(ty2);
f=double (f)/255;
[PSNR, MSE] = psnr(ty2,f)
imwrite(ty2,'E:\image restoration\bptest.jpg','jpg');
toc;
%visualize(ty);
%[er, bad] = nntest(nn, tx, tx);
%assert(er < 0.1, 'Too big error');本回答被网友采纳
第2个回答  2013-07-10
已经发私信给你了追问

没看到啊

追答

百度的私信,我无语啊,留下我的邮箱吧,给我发信吧。[email protected]

第3个回答  2013-07-06
去知网搜索吧