0% found this document useful (0 votes)
39 views4 pages

Ik Radon

The document discusses creating sinograms and reconstructing images from sinograms. It defines functions to: 1) Create a sinogram from an input image by rotating the image in defined slice angles and summing pixel values. 2) Reconstruct an image from a sinogram by back projecting each sinogram row after optional filtering, and summing the projections. 3) Display input images, sinograms, and reconstructions in a subplot format.

Uploaded by

ilkay KOZAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Ik Radon

The document discusses creating sinograms and reconstructing images from sinograms. It defines functions to: 1) Create a sinogram from an input image by rotating the image in defined slice angles and summing pixel values. 2) Reconstruct an image from a sinogram by back projecting each sinogram row after optional filtering, and summing the projections. 3) Display input images, sinograms, and reconstructions in a subplot format.

Uploaded by

ilkay KOZAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

% ilkay KOZAK - 2021900411

clear;

% if Padding is set, sinogram is extended by its size to eliminate crops on


% edges.
Padding=1;
% if set Ram-Lak is applied
Filtered=1;

%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));

% Sinogram is calculated here.


% we pass image and slice count (180 means in ever 1 degree, 90 means every
% 2 degree and so on. When we lower slice count, image quality drops.
% 180 is maximum slice count.
%Jr = zeros(180,colsR);
Ja=im2gray(imread('a.png'));
%[rowsR, colsR] = size(J1master);
%Jrm = radon(J1master,0:179);
Jas=ik_create_sinogram(Ja,180);

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);

I1 = iradon(im2uint8(imread(fn1)'), 0:179, 'linear', 'Ram-Lak');


subplot(irow,icol,nimage),imshow(Js);title(['File=',fn1]);nimage=nimage+1;
subplot(irow,icol,nimage),imshow(I1);title('MATLAB iRadon');nimage=nimage+1;
subplot(irow,icol,nimage),imshow(uint8(real(Jf)));title('ikBackProjection');nimage=
nimage+1;
subplot(irow,icol,nimage),imshow(real(Jfs));title('Fourier Sum');nimage=nimage+1;
end

% Set up figure properties:


% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Sinogram by IK', 'NumberTitle', 'Off')

% ========================================================================
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);

[rowsRadon, colsRadon] = size(im);

if angs > 180


disp('Angs must be lower than 180');
return;
end

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);

compDim = size(J1, 2);

Js=zeros(compDim,compDim);

if ( dbg == 1 )
disp(['xrow=',num2str(rows),', ycol=',num2str(cols)]);
disp(['compDim=',num2str(compDim),' PadSize=',num2str(padSize)]);
end

% it is Ram-Lak filter. 1 at the edges, 0 at center.


rampFilter_1d = abs(linspace(-1, 1, compDim))';

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

fourierCurRowRotate = imrotate(fourierCurRow, x, 'crop');

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy