博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【代码备份】pocs.m
阅读量:4502 次
发布时间:2019-06-08

本文共 9768 字,大约阅读时间需要 32 分钟。

超分辨率算法代码

POCS算法,凸集投影法。

pocs.m,没有调用的代码,没看懂。。只有这个函数。。抱歉。

function y = pocs(s,delta_est,factor)% POCS - reconstruct high resolution image using Projection On Convex Sets%    y = pocs(s,delta_est,factor)%    reconstruct an image with FACTOR times more pixels in both dimensions%    using Papoulis Gerchberg algorithm and using the shift and rotation %    information from DELTA_EST and PHI_EST%    in:%    s: images in cell array (s{
1}, s{
2},...)% delta_est(i,Dy:Dx) estimated shifts in y and x% factor: gives size of reconstructed image%% -----------------------------------------------------------------------% SUPERRESOLUTION - Graphical User Interface for Super-Resolution Imaging% Copyright (C) 2005-2007 Laboratory of Audiovisual Communications (LCAV), % Ecole Polytechnique Federale de Lausanne (EPFL), % CH-1015 Lausanne, Switzerland % % This program is free software; you can redistribute it and/or modify it % under the terms of the GNU General Public License as published by the % Free Software Foundation; either version 2 of the License, or (at your % option) any later version. This software is distributed in the hope that % it will be useful, but without any warranty; without even the implied % warranty of merchantability or fitness for a particular purpose. % See the GNU General Public License for more details % (enclosed in the file GPL). %% Latest modifications: August 20, 2006, by Karim Krichanemax_iter = 50;temp = upsample(upsample(s{
1}, factor)', factor)';y = zeros(size(temp));coord = find(temp);y(coord) = temp(coord);for i = 2:length(s) temp = upsample(upsample(s{i}, factor)', factor)'; temp = shift(temp, round(delta_est(i, 2)*factor), round(delta_est(i, 1)*factor)); coord = find(temp); y(coord) = temp(coord);end y_prev=y;E=[];iter=1;blur =[.25 0 1 0 .25;... 0 1 2 1 0;... 1 2 4 2 1;... 0 1 2 1 0;... .25 0 1 0 .25]; blur = blur / sum(blur(:));wait_handle = waitbar(0, '重构中...', 'Name', '超分辨率重构');while iter < max_iter waitbar(min(4*iter/max_iter, 1), wait_handle); y = imfilter(y, blur); for i = length(s):-1:1 temp = upsample(upsample(s{i}, factor)', factor)'; temp = shift(temp, round(delta_est(i, 2)*factor), round(delta_est(i, 1)*factor)); coord = find(temp); y(coord) = temp(coord); end delta= norm(y-y_prev)/norm(y); E=[E; iter delta]; iter = iter+1; if iter>3 if abs(E(iter-3,2)-delta) <1e-4 break end end y_prev=y;% if mod(iter,10)==2% disp(['iteration ' int2str(E(iter-1,1)) ', error ' num2str(E(iter-1,2))])% endendclose(wait_handle);

 

【其他】貌似这个里面有,可以试一下,没下载过

凸集投影法(POCS)超分辨重建算法MATLAB实现

POCS 提供了基于POCS算法的超分辨率图像重建的源程序 联合开发网 - pudn.com

超分辨率的POCS算法–MATLAB中文论坛


POCS.m:

close all clear clc t1=clock; NumberOfFrames =3;  k = zeros(1,4);  %%% 第一帧低分辨率图像与原图 RefImage = imread('a_0.jpg');        %第一帧LW图像 origin=imread('origin.jpg');    %原图 figure(1);  imshow(RefImage) RefImageImage =double(RefImage); %%%差值处理,spline,nearest,linear,cubic [x, y] = meshgrid(1:size(RefImage,2), 1:size(RefImage,1));  [X, Y] = meshgrid(1:2.*size(RefImage,2), 1:2.*size(RefImage,1));  upRefImage = interp2(x,y,double(RefImage),X./2,Y./2,'spline');  upRefImage(isnan(upRefImage)) = 0;  upRefImage=wiener2(upRefImage); figure(2);  imshow(mat2gray(upRefImage)) imwrite(mat2gray(upRefImage),'RefImage_filter_nearest.jpg') %计算信噪比PSNR c=zeros(); [m,n]=size(origin) for i=1:1:m     for j=1:1:n         minus(i,j)=(origin(i,j)-upRefImage(i,j))^2;     end end summ=sum(sum(minus));        PSNR=10*log10(255^2*m*n/summ) %迭代次数 for iter=1:8,    disp(iter);    for num = 2:NumberOfFrames,       %读入其他帧数图像     if (num < 8);        frame = imread(strcat('C:\Users\chen\Desktop\POCS\code\a_',num2str(num),'.jpg'));      else        frame = imread(strcat('C:\Users\chen\Desktop\POCS\code\a_',num2str(num),'.jpg'));      end      frame = double(frame);      %%%计算相对第一帧的位置     k = affine(frame,RefImage);      u =  k(1).*X + k(2).*Y + 2.*k(3);      v = -k(2).*X + k(1).*Y + 2.*k(4);      mcX = X + u;      mcY = Y + v;      for m2 = 1:size(frame,2),        for m1 = 1:size(frame,1),          n1 = 2*m1;          n2 = 2*m2;          N2 = mcX(n1,n2);          N1 = mcY(n1,n2);          if ( N1>3 & N1
3 & N2
1) convertedR=double(R); upRefImage(rN1-2:rN1+2,rN2-2:rN2+2) = upRefImage(rN1-2:rN1+2,rN2-2:rN2+2) + ... (weights.*(convertedR-1))./sum(sum(weights.^2)); elseif (R<-1) convertedR=double(R); upRefImage(rN1-2:rN1+2,rN2-2:rN2+2) = upRefImage(rN1-2:rN1+2,rN2-2:rN2+2) + ... (weights.*(convertedR+1))./sum(sum(weights.^2)); end end end end upRefImage(upRefImage<0) = 0; upRefImage(upRefImage>255) = 255; end end %%%展示图像 %%% imwrite(mat2gray(upRefImage),'SRframe_cubic.jpg'); t2=clock; disp(['程序总运行时间:',num2str(etime(t2,t1))]); figure(3); imshow(mat2gray(upRefImage))
View Code

 

另一种POCS算法,myPOCScode.m:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % POCS Image Reconstruction % ------------------------- %  AUTHOR: Stephen Rose, Maher Khoury %    DATE: March 1, 1999 % PURPOSE: Generates SR frame using the POCS method % % Notes: %   -init.m contains the affine transformation parameters ???????%   -Assuming a gaussian PSF %   -u,v are affine transformation vectors for (x,y) %   -mcX,mcY are transformed coordines in SR frame % % Variables: %   -ref            = LR reference frame %   -upref          = HR reference frame %   -NumberOfFrames = Number of pixel frames to consider %   -frame          = LR frame currently being examined %   -weights        = weights based on Gaussian PSF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Initialization 初始化????%init; clear;close allclc% NumberOfFrames = 4; k = zeros(1,4); wd=1;dlt=5;% max_iter=1;q=2;%放大倍数% I=imread('E:\SR\mmread\disk\frame1.bmp');% [m n]=size(I);% up_ref=zeros(q.*m,q.*n,17);%逐次选择初始图像    %%% Create the high-resolution reference frame % ref=imread(E:\SR\mmread\disk\frame1.bmp');%低分辨率参考帧ref=imread('frame1.bmp');ref=ref(:,:,1);% ref = ref(1:size(ref,1)./2,1:size(ref,2)./2);ref=double(ref);%ref = ref(1:2:size(ref,1),1:2:size(ref,2)); % figure,imshow(ref,[]);%  imwrite(mat2gray(ref),'ref.bmp');  % I0=imread('cameraman.bmp');%读入原始清晰图像(计算mse、psnr时,需要用)% mse=zeros(1,max_iter);% psnr=zeros(1,max_iter);% up_ref=zeros(q.*size(ref,1),q.*size(ref,2),iter_max);% for iter_max=1:max_iter%     disp(strcat('最大迭代次数:',num2str(iter_max))); % for dlt=1:6%%%Interpolate values at inbetween points 插值过程[x, y] = meshgrid(1:size(ref,2), 1:size(ref,1)); [X, Y] = meshgrid(1:q.*size(ref,2), 1:q.*size(ref,1)); upref = interp2(x,y,ref,X./q,Y./q,'bicubic'); %或者linear,bicubicupref1=upref;upref1(isnan(upref1)) = 0; [m,n]=size(upref);% figure,imshow(upref,[]); % imwrite(mat2gray(upref),'upref0.bmp');% drawnow; %%% Iterate the entire process 迭代过程% for iter=1:iter_max%     disp(strcat('第',num2str(iter),'次迭代'));   %%% Iterate over the frames 逐帧迭代  for num = 2:4         frame = imread(strcat('frame',num2str(num),'.bmp'));       frame=frame(:,:,1);      frame=double(frame);       %        frame = frame(1:size(frame,1)./q,1:size(frame,2)./q);     %%%Calculate the affine motion parameters for this frame     %%%计算该帧的仿射系数(估计图像配准参数)    k = affine(frame,ref);    u =  k(1).*X + k(2).*Y + q.*k(3);     v = -k(2).*X + k(1).*Y + q.*k(4);     %%% Calculate the coordinates of the motion compensated pixels    %%% %计算运动补偿像素的坐标?????    mcX = X + u;     mcY = Y + v; %     Imin=min(min(frame));%     Imax=max(max(frame));%     Rel=zeros(m,n);%     for k=1:m%         for j=1:n%             Rel(k,j)=0.1*(1-2/(Imax-Imin)*abs(upref(k,j)-(Imax-Imin)/2));%         end%     end    %%% Loop over entire (low-res) frame 逐像素修正    for m2 = 1:size(frame,2)       for m1 = 1:size(frame,1)                 %%% Get high-resolution coordinates         n1 = 2*m1;         n2 = 2*m2;         %%% Get coordinates of the motion compensated pixel 获取运动补偿像素的坐标        N2 = mcX(n1,n2);         N1 = mcY(n1,n2);         %%% If not a border pixel 排除边缘像素        if ( N1>=wd+1 & N1<=size(upref,1)-wd & N2>=wd+1 & N2<=size(upref,2)-wd ) %??????原程序为:N1>wd+1 & N1
dlt) upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) = upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) + (weights.*(R(m1,m2)-dlt))./sum(sum(weights.^2)); % upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) = upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) +Rel(rN1-wd:rN1+wd,rN2-wd:rN2+wd).*(R(m1,m2)-dlt); elseif (R(m1,m2)<-dlt) upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) = upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) + (weights.*((R(m1,m2)+dlt))./sum(sum(weights.^2)));% upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) = upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) +Rel(rN1-wd:rN1+wd,rN2-wd:rN2+wd).*(R(m1,m2)-dlt);% else% upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) = upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd) + Rel(rN1-wd:rN1+wd,rN2-wd:rN2+wd).*R(m1,m2); end end end end upref(upref<0) = 0; upref(upref>255) = 255; end %upref=255/max(max(upref))*upref;%%% Display the image %%% % up_ref(:,:,start)=uint8(upref);% imwrite(mat2gray(upref),strcat('upref',num2str(start),'.bmp'));% % % % 计算mse与psnr% mse(1,iter_max)=MSE(I0,up_ref(:,:,iter_max));% psnr(1,iter_max)=PSNR(I0,up_ref(:,:,iter_max));% imwrite(upref,'SRgirl.tif'); figure,imshow(upref,[]); figure,imshow(upref1,[]);% imwrite(mat2gray(upref),'upref.bmp');% g=midfilter(upref,1);% figure,imshow(g)% gg=imread('jichang.bmp');% figure,imshow(gg);% drawnow; % for i=1:10% up_ref(:,:,i)=double(up_ref(:,:,i));% imwrite(mat2gray(up_ref(:,:,i),strcat('up_ref',num2str(i),'.bmp')));% end
View Code

 

 网盘文件:

链接:

提取码:cmyr

转载于:https://www.cnblogs.com/wxl845235800/p/10151557.html

你可能感兴趣的文章
bzoj2007 NOI2010 网络流转对偶图
查看>>
再再论指针
查看>>
BZOJ 1208 [HNOI 2004] 宠物收养所 Splay
查看>>
C3p0连接mysql数据库中文乱码或因编码不一致而导致程序无法正确运行
查看>>
当手机键盘弹出时底部会被挤上去
查看>>
在iptables服务开启的状态测试不会出现unknown key的错误
查看>>
推荐系统判定标准
查看>>
Edusoho之X-Auth-Token
查看>>
推荐在线编程学习网站
查看>>
Handshake failed due to invalid Upgrade header: null 解决方案
查看>>
源码包的解压 .tar.gz /.tar.bz2的解压
查看>>
虚拟机的安装与使用
查看>>
aop 的一些表达式
查看>>
iOS的isnan函数
查看>>
iOS 系统消息通知
查看>>
Java函数的联级调用
查看>>
安装Asp.Net MVC3.0 失败
查看>>
linux挂载新磁盘、分区和开机自动挂载
查看>>
敏捷的生产--丰田模式之减少浪费
查看>>
面向对象---继承
查看>>