![](https://csdnimg.cn/release/download_crawler_static/88422039/bg5.jpg)
n= 1;
for i = 1 : row-patchsize+1
for j = 1 : col - patchsize+1
Opt_Block = Opt(i:i+patchsize-1,j:j+patchsize-1);
SAR_Block = SAR(i:i+patchsize-1,j:j+patchsize-1);
Opt_patches(:,n) = Opt_Block(:);
SAR_patches(:,n) = SAR_Block(:);
n = n+1;
end
end
%% ---------------------------------------------------------------
% For the autoencoder to work well we need to normalize the data
% Specifically, since the output of the network is bounded between [0,1]
% (due to the sigmoid activation function), we have to make sure
% the range of pixel values is also bounded between [0,1]
% Opt_patches = normalizeData(Opt_patches);
% SAR_patches = normalizeData(SAR_patches);
Opt_patches = (Opt_patches)./max(max(Opt_patches));
SAR_patches = (SAR_patches)./max(max(SAR_patches));
%% ---------------------------------------------------------------
function patches = normalizeData(patches)
% Squash data to [0.1, 0.9] since we use sigmoid as the activation function in the output layer
% Remove DC (mean of images).
patches = bsxfun(@minus, patches, mean(patches));
% Truncate to +/-3 standard deviations and scale to -1 to 1
pstd = 3 * std(patches(:)); patches = max(min(patches, pstd), -pstd)
/ pstd;
% Rescale from [-1,1] to [0.1,0.9]
patches = (patches + 1) * 0.4 + 0.1;
expand_im.m
function output = expand_im(input,patchsize)
%% expand the input images
% SAR1 = imread('OttwaH.bmp');% SAR1=SAR1(:,:,1);
% SAR1 = rand(6,6); % patchsize = 5; % input = SAR1;
bound = floor(patchsize/2);
[row,col] = size(input);
output = zeros(row+2*bound,col+2*bound);
output(bound+1:row+bound, bound+1:col+bound) = input;
% 行镜像
output(1:bound,:) = flipud(output(2+bound:1+2*bound,:));
output(end-bound:end,:) = flipud(output(end-2*bound:end-bound,:));