【代码备份】pocs.m
超分辨率算法代码
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{}, s{},...)
% 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) - Laboratory of Audiovisual Communications (LCAV),
% Ecole Polytechnique Federale de Lausanne (EPFL),
% CH- 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 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 , , by Karim Krichane max_iter = ; temp = upsample(upsample(s{}, factor)', factor)';
y = zeros(size(temp));
coord = find(temp);
y(coord) = temp(coord); for i = :length(s)
temp = upsample(upsample(s{i}, factor)', factor)';
temp = shift(temp, round(delta_est(i, )*factor), round(delta_est(i, )*factor));
coord = find(temp);
y(coord) = temp(coord);
end y_prev=y; E=[];
iter=; blur =[. .;...
;...
;...
;...
. .]; blur = blur / sum(blur(:));
wait_handle = waitbar(, '重构中...', 'Name', '超分辨率重构'); while iter < max_iter
waitbar(min(*iter/max_iter, ), wait_handle);
y = imfilter(y, blur);
for i = length(s):-:
temp = upsample(upsample(s{i}, factor)', factor)';
temp = shift(temp, round(delta_est(i, )*factor), round(delta_est(i, )*factor));
coord = find(temp);
y(coord) = temp(coord);
end delta= norm(y-y_prev)/norm(y);
E=[E; iter delta];
iter = iter+;
if iter>
if abs(E(iter-,)-delta) <1e-
break
end
end
y_prev=y;
% if mod(iter,)==
% disp(['iteration ' int2str(E(iter-,)) ', error ' num2str(E(iter-,))])
% end
end close(wait_handle);
【其他】貌似这个里面有,可以试一下,没下载过
凸集投影法(POCS)超分辨重建算法MATLAB实现 https://download.csdn.net/download/styyzxjq2009/2312854
POCS 提供了基于POCS算法的超分辨率图像重建的源程序 联合开发网 - pudn.com http://www.pudn.com/Download/item/id/3028355.html
超分辨率的POCS算法–MATLAB中文论坛 http://www.ilovematlab.cn/thread-135641-1-1.html
POCS.m:
close all
clear
clc
t1=clock;
NumberOfFrames =;
k = zeros(,);
%%% 第一帧低分辨率图像与原图
RefImage = imread('a_0.jpg'); %第一帧LW图像
origin=imread('origin.jpg'); %原图
figure();
imshow(RefImage)
RefImageImage =double(RefImage);
%%%差值处理,spline,nearest,linear,cubic
[x, y] = meshgrid(:size(RefImage,), :size(RefImage,));
[X, Y] = meshgrid(:.*size(RefImage,), :.*size(RefImage,));
upRefImage = interp2(x,y,double(RefImage),X./,Y./,'spline');
upRefImage(isnan(upRefImage)) = ;
upRefImage=wiener2(upRefImage);
figure();
imshow(mat2gray(upRefImage))
imwrite(mat2gray(upRefImage),'RefImage_filter_nearest.jpg')
%计算信噪比PSNR
c=zeros();
[m,n]=size(origin)
for i=::m
for j=::n
minus(i,j)=(origin(i,j)-upRefImage(i,j))^;
end
end
summ=sum(sum(minus));
PSNR=*log10(^*m*n/summ)
%迭代次数
for iter=:,
disp(iter);
for num = :NumberOfFrames, %读入其他帧数图像
if (num < );
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().*X + k().*Y + .*k();
v = -k().*X + k().*Y + .*k();
mcX = X + u;
mcY = Y + v;
for m2 = :size(frame,),
for m1 = :size(frame,),
n1 = *m1;
n2 = *m2;
N2 = mcX(n1,n2);
N1 = mcY(n1,n2);
if ( N1> & N1<size(upRefImage,)- & N2> & N2<size(upRefImage,)- )
rN1 = round(N1);
rN2 = round(N2);
windowX = Y(rN1-:rN1+,rN2-:rN2+);
windowY = X(rN1-:rN1+,rN2-:rN2+);
weights = exp(-((N1-windowX).^+(N2-windowY).^)./);
weights = weights./sum(sum(weights));
Ihat = sum(sum(weights.*upRefImage(rN1-:rN1+,rN2-:rN2+)));
R = frame(m1,m2) - Ihat; temp = ; %%% 计算新值
if (R>)
convertedR=double(R);
upRefImage(rN1-:rN1+,rN2-:rN2+) = upRefImage(rN1-:rN1+,rN2-:rN2+) + ...
(weights.*(convertedR-))./sum(sum(weights.^));
elseif (R<-)
convertedR=double(R);
upRefImage(rN1-:rN1+,rN2-:rN2+) = upRefImage(rN1-:rN1+,rN2-:rN2+) + ...
(weights.*(convertedR+))./sum(sum(weights.^));
end
end
end
end upRefImage(upRefImage<) = ;
upRefImage(upRefImage>) = ; end
end
%%%展示图像 %%%
imwrite(mat2gray(upRefImage),'SRframe_cubic.jpg');
t2=clock;
disp(['程序总运行时间:',num2str(etime(t2,t1))]);
figure();
imshow(mat2gray(upRefImage))
另一种POCS算法,myPOCScode.m:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% POCS Image Reconstruction
% -------------------------
% AUTHOR: Stephen Rose, Maher Khoury
% DATE: March ,
% 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 all
clc
% NumberOfFrames = ;
k = zeros(,);
wd=;
dlt=;
% max_iter=;
q=;%放大倍数 % I=imread('E:\SR\mmread\disk\frame1.bmp');
% [m n]=size(I);
% up_ref=zeros(q.*m,q.*n,);
%逐次选择初始图像 %%% Create the high-resolution reference frame
% ref=imread(E:\SR\mmread\disk\frame1.bmp');%低分辨率参考帧
ref=imread('frame1.bmp');
ref=ref(:,:,);
% ref = ref(:size(ref,)./,:size(ref,)./);
ref=double(ref);
%ref = ref(::size(ref,),::size(ref,));
% figure,imshow(ref,[]);
% imwrite(mat2gray(ref),'ref.bmp');
% I0=imread('cameraman.bmp');%读入原始清晰图像(计算mse、psnr时,需要用)
% mse=zeros(,max_iter);
% psnr=zeros(,max_iter);
% up_ref=zeros(q.*size(ref,),q.*size(ref,),iter_max);
% for iter_max=:max_iter
% disp(strcat('最大迭代次数:',num2str(iter_max)));
% for dlt=:
%%%Interpolate values at inbetween points 插值过程
[x, y] = meshgrid(:size(ref,), :size(ref,));
[X, Y] = meshgrid(:q.*size(ref,), :q.*size(ref,));
upref = interp2(x,y,ref,X./q,Y./q,'bicubic'); %或者linear,bicubic
upref1=upref;
upref1(isnan(upref1)) = ;
[m,n]=size(upref); % figure,imshow(upref,[]);
% imwrite(mat2gray(upref),'upref0.bmp');
% drawnow; %%% Iterate the entire process 迭代过程
% for iter=:iter_max
% disp(strcat('第',num2str(iter),'次迭代'));
%%% Iterate over the frames 逐帧迭代
for num = :
frame = imread(strcat('frame',num2str(num),'.bmp'));
frame=frame(:,:,);
frame=double(frame); % frame = frame(:size(frame,)./q,:size(frame,)./q); %%%Calculate the affine motion parameters for this frame
%%%计算该帧的仿射系数(估计图像配准参数)
k = affine(frame,ref);
u = k().*X + k().*Y + q.*k();
v = -k().*X + k().*Y + q.*k(); %%% 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=:m
% for j=:n
% Rel(k,j)=0.1*(-/(Imax-Imin)*abs(upref(k,j)-(Imax-Imin)/));
% end
% end
%%% Loop over entire (low-res) frame 逐像素修正
for m2 = :size(frame,)
for m1 = :size(frame,) %%% Get high-resolution coordinates
n1 = *m1;
n2 = *m2; %%% Get coordinates of the motion compensated pixel 获取运动补偿像素的坐标
N2 = mcX(n1,n2);
N1 = mcY(n1,n2); %%% If not a border pixel 排除边缘像素
if ( N1>=wd+ & N1<=size(upref,)-wd & N2>=wd+ & N2<=size(upref,)-wd ) %??????原程序为:N1>wd+ & N1<size(upref,)-wd %%% Find center of the window where the PSF will be applied
%%% 获取PSF作用范围的中心点
rN1 = round(N1);
rN2 = round(N2); %%% Calculate the effective window 计算窗口作用范围
windowX = Y(rN1-wd:rN1+wd,rN2-wd:rN2+wd);
windowY = X(rN1-wd:rN1+wd,rN2-wd:rN2+wd); %%% Find the value of the gaussian at these points and normalize
%%% 计算PSF并归一化
% weights = exp(-/wd^*((N1-windowX).^+(N2-windowY).^)./);
%%原代码如下计算weights
weights = exp(-((N1-windowX).^+(N2-windowY).^)./);
weights = weights./sum(sum(weights)); %%% Calculate the value of the estimate Ihat 计算投影像素的估计值
Ihat = sum(sum(weights.*upref(rN1-wd:rN1+wd,rN2-wd:rN2+wd))); %%% Calculate the residual 计算残差
R(m1,m2) = frame(m1,m2) - Ihat; temp = ; %%% Calculate new values for the reference frame 修正该点的像素值
if (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.^));
% 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.^)));
% 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<) = ;
upref(upref>) = ; end %upref=/max(max(upref))*upref;
%%% Display the image %%%
% up_ref(:,:,start)=uint8(upref); % imwrite(mat2gray(upref),strcat('upref',num2str(start),'.bmp')); % % % % 计算mse与psnr
% mse(,iter_max)=MSE(I0,up_ref(:,:,iter_max));
% psnr(,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,);
% figure,imshow(g)
% gg=imread('jichang.bmp');
% figure,imshow(gg);
% drawnow; % for i=:
% up_ref(:,:,i)=double(up_ref(:,:,i));
% imwrite(mat2gray(up_ref(:,:,i),strcat('up_ref',num2str(i),'.bmp')));
% end
网盘文件:
链接:https://pan.baidu.com/s/1qRNjUa93KXKQrFRmwYyWzw
提取码:cmyr
【代码备份】pocs.m的更多相关文章
- 博客使用的CSS代码备份
CSS代码备份 /*simplememory*/ #google_ad_c1, #google_ad_c2 { display: none; } .syntaxhighlighter a, .synt ...
- 1.svn 彻底clear时,注意代码备份 2.借助vc助手加头文件
1.svn 彻底clear时,注意代码备份 2.不小心彻底clear可以在回收站找到 3.借助vc助手加头文件
- 同时将代码备份到Gitee和GitHub
同时将代码备份到Gitee和GitHub 如何将GitHub项目一步导入Gitee 如何保持Gitee和GitHub同步更新 如何将GitHub项目一步导入Gitee 方法一: 登陆 Gitee 账号 ...
- Android短信管家视频播放器代码备份
自己保留备份,增强记忆 这是video的类 public class VideoActivity extends Activity { /** * 解析网络页面 */ private WebVie ...
- [Python]南邮OJ代码备份爬虫
之前看过Python学习的经验,说以project为导向学习. 自己分析了一下,一般接触Python的都有一定的其它语言基础,对于程序设计的基本逻辑,语法都有一个大概的了解.而Python这样的脚本语 ...
- CentOS 系统下Gitlab搭建与基本配置 以及代码备份迁移过程
GitLab 是一个开源的版本管理系统,提供了类似于 GitHub 的源代码浏览,管理缺陷和注释等功能,你可以将代码免费托管到 GitLab.com,而且不限项目数量和成员数.最吸引人的一点是,可以在 ...
- Qt 窗体间传值(代码备份)
刚开始看的时候看的云里雾里的,现在稍微明白一点了.现在假设有一个form,一个MainWindow,如图所示: 实现点击PushButton,将文本框中的内容传输到MainWindow中,显示为Lab ...
- java代码备份mysql数据库
编写bat文件 @echo off set "date_string=%date:~0,4%-%date:~5,2%-%date:~8,2%" set "time_str ...
- html和js基础功能代码备份
1)贴图:<img src="图片地址">2)加入连接:<a href="所要连接的相关地址">写上你想写的字</a> 3) ...
随机推荐
- ADexplorer - 用来查看AD的工具
ADExplorer是一款可以帮助查看和编辑数据库的软件.该数据库查看编辑器使用方便,操作简单,用户可通过该软件进行浏览AD数据库.自定义快速入口.查看对象属性.编辑权限.精确搜索等操作,还可以保存数 ...
- cpu_test
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 【JS】jQuery设置定时器,访问服务器(PHP示例)配合微信、支付宝原生支付,跳转web网页
废话不多说,直接上代码: 把下面的js放在html的</body>即可 <!-- 设置页面定时器,3秒查询一次数据库该订单状态,ok就跳走 --xzz1115> <scr ...
- (四)hibernate关联映射之——一对多映射
0. 映射分四种类型: 一对多 多对一 一对一 多对多 前两者最常用 1.单向一对多关联 1.1 如何在JAVA和数据库中表示一对多的关系. 2.多对一关联 以学生对应班级来解释 步骤(1)创建 ...
- Ubuntu系统使用命令禁用触摸板等输入设备
[日期:2012-02-22] 本人用的Ubuntu 10.04系统,笔记本上有鼠标和触摸板.默认下,触摸板是开启的, 有时候打字的时候会不时碰到触摸板,添了不少麻烦,所以得禁用触摸板,限于目前所 ...
- python 多线程 示例
import threading import Queue q = Queue.Queue() from test import * def worker1(x, y): #假设耗时 执行完毕 大于三 ...
- Python实现百度搜索并保存到本地示例,Python实现百度搜索
实现百度搜索并保存到本地 User_Agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko ...
- Windows里配置Apache2.2+PHP5.3+mod_fcgid运行高效的FastCGI模式
日发现win平台的Apache也可以跑FastCGI模式了,就折腾了一会.FastCGI模式是经实践证明了比传统的模块模式运行效率高很多.记录如下: 一.mod_fcgid配置说明 1.首先下载mod ...
- unity, editorWindow update计时
对于editorWindow,Time.deltaTime不起作用,所以需用下面方法对update进行计时: public class myEditorWindow : EditorWindow{ p ...
- 基于Java Netty框架构建高性能的Jt808协议的GPS服务器(转)
原文地址:http://www.jt808.com/?p=971 使用Java语言开发一个高质量和高性能的jt808 协议的GPS通信服务器,并不是一件简单容易的事情,开发出来一段程序和能够承受数十万 ...