Demo entry 6799508

matlab

   

Submitted by anonymous on May 20, 2019 at 13:03
Language: Matlab. Code size: 990 Bytes.

function g=Radon(f,dlt_theta)
%该函数实现了radon变换。f为输入图像;g为输出的正弦图,其中行为rou的划分,列为theta的划分;dlt_theta为角度的增量(单位为度)
f1=im2double(f);
[m,n]=size(f1);

le=round(sqrt(m*m+n*n));  %对角线长度
y=( -round(le/2)+1:round(le/2) );  %当theta=0时,投影线需要覆盖的最大范围
w=2*round(le/2);  %y的长度
p=le;  %正弦图的行数,rou值的划分数
dlt_rou=le/p;
rou0=-le/2;

dlt_rad=dlt_theta*pi/180;  %度数转换为弧度
q=round(pi/dlt_rad); %正弦图的列数,角度theta的划分

g=zeros(p,q);  %投影后的正弦图

for i=1:q
    theta=pi-(i-1)*dlt_rad;
    for j=1:p
        rou=rou0+(j-1)*dlt_rou;
            x2=-rou*cos(theta)+y*sin(theta);   %旋转投影线得到的新坐标系下的坐标值
            y2=rou*sin(theta)+y*cos(theta);    %旋转投影线得到的新坐标系下的坐标值
            x2=round(x2+n/2);      %将坐标转换为像素点列
            y2=round(-y2+m/2);     %将坐标转换为像素点行
            for k=1:w
                if((x2(1,k)>0) && (x2(1,k)<n+1) && (y2(1,k)>0) && (y2(1,k)<m+1))  %判断点是否在图像内
                    g(j,i)=g(j,i)+f1(y2(1,k),x2(1,k));    %对投影线上的像素点求和
                end
            end
    end
end
 
end

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).