Skip to content

Instantly share code, notes, and snippets.

@hex007
Created October 2, 2012 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hex007/3816188 to your computer and use it in GitHub Desktop.
Save hex007/3816188 to your computer and use it in GitHub Desktop.
function [ res ] = myradon(img)
%% Padding
center=floor(size(img)/2)+1;
padsize=sqrt(size(img,1)^2+size(img,2)^2);
padsize=2*floor(padsize/2)+1;
padcenter=[ceil(padsize/2),ceil(padsize/2)];
padimg=zeros(padsize);
padimg(padcenter(1)-center(1):padcenter(1)+center(1),...
padcenter(2)-center(2):padcenter(2)+center(2))...
=img(1:2*center+1,1:2*center+1);
%% process
[a b]=size(padimg);
mid=floor(a/2)+1;
x=ceil(-a/2):floor(a/2);
y=ceil(-b/2):floor(b/2);
[X Y]=meshgrid(x,y);
fs=30;
theta=fs:fs:360;
rad=deg2rad(theta);
n=length(rad);
for i=1:n
disp(i)
r=round(X*cos(rad(i))+Y*sin(rad(i)))+mid;
s=round(-X*sin(rad(i))+Y*cos(rad(i)))+mid;
[R S]=ind2sub(size(padimg),find(r>0 & r<a & s>0 & s<a));
t=sum(padimg(R,S),2)
m=floor(size(t,1)/2)
res(i,:)=t(m-mid:m+mid)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment