求基于BP神经网络的图像复原算法的matlab代码 5
3个回答
展开全部
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');
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');
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
万山数据
2024-11-14 广告
2024-11-14 广告
实时数仓处理是我们北京万山数据科技有限公司数据处理能力的核心之一。它基于先进的流处理技术,能够实时捕获、处理和分析海量数据,确保数据的时效性和准确性。通过构建高效的实时数据管道,我们能够实现数据的即时入库与查询,为业务决策提供强有力的支持。...
点击进入详情页
本回答由万山数据提供
2013-07-10
展开全部
已经发私信给你了
追问
没看到啊
追答
百度的私信,我无语啊,留下我的邮箱吧,给我发信吧。ajitaiajitai@163.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
去知网搜索吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询