当前位置:文档之家› 滤波反投影程序设计报告

滤波反投影程序设计报告

《滤波反投影程序设计报告》课程名称:生物医学图像处理2院系:生物医学工程姓名:学号:完成日期:2017年4月23日一、设计目的用Matlab实现平行束滤波反投影算法,比较不同滤波函数的效果。

二、实验原理(一)图像重建模型——shepp Logan头模型是图像重建标准体模,由10个位置、大小、方向、密度各异的椭圆组成,代表一个脑部断层。

(二)重建理论推导中心切片定理是从投影图像重建图像的理论基础,表述为:某断层图像f(x,y)在视角为θ时得到的平行投影的一维傅里叶变换等于f(x,y)二维傅里叶变换F(w1,w2)过原点的一个垂直切片,且切片与轴w1相交成θ角。

如下图所示。

公式表述为:F (wcos θ,wsin θ)=P(w,θ) ① 将在ω1-ω2坐标系中表达的F (w 1,w 2)引入新的极坐标系ω−θ中,新坐标系与原坐标系原点重合,有w1=wcos θ,w2=wsin θ. 面元换算为dw1dw2=wdwd θ.有 f(x,y)= ∫∫F (wcosθ,wsinθ)e j2πw(xcosθ+ysinθ)wdwdθ∞02π0 =∫∫P(w,θ)e j2πw(xcosθ+ysinθ)wdwdθ∞02π0 =∫∫P(w,θ)e j2πw(xcosθ+ysinθ)wdwdθ∞0π0 +∫∫P(w,θ+π)e −j2πw(xcosθ+ysinθ)wdwdθ∞0π0 ② 注意到在θ与θ+π两个角度下的平行束射线投影的投影存在如下关系:p (t,θ)=p (−t,θ+π)其傅里叶变换存在如下关系:P(w,θ+π)=P(−w,θ)将上式代入②式,有 f(x,y)= ∫∫P (w,θ)|w|e j2πw(xcosθ+ysinθ)dwdθ∞−∞π0 ③ 令③式内积分等于g(xcos θ+ysin θ),则有g(xcos θ+ysin θ)=∫|w |P (w,θ)e j2πwt |+∞−∞t= xcosθ+ysinθdw实际上,g(xcos θ+ysin θ)就是投射角度为θ时的滤波投影,在t-s 坐标系中表达时,转化为g (t,θ)=h(t)*p(t,θ),h(t)是传递函数H (w )=|w|的傅里叶逆变换,p(t, θ)是P (w, θ)的傅里叶逆变换。

所以③式可写成f(x,y)= ∫g(x π0cosθ+ysinθ)d θ ④ 在图3.5中注意到Xr=rcos(θ−φ)=xcos θ+ysinθ是从原点出发的通过点(r,θ)的射线方程,④式可写为:f(x,y)= ∫g[rcos (θ−φ),φ]π0dφ ⑤ ④⑤两式表明:f(x,y)在(x,y )处的重建,等于通过该点的所有角度下滤波投影的累加所得到的像素值,而Xr=rcos(θ−φ)=xcos θ+ysinθ的变化代表了所有平行投影射线。

(三)Radon 变换一个无限薄的切片内相对线性衰减系数的分布是由它的所有线积分的集合唯一决定,揭示了函数和投影之间的关系,若函数为f(x,y),则不同角度下的投影可写为P(t,θ)=∬f (x,y )δ(xcosθ+ysinθ−t )dxdy +∞−∞ ⑥(四)滤波函数由于直接反投影法把取自有限空间的投影均匀回抹到了射线所及的无限空间的各个像素上,使得原来像素值为0的点不为0,从而产生星状伪迹,滤波反投影算法用人为设计的一维滤波函数对所得投影数据进行卷积,而后进行反投影和累加时,由于正负抵消,可一定程度上消除星状伪迹。

现在常用的滤波函数有R-L、S-L、Hanning、Hamming、Parzen、Sigwin窗函数,本次设计比较了R-L、S-L和Parzen 滤波函数的效果,发现Parzen滤波效果最好。

1.R-L滤波函数R-L滤波函数频率响应为:R-L滤波函数滤波计算简单,避免了大量的正弦、余弦计算,所重建图像轮廓清楚,空间分辨率高,但有Gibbs现象,表现为明显的振荡响应,特别是工件的边缘和衰减系数变化剧烈(即密度变化)时,尤为明显。

