1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 【图像重建】基于matlab迭代步长自适应图像超分辨重建【含Matlab源码 048期】

【图像重建】基于matlab迭代步长自适应图像超分辨重建【含Matlab源码 048期】

时间:2023-10-19 16:37:50

相关推荐

【图像重建】基于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 allclcfilename = '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-TikhonovImage =imread([filename,'\',files(file_num).name]);SZ = size(size(Image));if (SZ(2)==2) % turn grayscale image to RGB imagefor qw = 1:3IMAGE (:,:,qw) = Image;endelseIMAGE = Image;end%% Image DegradationD = [1,1;-2,1;-1,-3;3,-2];% Shearing shiftGau = fspecial( 'gaussian', [3 3], 1); % Gaussian bluring kernelspf = 2;% sampling factorsigma2 = 1; % variation of noiseLR = 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:MLR(:,:,:,w) = rgb2ycbcr(uint8( squeeze(LR(:,:,:,w))));endmaxiter = 10; % maximum number of iterationy1(:,:,:) = LR(:,:,1,:);y2(:,:,:) = LR(:,:,2,:);y3(:,:,:) = LR(:,:,3,:);HRitp1 = imresize(y1(:,:,1), spf, 'bicubic'); % bicubic interpolationHRitp1 = ImWarp(HRitp1, -D(1,1), -D(1,2)); % shift recoveringI1 = Wang_SR(HRitp1, y1, D, Gau, spf, maxiter, reg_term); %Our proposed SR methodHRitp2 = 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 RGBfigure; imshow( uint8( ImZ ) ); title('Wang et al.');figure; imshow( uint8( IMAGE ) ); title('groundtruth');%% EvaluationIf = double(ImZ); %output imageIs = double(IMAGE); %reference image[row,col,~]=size(If); %RMSErmse=0;for color = 1:3Ifc = If(:,:,color); Isc = Is(:,:,color);SSE=sum(sum((Ifc-Isc).^2));rmsec=sqrt(SSE/(row*col));rmse = rmse+rmsec/3;endrmse%PSNRpsnr=0;for color = 1:3Ifc = 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;endpsnr%SSIMssim=0;for color = 1:3Ifc = uint8(If(:,:,color)); Isc = uint8(Is(:,:,color));ssimc = cal_ssim(Ifc, Isc, 0, 0);ssim = ssim + ssimc/3;endssimfunction 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));elsefor i = 1:chssim = 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));endssim = ssim/3;endreturnfunction [mssim, ssim_map] = ssim_index(img1, img2, K, window, L)if (nargin < 2 || nargin > 5)mssim = -Inf;ssim_map = -Inf;return;endif (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;returnendwindow = fspecial('gaussian', 11, 1.5);%K(1) = 0.01;% default settingsK(2) = 0.03;%L = 255; %endif (nargin == 3)if ((M < 11) || (N < 11))mssim = -Inf;ssim_map = -Inf;returnendwindow = fspecial('gaussian', 11, 1.5);L = 255;if (length(K) == 2)if (K(1) < 0 || K(2) < 0)mssim = -Inf;ssim_map = -Inf;return;endelsemssim = -Inf;ssim_map = -Inf;return;endendif (nargin == 4)[H W] = size(window);if ((H*W) < 4 || (H > M) || (W > N))mssim = -Inf;ssim_map = -Inf;returnendL = 255;if (length(K) == 2)if (K(1) < 0 || K(2) < 0)mssim = -Inf;ssim_map = -Inf;return;endelsemssim = -Inf;ssim_map = -Inf;return;endendif (nargin == 5)[H W] = size(window);if ((H*W) < 4 || (H > M) || (W > N))mssim = -Inf;ssim_map = -Inf;returnendif (length(K) == 2)if (K(1) < 0 || K(2) < 0)mssim = -Inf;ssim_map = -Inf;return;endelsemssim = -Inf;ssim_map = -Inf;return;endendimg1 = double(img1);img2 = double(img2);% automatic downsamplingf = 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);endC1 = (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));elsenumerator1 = 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);endmssim = mean2(ssim_map);return

四、运行结果

五、matlab版本及参考文献

1 matlab版本

a

2 参考文献

[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,.

[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,.

[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,.

[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。