Ik Radon
Ik Radon
clear;
%J1org=imread('sinogram1.png')';
%J1org=im2uint8(J1org);
%S1=im2uint8(imread('sinogram1.png'))';
%[S1bp,S1fs]=ik_reconstruct('sinogram1.png',Padding,Filtered);
% We can also create a sinogram from MATLAB radon & phantom function.
%J1master=phantom(180);
%J1org = im2gray(radon(J1master,0:179));
Jb=im2gray(imread('b.png'));
Jbs=ik_create_sinogram(Jb,180);
Jc=im2gray(imread('c.png'));
Jcs=ik_create_sinogram(Jc,180);
Jd=im2gray(imread('d.png'));
Jds=ik_create_sinogram(Jd,180);
icol=8;
irow=7;
nimage=1;
subplot(irow,icol,nimage),imshow(Ja);title(['File=a.png']);nimage=nimage+1;
subplot(irow,icol,nimage),imshow(Jas);title('Sinogram a.png');nimage=nimage+1;
subplot(irow,icol,nimage),imshow(Jb);title(['File=b.png']);nimage=nimage+1;
subplot(irow,icol,nimage),imshow(Jbs);title('Sinogram b.png');nimage=nimage+1;
subplot(irow,icol,nimage),imshow(Jc);title(['File=c.png']);nimage=nimage+1;
subplot(irow,icol,nimage),imshow(Jcs);title('Sinogram c.png');nimage=nimage+1;
subplot(irow,icol,nimage),imshow(Jd);title(['File=d.png']);nimage=nimage+1;
subplot(irow,icol,nimage),imshow(Jds);title('Sinogram d.png');nimage=nimage+1;
for ss=1:11
fn1 = sprintf('sinogram%d.png', ss);
% reconstruct function is called by filename, Padding and Filtered.
% it returns sinogram, back projection and Fourier Sum image.
[Js,Jf,Jfs] = ik_reconstruct(fn1,Padding,Filtered);
% ========================================================================
function [out] = ik_create_sinogram(im,angs)
% The function creates sinogram of given image
% --------------------------------------------------
% Written by
% --------------------------------------------------
% M.Sc.EE ilkay KOZAK
% Politeknik Elektronik,
% ilkay.kozak@ogr.deu.edu.tr (2021900411)
% --------------------------------------------------
% INPUT
% im corresponds to the image.
% angs corresponds slice count.
% OUTPUT
% out is sinogram of given image and predefined slice count and angle
% steps.
% --------------------------------------------------
% dbg is used to display some values for debug purposes
dbg=0;
im=double(im);
theta=linspace(0,178,90);
if ( dbg == 1 )
disp(theta);
end
slice_count=angs;
slice_angle=180/angs;
Jout = zeros(slice_count,colsRadon);
if ( dbg == 1 )
disp(['xrow=',num2str(rowsRadon),', ycol=',num2str(colsRadon)]);
disp(['Angs=',num2str(angs)]);
end
sc=0;
for x=0:slice_angle:179
Jd=imrotate(im,x,'crop');
if ( dbg == 1 )
disp(['Rotate angle=',num2str(x)]);
end
for y=1:rowsRadon
%disp(sum(Jd(y,:)));
Jout(slice_count-sc,y)=sum(Jd(:,rowsRadon-y+1));%/colsR;
end
sc=sc+1;
end
if ( dbg == 1 )
disp(['sc=',num2str(sc)]);
end
Jout=Jout/180;
%Jout=flip(Jout,1);
Jout=Jout';
%Jr=flip(Jr,2);
Jout=imresize(Jout,[slice_count*3*slice_angle colsRadon]);
out=uint8(Jout);
end
% ========================================================================
function [sino,out,fs] = ...
ik_reconstruct(im,Padding,Filtered)
% The function creates back project of given sinogram
% --------------------------------------------------
% Written by
% --------------------------------------------------
% M.Sc.EE ilkay KOZAK
% Politeknik Elektronik,
% ilkay.kozak@ogr.deu.edu.tr (2021900411)
% --------------------------------------------------
% INPUT
% im corresponds to the image filename.
% Padding is used to eliminate crops on edges, enlarges working matrix
% adding zeros outsize of image.
% Filtered is used to filter fourier line using ramp filter.
% without filter center weigth is very high.
% OUTPUT
% out is back projection of sinogram given
% --------------------------------------------------
% dbg is used to display some values for debug purposes
dbg=1;
J1org=imread(im);
J1org=im2uint8(J1org)';
padSize=floor(size(J1org,1)/2);
sinogramSize=size(J1org,1);
sino=J1org;
% Paddind improves Projection Quality.
if Padding == 1
J1 = padarray(J1org, padSize, 'both');
else
J1=J1org;
end
J1=J1';
% Let's compute Sinogram row and col count.
[rows, cols] = size(J1);
Js=zeros(compDim,compDim);
if ( dbg == 1 )
disp(['xrow=',num2str(rows),', ycol=',num2str(cols)]);
disp(['compDim=',num2str(compDim),' PadSize=',num2str(padSize)]);
end
for x=1:rows
curRow = J1(x,:);
dummy=zeros(compDim,compDim);
for xx=1:compDim
dummy(xx,:)=curRow;
end
fourierCurRow = fftshift(fft2(ifftshift(dummy)));
if Filtered == 1
fourierCurRow = fourierCurRow' .* rampFilter_1d;
end
Js=Js+fourierCurRowRotate;
end
Jf = real(fftshift(ifft2(ifftshift(Js))));
Jf = imrotate(Jf,-90);
if Filtered ~= 1
Jf=Jf/120;
end
if Padding == 1
% Jf=Jf(padSize:(padSize+sinogramSize),padSize:(padSize+sinogramSize));
Jf=Jf(padSize+1:end-padSize,padSize+1:end-padSize);
% Jf=Jf((compDim-padSize*2)/2:(compDim+padSize*2)/2,(compDim-padSize*2)/2:
(compDim+padSize*2)/2);
end
out=Jf;
fs=Js;
end