S-L滤波器对投影中的高频成分具有抑制作用,进而使重建图像的振荡响应减小,对含噪声的投影数据,重建质量较用RL的好,但在低频段不及R-l滤波函数好,这是由于H(w)在低频段也偏离了|w|的缘故3.Parzen滤波函数三、程序实现程序包含FBP_GUI.m和dps.m两个m文件,其中投影、滤波和反投影过程均为自己编写,没有使用Matlab自带函数,附录中对过程有详细注释,程序大致流程为:四、运行结果(1)sheep Logan256*256图像重建(2)自定义灰度图像重建(3)自定义RGB图像重建(滤波函数进行滤波处理。

五、总结本次程序设计完成了设计目的,投影和反投影过程没有使用自带函数,但是在处理像素比较大的图像时程运行时间比较长,是一个缺点,图像也存在一定误差,效果不是特别完美,不过也算是锻炼了自己的能力,对图像重建中对滤波反投影算法有了深刻的了解,增加了对这门课程的兴趣,期待在以后的学习中能进一步完善程序,缩短运行时间,减小图像误差。

六、附录——程序代码①dps.m文件代码如下:function [a]=dps(P)tic;%P=phantom(256);%P=imread('gray1.jpg');%P=rgb2gray(P);[N,N]=size(P);subplot(2,3,2);imshow(P);title([int2str(N),'*',int2str(N),'原始图像']);%先进行自定义radon变换------------------------------------------------------------thm=45; %45度时会出现最大尺寸pre = imrotate(P,thm);[mmax,nmax] = size(pre);s=1;%创建一个180*nmax的空白图片,用以存储投影后的线状图片Final = zeros(180/s,nmax);%这里180代表180角度,每个角度投影成为一条线t = 1;for theta = 1:s:179Protate = imrotate(P,theta); %对原图旋转一个角度,求和(线积分)Pf = sum(Protate,1);[mreal,nreal]=size(Pf); %计算实际尺寸%确定起始点if (nmax - nreal)/2-floor((nmax - nreal)/2) == 0From = floor((nmax - nreal)/2 + 1);%总点数为偶数时elseFrom = floor((nmax - nreal)/2) + 1;%总点数为奇数时end%确定结束点End = floor((nmax-nreal)/2) + nreal;%将一个角度Radon变换后的线状图存入结果图像的某一行Final(180/s-t,From:End) = Pf; %从最底下一行开始存起%上移一行t = t + 1;end%再逆时针旋转R=imrotate(Final,90);subplot(2,3,3);imshow(R,[]);title('自定义投影后图像');z=2*ceil(norm(size(P)-floor((size(P)-1)/2)-1))+3;% radon变换默认平移点数/角度e=floor((z-N)/2)+2;R1=R(e:(N+e-1),:);[mm,nn]=size(R1);subplot(2,3,4);imagesc(R1);title([int2str(mm),'*',int2str(nn),'正弦图']);colormap(gray);colorbar;%滤波函数构造------------------------------------------------------------g=1-N:N-1;% d=1;% R-L滤波函数% for i=1:2*N-1% if g(i)==0% h(i)=1/(4*(d^2));% else if mod(g(i),2)==0% h(i)=0;% else% h(i)=(-1)/(pi^2*d^2*(g(i)^2));% end% end% end%S-L滤波函数% d=1;% for i=1:2*N-1% h(i)=2/(pi^2*d^2*(1-4*g(i)^2));% end%Parzen滤波函数for i=1:2*N-1h(i)=(24*pi*g(i)*cos(pi*g(i))-96*sin(pi*g(i))-48*pi*g(i)*cos(pi*g(i)/2)+384*sin(pi*g(i)/2)-2*(pi^3)*(g(i)^3)-72*pi*g(i))/(4*(pi^5)*(g(i)^5));endh(N)=0.0435;%将投影与滤波函数卷积----------------------------------------------------G=zeros(N,180);for m=1:180for i=1:Nb=0;for n=1:Nb=b+h(N+n-i)*R1(n,m);G(i,m)=b;endendend%投影滤波后线性内插进行图像重建----------------------------------------------a=zeros(N); %重建图像初始化,每个像素点像素值为0ns=(N+1)/2;for m=1:180 %遍历每个投影角度r=pi/180; %将角度换为弧度for i=1:Nfor j=1:N %遍历原图的每一个像素点Xrm=(i-ns)*cos(m*r)+(j-ns)*sin(m*r)+ns-1; %坐标转换if Xrm<1n=1; %内插运算整数值t=abs(Xrm)-floor(abs(Xrm)); %内插运算小数值elsen=floor(Xrm);t=Xrm-floor(Xrm);endif n>N-1n=N-1;endc=(1-t)*G(n,m)+t*G(n+1,m); %内插后的滤波投影值a(N+1-j,i)=a(N+1-j,i)+c; %像素值的叠加endendend%将P、a的像素值变换到0-1之间P=double(P);P=P-min(min(P));kk=max(max(P));for i=1:Nfor j=1:NP(i,j)=P(i,j)/kk;endenda=double(a);a=a-min(min(a));kkk=max(max(a));for i=1:Nfor j=1:Na(i,j)=a(i,j)/kkk;endendsubplot(2,3,5);imshow(a,[]); %重建图形的显示title('滤波反投影重建图像');%重建图像质量评价--------------------------------------------------------%计算归一化均方距离判据d;ave=0;for x=1:Nfor y=1:Nave=ave+P(x,y);endendave=ave/(N*N);x1=0;x2=0;for x=1:Nfor y=1:Nx1=x1+(P(x,y)-a(x,y))^2;x2=x2+(P(x,y)-ave)^2;endendevaluate_d=sqrt(double(x1/x2));%计算归一化平均绝对距离判据r;x3=0;x4=0;for x=1:Nfor y=1:Nx3=x3+abs(P(x,y)-a(x,y));x4=x4+abs(P(x,y));endendevaluate_r=x3/x4;%计算最坏情况距离判据ens=floor(N/2)-1;g=zeros(ns);for x=1:nsfor y=1:nsT=(P(2*x,2*y)+P(2*x+1,2*y)+P(2*x,2*y+1)+P(2*x+1,2*y+1))/4;R=(a(2*x,2*y)+a(2*x+1,2*y)+a(2*x,2*y+1)+a(2*x+1,2*y+1))/4;g(x,y)=abs(T-R);endendevaluate_e=max(max(g));%结果文本显示------------------------------------------------------------o=ones(500,1000);subplot(2,3,6);imshow(o,[]);s_title=['图像重建精度判据如下:'];text(0,0,s_title,'Fontsize',14);s=num2str(toc);s_one=['run time = ' s ' s;'];text(0,100,s_one,'FontSize',10);s=num2str(evaluate_d);s_two=['归一化均方距离判据d=' s ';'];text(0,200,s_two,'Fontsize',10);s=num2str(evaluate_r);s_three=['归一化平均绝对距离判据r=' s ';'];text(0,300,s_three,'Fontsize',10);s=num2str(evaluate_e);s_four=['最坏情况距离判据e=' s ';'];text(0,400,s_four,'Fontsize',10);toc②FBP_GUI.m文件代码如下:function varargout = FBP_GUI(varargin)% FBP_GUI MATLAB code for FBP_GUI.fig% FBP_GUI, by itself, creates a new FBP_GUI or raises the existing% singleton*.%% H = FBP_GUI returns the handle to a new FBP_GUI or the handle to% the existing singleton*.%% FBP_GUI('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in FBP_GUI.M with the given input arguments. %% FBP_GUI('Property','Value',...) creates a new FBP_GUI or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before FBP_GUI_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application % stop. All inputs are passed to FBP_GUI_OpeningFcn via varargin.%% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help FBP_GUI% Last Modified by GUIDE v2.5 15-Apr-2017 14:24:03% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @FBP_GUI_OpeningFcn, ...'gui_OutputFcn', @FBP_GUI_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before FBP_GUI is made visible.function FBP_GUI_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to FBP_GUI (see VARARGIN)% Choose default command line output for FBP_GUIhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes FBP_GUI wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line. function varargout = FBP_GUI_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structure varargout{1} = handles.output;% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)I=phantom(256);[A]=dps(I);% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [fn,pn,fi]=uigetfile('*.*','选择图片');lujing=[pn fn];%得到待重建图像存储路径I=imread(lujing);[A]=dps(I);% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [fn,pn,fi]=uigetfile('*.*','选择图片');lujing=[pn fn];%得到待重建图像存储路径I=imread(lujing);I=rgb2gray(I);[A]=dps(I);% --- Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all。

相关主题