├── BackProjection ├── CT_reconstruction.m ├── back_projection.m ├── convolution_back_projection.m └── filtered_back_projection.m ├── MaximumIntensityProjection ├── CT_MIP.m ├── MIP.m ├── image_normalize.m ├── load_DICOM_volume.m ├── load_volume.m ├── mip_360.avi ├── paralleltomo.m ├── rotate_axial_plane.m ├── rotate_views.m ├── rotate_volume.m ├── show_view.m └── write_video.m └── README.md /BackProjection/CT_reconstruction.m: -------------------------------------------------------------------------------- 1 | %% Implementation of Image Reconstruction 2 | % 3 | % In this script, CT image is reconstructed by 4 | % the method of back projection, filtered back 5 | % projection and convolution back projection. 6 | % 7 | % All results are saved in folder 'results'. 8 | % 9 | % Created by Qixun QU 10 | % 2017/05/01 11 | 12 | %% Clearn Environment 13 | clc 14 | clear 15 | close all 16 | 17 | %% Load Data 18 | load data.mat 19 | load data2.mat 20 | 21 | %% Part A. Back Projection 22 | % A2.The back projection of the sinogram data at 30 degree 23 | img_bp_30 = back_projection(g, 1, 30); 24 | 25 | % A3.Back projection summation images with different N 26 | N = 180; % Change N 27 | img_bp_N = back_projection(g, N); 28 | 29 | %% Part B. Filtered Back Projection 30 | % B2.Filtered back projection with different N 31 | N = 180; % Change N 32 | img_fbp_ramlak = filtered_back_projection(g, N, 'ramlak'); 33 | 34 | % B3.Apply Hamming window in filtering process 35 | N = 180; % Change N 36 | img_fbp_hamming = filtered_back_projection(g, N, 'hamming'); 37 | 38 | %% Part C. Convolution Back Projection 39 | % C2.Implement convolution back projection 40 | % with Hamming window with different N 41 | N = 180; % Chang N 42 | img_cbp_hamming = convolution_back_projection(g, N, 'hamming'); 43 | 44 | %% Part E. Real CT Image 45 | % E1.Reconstruct real CT image by applying three implementations 46 | % Back projection 47 | ri_bp = back_projection(g2); 48 | % Filtered back projection 49 | ri_fbp = filtered_back_projection(g2); 50 | % Convolution back projection 51 | ri_cbp = convolution_back_projection(g2); 52 | -------------------------------------------------------------------------------- /BackProjection/back_projection.m: -------------------------------------------------------------------------------- 1 | function img_bp = back_projection(sg, N, angle) 2 | %%BACK_PROJECTION Implement the back projection approach to reconstruct 3 | %image from given sinogram. 4 | % Input argument: 5 | % - sg : the known sinogram 6 | % - N : the number of projections used in construction, 7 | % default is the number of columns of sinogram 8 | % - angle : back projection of one data in sinogram at given angle 9 | % Output: 10 | % - img_bp : the reconstruction result 11 | 12 | % Set the default value for the number of 13 | % projection that applied to reconstruct 14 | if nargin < 2 || isempty(N) 15 | N = size(sg, 2); 16 | end 17 | 18 | % Set the default value of angle 19 | if nargin < 3 || isempty(angle) 20 | angle = -1; 21 | else 22 | N = length(angle); 23 | end 24 | 25 | % Obtain the size of sinogram and compute the 26 | % size of reconstructed image 27 | [gl, gt] = size(sg); 28 | hfgl = floor(gl / 2); 29 | 30 | iw = 2 * floor(gl / (2 * sqrt(2))); 31 | hfiw = iw / 2; 32 | 33 | % Back Projection 34 | % Initialize the reconstructed image 35 | img_bp = zeros(iw); 36 | 37 | % Compute some arguments for back projection 38 | % Positions map of reconstructed image 39 | [posX, posY] = meshgrid((1:iw) - hfiw); 40 | 41 | if angle == -1 42 | % If back projection is generated from 43 | % several data in sinogram 44 | % Calculate the degree interval 45 | igt = floor(gt / N); 46 | angles_array = 1:igt:gt; 47 | else 48 | % If back projection is created only by 49 | % one data in sinogram at given angle 50 | angles_array = angle; 51 | end 52 | 53 | % Run N times back projection 54 | for t = angles_array 55 | 56 | % Calculate the position in sinogram 57 | pos = posX * cosd(t) + posY * sind(t) + hfgl; 58 | % Accumulate projection of each degree sinogram 59 | img_bp = img_bp + interp1(1:gl, sg(:, t), pos); 60 | 61 | end 62 | 63 | % Multiply the factor 64 | img_bp = img_bp * (pi / (2 * N)); 65 | 66 | % Plot results 67 | % Plot back projection result that 68 | % multiplies the factor 69 | figure 70 | imagesc(img_bp), colormap gray 71 | axis('off') 72 | 73 | end -------------------------------------------------------------------------------- /BackProjection/convolution_back_projection.m: -------------------------------------------------------------------------------- 1 | function img_cbp = convolution_back_projection(sg, N, filter, angle) 2 | %%CONVOLUTION_BACK_PROJECTION Implement the convolution back projection 3 | %approach to reconstruct image from given sinogram. 4 | % Input argument: 5 | % - sg : the known sinogram 6 | % - filter : the name of the filter used to filter the projection, 7 | % default is 'hamming' 8 | % - N : the number of projections used in construction, 9 | % default is the number of columns of sinogram 10 | % - angle : back projection of one data in sinogram at given angle 11 | % Output: 12 | % - img_bp : the reconstruction result 13 | 14 | % Set the default value for the number of 15 | % projection that applied to reconstruct 16 | if nargin < 2 || isempty(N) 17 | N = size(sg, 2); 18 | end 19 | 20 | % Set the default value of filter 21 | if nargin < 3 || isempty(filter) 22 | filter = 'hamming'; 23 | end 24 | 25 | % Set the default value of angle 26 | if nargin < 4 || isempty(angle) 27 | angle = -1; 28 | else 29 | N = length(angle); 30 | end 31 | 32 | % Obtain the size of sinogram and compute the 33 | % size of reconstructed image 34 | [gl, gt] = size(sg); 35 | hfgl = floor(gl / 2); 36 | 37 | iw = 2 * floor(gl / (2 * sqrt(2))); 38 | hfiw = iw / 2; 39 | 40 | % Convolution Back Projection 41 | % Compute the Ram-Lak filter 42 | gx = [0:hfgl, hfgl - 1:-1:1]; 43 | if mod(gl, 2) ~= 0 44 | gx = [gx, 0]; 45 | end 46 | 47 | ramlak = 2 * gx / gl; 48 | 49 | switch filter 50 | 51 | case 'ramlak' % Use Ramlak filter 52 | H = ramlak; 53 | case 'hamming' % Use Hamming filter 54 | hamming = 0.54 - 0.46 * cos(2 * pi * (0:gl-1) / gl); 55 | H = [hamming(hfgl:gl), hamming(1:hfgl-1)] .* ramlak; 56 | otherwise 57 | fprintf('Wrong filter, it should be ''ramlak'' or ''hamming''.') 58 | 59 | end 60 | 61 | % Compute inverse Fourier transformation of filter 62 | c = real(ifftshift(ifft(H))); 63 | % Convolve the sinogram with the IFT of filter 64 | sgc = convn(sg, c', 'same'); 65 | 66 | % Initialize the reconstructed image 67 | img_cbp = zeros(iw); 68 | 69 | % Compute some arguments for back projection 70 | % Positions map of reconstructed image 71 | [posX, posY] = meshgrid((1:iw) - hfiw); 72 | 73 | if angle == -1 74 | % If back projection is generated from 75 | % several data in sinogram 76 | % Calculate the degree interval 77 | igt = floor(gt / N); 78 | angles_array = 1:igt:gt; 79 | else 80 | % If back projection is created only by 81 | % one data in sinogram at given angle 82 | angles_array = angle; 83 | end 84 | 85 | % Run N times back projection 86 | for t = angles_array 87 | 88 | % Calculate the position in sinogram 89 | pos = posX * cosd(t) + posY * sind(t) + hfgl; 90 | % Accumulate projection of each degree sinogram 91 | img_cbp = img_cbp + interp1(1:gl, sgc(:, t), pos); 92 | 93 | end 94 | 95 | % Multiply the factor 96 | img_cbp = img_cbp * (pi / (2 * N)); 97 | 98 | % Plot results 99 | % Plot back projection result 100 | figure 101 | imagesc(img_cbp), colormap gray 102 | axis('off') 103 | 104 | end -------------------------------------------------------------------------------- /BackProjection/filtered_back_projection.m: -------------------------------------------------------------------------------- 1 | function img_fbp = filtered_back_projection(sg, N, filter, angle) 2 | %%FILTERED_BACK_PROJECTION Implement the filtered back projection approach 3 | %to reconstruct image from given sinogram. 4 | % Input argument: 5 | % - sg : the known sinogram 6 | % - filter : the name of the filter used to filter the projection, 7 | % default is 'hamming' 8 | % - N : the number of projections used in construction, 9 | % default is the number of columns of sinogram 10 | % - angle : back projection of one data in sinogram at given angle 11 | % Output: 12 | % - img_bp : the reconstruction result 13 | 14 | % Set the default value for the number of 15 | % projection that applied to reconstruct 16 | if nargin < 2 || isempty(N) 17 | N = size(sg, 2); 18 | end 19 | 20 | % Set the default value of filter 21 | if nargin < 3 || isempty(filter) 22 | filter = 'hamming'; 23 | end 24 | 25 | % Set the default value of angle 26 | if nargin < 4 || isempty(angle) 27 | angle = -1; 28 | else 29 | N = length(angle); 30 | end 31 | 32 | % Obtain the size of sinogram and compute the 33 | % size of reconstructed image 34 | [gl, gt] = size(sg); 35 | hfgl = floor(gl / 2); 36 | 37 | iw = 2 * floor(gl / (2 * sqrt(2))); 38 | hfiw = iw / 2; 39 | 40 | % Filtered Back Projection 41 | % Compute the Ramlak filter 42 | gx = [0:hfgl, hfgl - 1:-1:1]; 43 | if mod(gl, 2) ~= 0 44 | gx = [gx, 0]; 45 | end 46 | 47 | ramlak = 2 * gx / gl; 48 | 49 | switch filter 50 | 51 | case 'ramlak' % Use Ramlak filter 52 | H = ramlak; 53 | case 'hamming' % Use Hamming filter 54 | hamming = 0.54 - 0.46 * cos(2 * pi * (0:gl-1) / gl); 55 | H = [hamming(hfgl:gl), hamming(1:hfgl-1)] .* ramlak; 56 | otherwise 57 | fprintf('Wrong filter, it should be ''ramlak'' or ''hamming''.') 58 | 59 | end 60 | 61 | % Compute Fourier transformation of sinogram 62 | gf = fft(sg, [], 1); 63 | % Multiply the filter in frequency domain 64 | gff = bsxfun(@times, gf, H'); 65 | % Do inverse Fourier transformation 66 | gffi = real(ifft(gff, [], 1)); 67 | 68 | % Initialize the reconstructed image 69 | img_fbp = zeros(iw); 70 | 71 | % Compute some arguments for back projection 72 | % Positions map of reconstructed image 73 | [posX, posY] = meshgrid((1:iw) - hfiw); 74 | 75 | if angle == -1 76 | % If back projection is generated from 77 | % several data in sinogram 78 | % Calculate the degree interval 79 | igt = floor(gt / N); 80 | angles_array = 1:igt:gt; 81 | else 82 | % If back projection is created only by 83 | % one data in sinogram at given angle 84 | angles_array = angle; 85 | end 86 | 87 | % Run N times back projection 88 | for t = angles_array 89 | 90 | % Calculate the position in sinogram 91 | pos = posX * cosd(t) + posY * sind(t) + hfgl; 92 | % Accumulate projection of each degree sinogram 93 | img_fbp = img_fbp + interp1(1:gl, gffi(:, t), pos); 94 | 95 | end 96 | 97 | % Multiply the factor 98 | img_fbp = img_fbp * (pi / (2 * N)); 99 | 100 | % Plot results 101 | % Plot back projection result 102 | figure 103 | imagesc(img_fbp), colormap gray 104 | axis('off') 105 | 106 | end -------------------------------------------------------------------------------- /MaximumIntensityProjection/CT_MIP.m: -------------------------------------------------------------------------------- 1 | %% Maximum Intensity Projection (MIP) 2 | % Lab 1 for Diagnostic Imaging 3 | % Group Members: Qixun Qu, Yankun Xu, Zihui Wang 4 | % Script and function are tested in Matlab 2016b. 5 | % 2017/04/22 6 | 7 | %% Clean Environment 8 | clc 9 | clear 10 | close all 11 | 12 | %% Load Data 13 | % Set the number of input dicom images 14 | % Here, all images are read into the memory 15 | slice_to_load = 1 : 113; 16 | 17 | % Load all images, the dimension of V is 18 | % 512 by 512 by 113 19 | V = load_DICOM_volume('spiral_CT_mandible', slice_to_load); 20 | 21 | %% Maximum Intensity Projection 22 | % Compute MIP in three different views 23 | mip_axial = MIP(V, 'axial'); 24 | mip_coronal = MIP(V, 'coronal'); 25 | mip_sagittal = MIP(V, 'sagittal'); 26 | 27 | % Show results 28 | show_view(mip_axial, 'Axial View') 29 | show_view(mip_coronal, 'Coronal View') 30 | show_view(mip_sagittal, 'Sagittal View') 31 | 32 | %% Rotate Volume 33 | % Rotate axial plane, obtain MIP from many angles 34 | % The viewing angle is fixed, rotate the volume 35 | views_360 = rotate_volume(V); 36 | 37 | %% Rotate Views 38 | % Rotate axial plane, obtain MIP from many angles 39 | % The volume is fixed, change the perspective 40 | % This method is too slow 41 | % views_360 = rotate_views(V); 42 | 43 | %% Write Results into a Video 44 | % Write all views into a video 45 | write_video(views_360, 'mip_360.avi', 10) 46 | -------------------------------------------------------------------------------- /MaximumIntensityProjection/MIP.m: -------------------------------------------------------------------------------- 1 | function mip = MIP(V, view) 2 | %%MIP Compute maximum intensity projection in given view. 3 | % 'V' is the volumn data. 4 | % Three possible inputs of 'view': 5 | % 'axial'(defaule), 'sagittal', 'coronal'. 6 | 7 | % Set default argument 8 | if nargin < 2 9 | view = 'axial'; 10 | end 11 | 12 | % Obtain the size of input volumn data 13 | [w, h, d] = size(V); 14 | 15 | switch view 16 | 17 | case 'axial' 18 | % Obtain the MIP in axial view 19 | mip = max(V, [], 3); 20 | 21 | case 'sagittal' 22 | % Obtain the MIP in sagittal view 23 | mip = max(V, [], 2); 24 | mip = flip(reshape(mip, w, d)', 1); 25 | 26 | case 'coronal' 27 | % Obtain the MIP in coronal view 28 | mip = max(V, [], 1); 29 | mip = flip(reshape(mip, h, d)', 1); 30 | 31 | end 32 | 33 | end -------------------------------------------------------------------------------- /MaximumIntensityProjection/image_normalize.m: -------------------------------------------------------------------------------- 1 | function img = image_normalize( img ) 2 | %%IMAGE_NORMALIZE Convert the range of image's values 3 | % from 0 to 1. 4 | 5 | % Convert image from int16 to double 6 | img = double(img); 7 | 8 | % Normalize the image 9 | imin = min(img(:)); 10 | imax = max(img(:)); 11 | img = (img - imin) / (imax - imin); 12 | 13 | end -------------------------------------------------------------------------------- /MaximumIntensityProjection/load_DICOM_volume.m: -------------------------------------------------------------------------------- 1 | function [v,t] = load_DICOM_volume(directory,slices_to_load) 2 | % LOAD_DICOM_VOLUME Loads in the specified DICOM files from the specified 3 | % directory into a 3D array. 4 | % V = LOAD_DICOM_VOLUME(D,S) loads in the DICOM files (files with the 5 | % extension .dcm) from DIRECTORY into the 3D array V with dimensions: 6 | % row, column, slice. The parameter S is a vector containing a range 7 | % of slice numbers; e.g. 1:5 8 | 9 | % keep a record of the current directory 10 | current_directory = cd; 11 | 12 | % go to the directory containing the DICOM files 13 | cd(directory); 14 | 15 | % get a list of all the files with the extension .dcm 16 | files = dir('*.dcm'); 17 | 18 | h = waitbar(0,'Loading volume...'); 19 | info = dicominfo(files(1).name); 20 | t = info.ContentTime; 21 | 22 | for i=slices_to_load 23 | v(:,:,i-slices_to_load(1)+1) = dicomread(files(i).name); 24 | waitbar(i/length(slices_to_load)); 25 | end 26 | close(h) 27 | 28 | % return to the original directory 29 | cd(current_directory); 30 | -------------------------------------------------------------------------------- /MaximumIntensityProjection/load_volume.m: -------------------------------------------------------------------------------- 1 | function V = load_volume( directory, slices_num ) 2 | % LOAD_VOLUME Load volume data from dicom images in given folder. 3 | 4 | % get a list of all the files with the extension .dcm 5 | files = dir([directory '/*.dcm']); 6 | 7 | h = waitbar(0, 'Loading ...'); 8 | for i = 1 : slices_num 9 | % Read dicom image and save it into output matrix 10 | V(:, :, i) = dicomread([directory '/' files(i).name]); 11 | waitbar(i / slices_num); 12 | 13 | end 14 | close(h) 15 | 16 | end 17 | -------------------------------------------------------------------------------- /MaximumIntensityProjection/mip_360.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quqixun/CTReconstruction/4d6f6adc7d83da5e511371570c3592e6e7934d92/MaximumIntensityProjection/mip_360.avi -------------------------------------------------------------------------------- /MaximumIntensityProjection/paralleltomo.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quqixun/CTReconstruction/4d6f6adc7d83da5e511371570c3592e6e7934d92/MaximumIntensityProjection/paralleltomo.m -------------------------------------------------------------------------------- /MaximumIntensityProjection/rotate_axial_plane.m: -------------------------------------------------------------------------------- 1 | function views = rotate_axial_plane( V, degrees ) 2 | %%ROTATE_AXIAL_PLANE Rotate the volumn on axial plane, 3 | % save all views in given degrees. 4 | % 'V' is the volumn data. 5 | % 'degrees' is a vector consists of degrees, default is 6 | % from 0 to 360. 7 | 8 | % Set default value for degrees 9 | if nargin < 2 || isempty(degrees) 10 | degrees = 0 : 360; 11 | end 12 | 13 | % Obtain the size of input volumn data 14 | [w, h, d] = size(V); 15 | 16 | % Obtain the length of 'degrees' 17 | d_num = length(degrees); 18 | 19 | % Initialize the output 20 | views = zeros(d, w, d_num); 21 | 22 | % Initialize a temporary variable 23 | V_temp = zeros(w, h, d); 24 | 25 | % Conut how many views have been obtained 26 | step = 0; 27 | h = waitbar(0, 'Rotating Axial Plane ...'); 28 | 29 | for i = degrees 30 | % In each degree, 31 | for j = 1 : d 32 | % In each image in the volumn, rotate the image, 33 | % thus, the volumn will be rotated 34 | V_temp(:, :, j) = imrotate(V(:, :, j), i, 'crop'); 35 | 36 | end 37 | 38 | % Save MIP into output 39 | step = step + 1; 40 | views(:, :, step) = MIP(V_temp, 'coronal'); 41 | 42 | waitbar(step / d_num) 43 | 44 | end 45 | close(h) 46 | 47 | end -------------------------------------------------------------------------------- /MaximumIntensityProjection/rotate_views.m: -------------------------------------------------------------------------------- 1 | function views = rotate_views( V, degrees ) 2 | %%ROTATE_VIEWS Rotate the viewing angles on axial plane, 3 | % save all views in given degrees. 4 | % 'V' is the volume data. 5 | % 'degrees' is a vector consists of degrees, default is 6 | % from 0 to 360. 7 | 8 | % Set default value for degrees 9 | if nargin < 2 || isempty(degrees) 10 | degrees = 0 : 360; 11 | end 12 | 13 | % Convert value into double 14 | V = double(V); 15 | 16 | % Obtain the size of input volumn data 17 | [w, ~, d] = size(V); 18 | 19 | % Obtain the length of 'degrees' 20 | d_num = length(degrees); 21 | 22 | % Initialize the output 23 | views = zeros(d, w, d_num); 24 | 25 | % Compute the number of rays 26 | p = round(sqrt(2) * w); 27 | 28 | % Compute the index of start and stop position 29 | % after the slice being projected 30 | width_diff = round((p - w)/2); 31 | w_start = width_diff + 1; 32 | w_stop = width_diff + w; 33 | 34 | % Initialize temporary variables 35 | slice_temp = zeros(d, w); 36 | max_temp = zeros(1, p); 37 | 38 | % Conut how many views have been obtained 39 | step = 0; 40 | h = waitbar(0, 'Rotating Axial Plane ...'); 41 | 42 | for i = degrees % In each viewing angle 43 | fprintf('Viewing Angle: %d\n', i) 44 | 45 | % Compute coefficient matrix, which consists of 46 | % positions where all rays cross the slice 47 | A = full(paralleltomo(w, i)); 48 | 49 | for j = 1 : d % In each slice 50 | fprintf('\tSlice: %d\n', j) 51 | 52 | % Extract a slice from the volume 53 | Vj = V(:, :, j); 54 | 55 | for k = 1 : p % Obtain the maximum in each ray 56 | Vj_temp = Vj(A(k, :) > 0); 57 | if isempty(Vj_temp) 58 | max_temp(k) = 0; 59 | else 60 | max_temp(k) = max(Vj_temp(:)); 61 | end 62 | end 63 | 64 | % slice_temp is the MIP of the volume at one viewing angle 65 | slice_temp(j, :) = flip(max_temp(w_start : w_stop), 2); 66 | end 67 | 68 | fprintf('\n') 69 | 70 | % Save MIP into output 71 | step = step + 1; 72 | views(:, :, step) = flip(slice_temp); 73 | 74 | waitbar(step / d_num) 75 | 76 | end 77 | close(h) 78 | 79 | end -------------------------------------------------------------------------------- /MaximumIntensityProjection/rotate_volume.m: -------------------------------------------------------------------------------- 1 | function views = rotate_volume( V, degrees ) 2 | %%ROTATE_VOLUME Rotate the volume on axial plane, 3 | % save all views in given degrees. 4 | % 'V' is the volume data. 5 | % 'degrees' is a vector consists of degrees, default is 6 | % from 0 to 360. 7 | 8 | % Set default value for degrees 9 | if nargin < 2 || isempty(degrees) 10 | degrees = 0 : 360; 11 | end 12 | 13 | % Obtain the size of input volume data 14 | [w, h, d] = size(V); 15 | 16 | % Obtain the length of 'degrees' 17 | d_num = length(degrees); 18 | 19 | % Initialize the output 20 | views = zeros(d, w, d_num); 21 | 22 | % Initialize a temporary variable 23 | V_temp = zeros(w, h, d); 24 | 25 | % Conut how many views have been obtained 26 | step = 0; 27 | h = waitbar(0, 'Rotating Axial Plane ...'); 28 | 29 | for i = degrees 30 | % At each degree, 31 | for j = 1 : d 32 | % In each image in the volume, rotate the image, 33 | % thus, the volume will be rotated 34 | V_temp(:, :, j) = imrotate(V(:, :, j), i, 'crop'); 35 | 36 | end 37 | 38 | % Save MIP into output 39 | step = step + 1; 40 | views(:, :, step) = MIP(V_temp, 'coronal'); 41 | 42 | waitbar(step / d_num) 43 | 44 | end 45 | close(h) 46 | 47 | end -------------------------------------------------------------------------------- /MaximumIntensityProjection/show_view.m: -------------------------------------------------------------------------------- 1 | function show_view( img, str ) 2 | %%SHOW_VIEW Show image with given title. 3 | 4 | if nargin < 2 || isempty(str) 5 | str = ''; 6 | end 7 | 8 | figure 9 | imshow(img, []) 10 | title(str) 11 | 12 | end 13 | -------------------------------------------------------------------------------- /MaximumIntensityProjection/write_video.m: -------------------------------------------------------------------------------- 1 | function write_video( views, name, sec ) 2 | %%WRITE_VIDEO Write all view images into a video. 3 | % The 3rd dimension of 'views' indicates the number 4 | % of views. 5 | % 'name' is the file name of the video. 6 | % 'sec' is the the length of video in seconds. 7 | 8 | % Set default length for video file 9 | if nargin < 3 || isempty(sec) 10 | sec = 10; 11 | end 12 | 13 | % Set default name for video file 14 | if nargin < 2 || isempty(name) 15 | name = 'mip.avi'; 16 | end 17 | 18 | % Create a video 19 | mip_video = VideoWriter(name); 20 | 21 | % Set the frame rate according to the length 22 | mip_video.FrameRate = round(size(views, 3) / sec); 23 | 24 | % Write image into video 25 | open(mip_video); 26 | for i = 1 : size(views, 3) 27 | 28 | % Normalize the view 29 | f = image_normalize(views(:, :, i)); 30 | writeVideo(mip_video, f); 31 | 32 | % Method to write gif file 33 | % [A,map] = gray2ind(f,256); 34 | % delay = 1 / mip_video.FrameRate; 35 | % if i == 1 36 | % imwrite(A, map, 'mip_360.gif', 'gif',... 37 | % 'LoopCount', Inf, 'DelayTime', delay); 38 | % elseif mod(i, 10) == 0 39 | % imwrite(A, map, 'mip_360.gif', 'gif',... 40 | % 'WriteMode', 'append', 'DelayTime', delay); 41 | % end 42 | 43 | end 44 | 45 | % Close the video file 46 | close(mip_video); 47 | 48 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CTReconstruction 2 | Matlab code for reconstructing CT image by applying back projection, filtered back projection and convolution back projection. 3 | --------------------------------------------------------------------------------