【图像重建】基于matlab迭代步长自适应图像超分辨重建【含Matlab源码 048期】
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【图像重建】基于matlab迭代步长自适应图像超分辨重建【含Matlab源码 048期】
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、迭代步长自适应简介
传统的超分辨重建算法往往采用梯度下降法进行求解,迭代时步长往往通过经验确定。而且不同的图像的最优步长往往不相同。步长过大会导致发散,步长过小会导致收敛缓慢。本算法基于对正则化超分辨重建算法实现的基础上,对步长的选取进行了优化,推导出了每次迭代时的最优步长大小,并将其自适应化,改进了超分辨算法的收敛性,从而能够在更短的时间内取得更加精确的重建结果。相关具体内容请参考对应的论文:Yingqian Wang, Jungang Yang, Chao Xiao, and Wei An, “Fast convergence strategy for multi-image superresolution via adaptive line search,” IEEE Access, vol. 6, no. 1, pp. 9129-9139.
三、部分源代码
clear all
clc
filename = 'Set';
files = dir(fullfile( filename,'*.bmp'));
file_num = 2; % different number corresponds to defferent test images in 'Set'
reg_term = 1; %regularization term: 1-BTV, 2-Tikhonov
Image =imread([filename,'\',files(file_num).name]);
SZ = size(size(Image));
if (SZ(2)==2) % turn grayscale image to RGB image
for qw = 1:3
IMAGE (:,:,qw) = Image;
end
else
IMAGE = Image;
end
%% Image Degradation
D = [1,1;-2,1;-1,-3;3,-2]; % Shearing shift
Gau = fspecial( 'gaussian', [3 3], 1); % Gaussian bluring kernel
spf = 2; % sampling factor
sigma2 = 1; % variation of noise
LR = ImDegrate(IMAGE,D,Gau,spf,sigma2); % image degradation function
%% Turn RGB to YCbCr, and only SR the Y component
[~, ~, ~, M] = size(LR);
for w = 1:M
LR(:,:,:,w) = rgb2ycbcr(uint8( squeeze(LR(:,:,:,w))));
end
maxiter = 10; % maximum number of iteration
y1(:,:,:) = LR(:,:,1,:);
y2(:,:,:) = LR(:,:,2,:);
y3(:,:,:) = LR(:,:,3,:);
HRitp1 = imresize(y1(:,:,1), spf, 'bicubic'); % bicubic interpolation
HRitp1 = ImWarp(HRitp1, -D(1,1), -D(1,2)); % shift recovering
I1 = Wang_SR(HRitp1, y1, D, Gau, spf, maxiter, reg_term); %Our proposed SR method
HRitp2 = imresize(y2(:,:,1), spf, 'bicubic');
HRitp2 = ImWarp(HRitp2, -D(1,1), -D(1,2));
I2 = HRitp2;
HRitp3 = imresize(y3(:,:,1), spf, 'bicubic');
HRitp3 = ImWarp(HRitp3, -D(1,1), -D(1,2));
I3 = HRitp3;
ImZ(:, :, 1) = I1;
ImZ(:, :, 2) = I2;
ImZ(:, :, 3) = I3;
ImZ = ycbcr2rgb(uint8( ImZ)); % Turn YCbCr to RGB
figure; imshow( uint8( ImZ ) ); title('Wang et al.');
figure; imshow( uint8( IMAGE ) ); title('groundtruth');
%% Evaluation
If = double(ImZ); %output image
Is = double(IMAGE); %reference image
[row,col,~]=size(If);
%RMSE
rmse=0;
for color = 1:3
Ifc = If(:,:,color); Isc = Is(:,:,color);
SSE=sum(sum((Ifc-Isc).^2));
rmsec=sqrt(SSE/(row*col));
rmse = rmse+rmsec/3;
end
rmse
%PSNR
psnr=0;
for color = 1:3
Ifc = If(:,:,color); Isc = Is(:,:,color);
maxIs = max(max(Isc));
minIs = min(min(Isc));
PSNRc = 10*log10((row*col*(maxIs-minIs)^2)/sum(sum((Ifc-Isc).^2)));
psnr = psnr+PSNRc/3;
end
psnr
%SSIM
ssim=0;
for color = 1:3
Ifc = uint8(If(:,:,color)); Isc = uint8(Is(:,:,color));
ssimc = cal_ssim(Ifc, Isc, 0, 0);
ssim = ssim + ssimc/3;
end
ssim
function ssim = cal_ssim( im1, im2, b_row, b_col)
[h, w, ch] = size( im1 );
ssim = 0;
if (ch == 1)
ssim = ssim_index ( im1(b_row+1:h-b_row, b_col+1:w-b_col), im2(b_row+1:h-b_row,b_col+1:w-b_col));
else
for i = 1:ch
ssim = ssim + ssim_index ( im1(b_row+1:h-b_row, b_col+1:w-b_col, i), im2(b_row+1:h-b_row,b_col+1:w-b_col, i));
end
ssim = ssim/3;
end
return
function [mssim, ssim_map] = ssim_index(img1, img2, K, window, L)
if (nargin < 2 || nargin > 5)
mssim = -Inf;
ssim_map = -Inf;
return;
end
if (size(img1) ~= size(img2))
mssim = -Inf;
ssim_map = -Inf;
return;
end
[M N] = size(img1);
if (nargin == 2)
if ((M < 11) || (N < 11))
mssim = -Inf;
ssim_map = -Inf;
return
end
window = fspecial('gaussian', 11, 1.5); %
K(1) = 0.01; % default settings
K(2) = 0.03; %
L = 255; %
end
if (nargin == 3)
if ((M < 11) || (N < 11))
mssim = -Inf;
ssim_map = -Inf;
return
end
window = fspecial('gaussian', 11, 1.5);
L = 255;
if (length(K) == 2)
if (K(1) < 0 || K(2) < 0)
mssim = -Inf;
ssim_map = -Inf;
return;
end
else
mssim = -Inf;
ssim_map = -Inf;
return;
end
end
if (nargin == 4)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mssim = -Inf;
ssim_map = -Inf;
return
end
L = 255;
if (length(K) == 2)
if (K(1) < 0 || K(2) < 0)
mssim = -Inf;
ssim_map = -Inf;
return;
end
else
mssim = -Inf;
ssim_map = -Inf;
return;
end
end
if (nargin == 5)
[H W] = size(window);
if ((H*W) < 4 || (H > M) || (W > N))
mssim = -Inf;
ssim_map = -Inf;
return
end
if (length(K) == 2)
if (K(1) < 0 || K(2) < 0)
mssim = -Inf;
ssim_map = -Inf;
return;
end
else
mssim = -Inf;
ssim_map = -Inf;
return;
end
end
img1 = double(img1);
img2 = double(img2);
% automatic downsampling
f = max(1,round(min(M,N)/256));
%downsampling by f
%use a simple low-pass filter
if(f>1)
lpf = ones(f,f);
lpf = lpf/sum(lpf(:));
img1 = imfilter(img1,lpf,'symmetric','same');
img2 = imfilter(img2,lpf,'symmetric','same');
img1 = img1(1:f:end,1:f:end);
img2 = img2(1:f:end,1:f:end);
end
C1 = (K(1)*L)^2;
C2 = (K(2)*L)^2;
window = window/sum(sum(window));
mu1 = filter2(window, img1, 'valid');
mu2 = filter2(window, img2, 'valid');
mu1_sq = mu1.*mu1;
mu2_sq = mu2.*mu2;
mu1_mu2 = mu1.*mu2;
sigma1_sq = filter2(window, img1.*img1, 'valid') - mu1_sq;
sigma2_sq = filter2(window, img2.*img2, 'valid') - mu2_sq;
sigma12 = filter2(window, img1.*img2, 'valid') - mu1_mu2;
if (C1 > 0 && C2 > 0)
ssim_map = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))./((mu1_sq + mu2_sq + C1).*(sigma1_sq + sigma2_sq + C2));
else
numerator1 = 2*mu1_mu2 + C1;
numerator2 = 2*sigma12 + C2;
denominator1 = mu1_sq + mu2_sq + C1;
denominator2 = sigma1_sq + sigma2_sq + C2;
ssim_map = ones(size(mu1));
index = (denominator1.*denominator2 > 0);
ssim_map(index) = (numerator1(index).*numerator2(index))./(denominator1(index).*denominator2(index));
index = (denominator1 ~= 0) & (denominator2 == 0);
ssim_map(index) = numerator1(index)./denominator1(index);
end
mssim = mean2(ssim_map);
return
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/120338112
- 点赞
- 收藏
- 关注作者
评论(0)