├── Readme.docx ├── PhotonAttenuationQ.m ├── PhotonIntensity.mat ├── graphics ├── mpgread.dll ├── mpgwrite.dll ├── private │ ├── VRMLra.m │ ├── SetDisplay.m │ ├── GetDisplay.m │ ├── VRMLca.m │ ├── UpdateDisplay.m │ ├── VRMLpg.m │ ├── VRMLpa.m │ ├── robotTemplate.wrl │ ├── VRMLcf.m │ ├── vehicleTemplate.wrl │ └── DisplayConsole.m ├── plot2.m ├── pplot.m ├── plane.m ├── mpgwrite.m ├── brain.m ├── anatomy.m ├── mpgread.m ├── french.m ├── spectral.m ├── hotmetal.m ├── combcolor.m ├── gecolor.m ├── gecolour.m ├── imdisp2.m ├── rainbow.m ├── arrow.m ├── imdisp.m ├── rgb.m └── imhdr.m ├── BackgroundInformation.docx ├── CreateProjSlice_Helical_Curve.mexw64 ├── CreateProjSlice_Helical_Flat.mexw64 ├── Parallel_FDK_Helical_2DWeighting.mexw64 ├── Parallel_FDK_Helical_3DWeighting.mexw64 ├── Parallel_FDK_Helical_NOWeighting.mexw64 ├── CreateSourcePosAry_CB_Helical.m ├── README.md ├── Parallel_Rebinning_CB_Flat.m ├── Parallel_Rebinning_CB_Curve.m ├── Conebeam_Curve_CreateProj_CB_Helical_Spectrum.m ├── Conebeam_Flat_CreateProj_CB_Helical_Spectrum.m ├── ParseChemicalFormula.m ├── Helical_Rec_Flat.m ├── Helical_Rec_Curve.m ├── Parallel_FDK_Helical_NOWeighting.cpp ├── CreateProjSlice_Helical_Flat.cpp ├── CreateProjSlice_Helical_Curve.cpp ├── Parallel_FDK_Helical_2DWeighting.cpp ├── myHelical_Rec_Curve.m ├── Parallel_FDK_Helical_3DWeighting.cpp ├── PhotonAttenuation.m └── PhysProps.m /Readme.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/Readme.docx -------------------------------------------------------------------------------- /PhotonAttenuationQ.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/PhotonAttenuationQ.m -------------------------------------------------------------------------------- /PhotonIntensity.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/PhotonIntensity.mat -------------------------------------------------------------------------------- /graphics/mpgread.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/graphics/mpgread.dll -------------------------------------------------------------------------------- /graphics/mpgwrite.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/graphics/mpgwrite.dll -------------------------------------------------------------------------------- /BackgroundInformation.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/BackgroundInformation.docx -------------------------------------------------------------------------------- /CreateProjSlice_Helical_Curve.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/CreateProjSlice_Helical_Curve.mexw64 -------------------------------------------------------------------------------- /CreateProjSlice_Helical_Flat.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/CreateProjSlice_Helical_Flat.mexw64 -------------------------------------------------------------------------------- /Parallel_FDK_Helical_2DWeighting.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/Parallel_FDK_Helical_2DWeighting.mexw64 -------------------------------------------------------------------------------- /Parallel_FDK_Helical_3DWeighting.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/Parallel_FDK_Helical_3DWeighting.mexw64 -------------------------------------------------------------------------------- /Parallel_FDK_Helical_NOWeighting.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hengyongyu/OpenRecon/HEAD/Parallel_FDK_Helical_NOWeighting.mexw64 -------------------------------------------------------------------------------- /graphics/private/VRMLra.m: -------------------------------------------------------------------------------- 1 | function A = VRMLra(nx,ny,nz,phi) 2 | % 3 | % function returns a 3x3 rotation matrix corresponding to 4 | % a rotation of phi about [xn;xy;xz] 5 | % 6 | 7 | sp = sin(phi); cp = cos(phi); vp = 1-cp; 8 | 9 | A = [nx*nx*vp+cp nx*ny*vp-nz*sp nx*nz*vp+ny*sp; ny*nx*vp+nz*sp ny*ny*vp+cp ny*nz*vp-nx*sp; nz*nx*vp-ny*sp nz*ny*vp+nx*sp nz*nz*vp+cp ]; 10 | 11 | -------------------------------------------------------------------------------- /graphics/plot2.m: -------------------------------------------------------------------------------- 1 | function plot2(a,b,kb,dim) 2 | 3 | if nargin==3, dim = 1; end 4 | 5 | ka = ~(dim-1)+1; 6 | ka = floor(kb*size(a,ka)/size(b,ka)); 7 | 8 | na = size(a,dim); 9 | nb = size(b,dim); 10 | xa = linspace(1,max(na,nb),na); 11 | xb = linspace(1,xa(end),nb); 12 | 13 | if dim==1 14 | plot(xa,a(:,ka),'b',xb,b(:,kb),'r'); 15 | else 16 | plot(xa,a(ka,:),'b',xb,b(kb,:),'r'); 17 | end 18 | axis tight; 19 | -------------------------------------------------------------------------------- /graphics/pplot.m: -------------------------------------------------------------------------------- 1 | function pplot(p,varargin) 2 | 3 | c = 'g'; 4 | if nargin==2, c = varargin{1}; end 5 | 6 | if nargin<3 7 | opts = { 'rs', ... 8 | 'LineWidth',1, ... 9 | 'MarkerEdgeColor','k', ... 10 | 'MarkerFaceColor',c, ... 11 | 'MarkerSize',5 12 | }; 13 | else 14 | opts = varargin; 15 | end 16 | 17 | if size(p,1)==3 18 | plot3(p(1,:),p(2,:),p(3,:),opts{:}); 19 | elseif size(p,2)==3 20 | plot3(p(:,1)',p(:,2)',p(:,3)',opts{:}); 21 | else 22 | plot(p(1,:),p(2,:),opts{:}); 23 | end 24 | -------------------------------------------------------------------------------- /graphics/private/SetDisplay.m: -------------------------------------------------------------------------------- 1 | function SetDisplay(arg,handles,varargin) 2 | 3 | switch arg 4 | case 'ShowPoint' 5 | set(handles.ShowPoint,'Value',varargin{1}); 6 | 7 | case 'ShowGraph' 8 | set(handles.ShowGraph,'Value',varargin{1}); 9 | 10 | case 'Windowing' 11 | value = GetValue(varargin{1}); 12 | set(handles.Limits,{'Value'},value); 13 | value{1} = num2str(value{1}); 14 | value{2} = num2str(value{2}); 15 | set(handles.LimTxt,{'String'},value); 16 | if nargin>3 17 | set(handles.Limits,{'Min','Max'},GetValue(varargin{2})); 18 | end 19 | 20 | case 'Point' 21 | set(handles.Point,{'Value'},GetValue(varargin{1})); 22 | end 23 | 24 | UpdateDisplay(handles); 25 | 26 | 27 | % -------------------------------------------------------------------- 28 | function value = GetValue(value) 29 | 30 | if ~iscell(value), value = num2cell(value); end 31 | -------------------------------------------------------------------------------- /CreateSourcePosAry_CB_Helical.m: -------------------------------------------------------------------------------- 1 | function PosArry = CreateSourcePosAry_CB_Helical(BetaS,BetaE,SO,h,ViewN) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % SO : Distance between the source-Center and the origin 4 | % ViewN : The total source number 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | % PosArry{:,1} x coordinate of the source position 7 | % PosArry[:,2] y coordinate of the source position 8 | % PosArry[:,3] z coordinate of the source position 9 | % PosArry[:,4] x component of the unit vector 10 | % PosArry[:,5] y component of the unit vector 11 | %%%%%%%%%%%%%%%%%%%%%% View 12 | PosArry = zeros(ViewN,5); 13 | deltafai=(BetaE-BetaS)/(ViewN-1); 14 | for i=1:ViewN 15 | View = BetaS+(i-1)*deltafai; 16 | PosArry(i,1) = SO*cos(View); 17 | PosArry(i,2) = SO*sin(View); 18 | PosArry(i,3) = h*View/(2*pi); 19 | PosArry(i,4) = cos(View); 20 | PosArry(i,5) = sin(View); 21 | end 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /graphics/plane.m: -------------------------------------------------------------------------------- 1 | function [xx,yy,zz] = plane(c,y,z) 2 | %PLANE Generate plane. 3 | % [X,Y,Z] = PLANE(N) generates three (N+1)-by-(N+1) 4 | % matrices so that SURF(X,Y,Z) produces a unit plane. 5 | % 6 | % [X,Y,Z] = PLANE uses N = 20. 7 | % 8 | % PLANE(N) and just PLANE graph the plane as a SURFACE 9 | % and do not return anything. 10 | % 11 | % See also ELLIPSOID, CYLINDER, SPHERE. 12 | 13 | if nargin<2, y = [-1,1,2]; end 14 | if nargin<3, z = y; end 15 | y = ParseInput(y); 16 | z = ParseInput(z); 17 | 18 | [y,z] = meshgrid(linspace(y(1),y(2),y(3)),linspace(z(1),z(2),z(3))); 19 | 20 | x = z; 21 | x(:) = c; 22 | 23 | if nargout == 0 24 | surf(x,y,z); 25 | alpha(.3); 26 | else 27 | xx = x; yy = y; zz = z; 28 | end 29 | 30 | 31 | function y = ParseInput(y) 32 | 33 | if length(y)==1 34 | y = [-y,y,2]; 35 | elseif length(y)==2 36 | y = [y 2]; 37 | end 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenRecon 2 | This open-source software package is a response to the NIH/NIBIB Low-dose CT U01 community. The purpose is to share a standardized platform equipped with key analytic reconstruction methods for helical/spiral multi-slice/cone-beam CT assuming either a flat-panel detector or a curved detector array. 3 | 4 | For the flat-panel detector, the main file is: Helical_Rec_Flat.m 5 | 6 | For the curved detector, the main file is: Helical_Rec_Curve.m 7 | 8 | If your Matlab cannot identify the MEX file, you can re-compile the corresponding CPP files use the MEX command. 9 | 10 | The functions to generate the linear attenuation coefficients are from the following webpage: http://www.mathworks.com/matlabcentral/fileexchange/12092-photonattenuation-2, and the copyright belongs to Jaroslaw Tuszynski. The image display graphic toolbox was developed by our late collaborator Dr. Shiying Zhao in 2004 for our collaboration. The public use of Dr. Zhao’s codes is a good way in memory of his dedication and contribution to our field. 11 | -------------------------------------------------------------------------------- /graphics/mpgwrite.m: -------------------------------------------------------------------------------- 1 | %MPGWRITE Write an MPEG file. 2 | % MPGWRITE(M, map, 'filename', options) Encodes M in MPEG 3 | % format using the specified colormap and writes the result to the 4 | % specified file. The options argument is an optional vector of 5 | % 8 or fewer options where each value has the following meaning: 6 | % 1. REPEAT: 7 | % An integer number of times to repeat the movie 8 | % (default is 1). 9 | % 2. P-SEARCH ALGORITHM: 10 | % 0 = logarithmic (fastest, default value) 11 | % 1 = subsample 12 | % 2 = exhaustive (better, but slow) 13 | % 3. B-SEARCH ALGORITHM: 14 | % 0 = simple (fastest) 15 | % 1 = cross2 (slightly slower, default value) 16 | % 2 = exhaustive (very slow) 17 | % 4. REFERENCE FRAME: 18 | % 0 = original (faster, default) 19 | % 1 = decoded (slower, but results in better quality) 20 | % 5. RANGE IN PIXELS: 21 | % An integer search radius. Default is 10. 22 | % 6. I-FRAME Q-SCALE: 23 | % An integer between 1 and 31. Default is 8. 24 | % 7. P-FRAME Q-SCALE: 25 | % An integer between 1 and 31. Default is 10. 26 | % 8. B-FRAME Q-SCALE: 27 | % An integer between 1 and 31. Default is 25. 28 | % 29 | 30 | -------------------------------------------------------------------------------- /graphics/brain.m: -------------------------------------------------------------------------------- 1 | function c = brain(m); 2 | 3 | % ColEdit function [cmap] = brain(maplength); 4 | % 5 | % colormap m-file written by ColEdit 6 | % version 1.1 on 04-Nov-2002 7 | % 8 | % input : [maplength] [64] - colormap length 9 | % 10 | % output : cmap - colormap RGB-value array 11 | 12 | if nargin<1, m = size(get(gcf,'colormap'),1); end 13 | 14 | % set red points 15 | r = [ [];... 16 | [0 0];... 17 | [0.275 0.1];... 18 | [0.625 1];... 19 | [1 1];... 20 | [] ]; 21 | 22 | % set green points 23 | g = [ [];... 24 | [0 0];... 25 | [0.625 0];... 26 | [1 1];... 27 | [] ]; 28 | 29 | % set blue points 30 | b = [ [];... 31 | [0 0];... 32 | [0.075 0.3];... 33 | [0.375 1];... 34 | [0.475 1];... 35 | [0.625 0];... 36 | [1 0];... 37 | [] ]; 38 | % ColEditInfoEnd 39 | 40 | % interpolate colormap 41 | n = linspace(0,1,m); 42 | r = interp1(r(:,1),r(:,2),n,'linear'); 43 | g = interp1(g(:,1),g(:,2),n,'linear'); 44 | b = interp1(b(:,1),b(:,2),n,'linear'); 45 | 46 | % compose colormap 47 | c = [r(:),g(:),b(:)]; 48 | -------------------------------------------------------------------------------- /graphics/private/GetDisplay.m: -------------------------------------------------------------------------------- 1 | function varargout = GetDisplay(arg,handles,varargin) 2 | 3 | switch arg 4 | case 'ShowPoint' 5 | varargout{1} = get(handles.ShowPoint,'Value'); 6 | 7 | case 'ShowGraph' 8 | varargout{1} = get(handles.ShowGraph,'Value'); 9 | 10 | case 'ShowTips' 11 | varargout{1} = get(handles.ShowTips,'Value'); 12 | 13 | case 'Overlay' 14 | varargout{1} = get(handles.Display(4),'Value'); 15 | 16 | case 'Windowing' 17 | lims = cell2mat(get(handles.Limits,'Value')); 18 | if nargout==1 19 | varargout{1} = lims; 20 | else 21 | [varargout{1:2}] = deal(lims(1),lims(2)); 22 | end 23 | 24 | case 'Point' 25 | if isfield(handles,'Point') 26 | [varargout{1:nargout}] = GetSliders(handles.Point,@round); 27 | else 28 | [varargout{1:nargout}] = deal(0,0,0); 29 | end 30 | end 31 | 32 | 33 | % -------------------------------------------------------------------- 34 | function varargout = GetSliders(hsldr,f) 35 | 36 | value = cell2mat(get(hsldr,'Value')); 37 | if nargin==2, value = feval(f,value); end 38 | if nargout==1 39 | varargout{1} = value; 40 | else 41 | [varargout{1:3}] = deal(value(1),value(2),value(3)); 42 | end 43 | -------------------------------------------------------------------------------- /graphics/anatomy.m: -------------------------------------------------------------------------------- 1 | function c = anatomy(m); 2 | 3 | % ColEdit function [cmap] = anatomy(maplength); 4 | % 5 | % colormap m-file written by ColEdit 6 | % version 1.1 on 04-Nov-2002 7 | % 8 | % input : [maplength] [64] - colormap length 9 | % 10 | % output : cmap - colormap RGB-value array 11 | 12 | if nargin<1, m = size(get(gcf,'colormap'),1); end 13 | 14 | % set red points 15 | r = [ [];... 16 | [0 0];... 17 | [0.075 0];... 18 | [0.375 0.3];... 19 | [0.625 1];... 20 | [1 1];... 21 | [] ]; 22 | 23 | % set green points 24 | g = [ [];... 25 | [0 0];... 26 | [0.375 0.3];... 27 | [0.625 0.3];... 28 | [1 1];... 29 | [] ]; 30 | 31 | % set blue points 32 | b = [ [];... 33 | [0 0];... 34 | [0.075 0.35];... 35 | [0.500 1];... 36 | [0.625 0];... 37 | [1 0.6];... 38 | [] ]; 39 | % ColEditInfoEnd 40 | 41 | % interpolate colormap 42 | n = linspace(0,1,m); 43 | r = interp1(r(:,1),r(:,2),n,'linear'); 44 | g = interp1(g(:,1),g(:,2),n,'linear'); 45 | b = interp1(b(:,1),b(:,2),n,'linear'); 46 | 47 | % compose colormap 48 | c = [r(:),g(:),b(:)]; 49 | -------------------------------------------------------------------------------- /graphics/mpgread.m: -------------------------------------------------------------------------------- 1 | %MPGREAD Read an MPEG encoded movie file. 2 | % [M, map] = mpgread('filename', frames) reads the specifed 3 | % MPEG file and translates it into the movie M, and colormap map. 4 | % If a vector frames is specified, then only the frames specified 5 | % in this vector will be placed in M. Otherwise, all frames will 6 | % be placed in M. 7 | % 8 | % M = mpgread('filename', frames, 'indexed') 9 | % Reads an MPEG file into the MATLAB 5.3+ format movie which 10 | % is a structure array. Each element has a cdata field 11 | % containing a uint8 image matrix and a colormap field 12 | % containing the colormap. The frames parameter can be [] to 13 | % indicate that all frames should be read. 14 | % 15 | % M = mpgread('filename', frames, 'truecolor') 16 | % Reads an MPEG file into the MATLAB 5.3+ format movie. Each 17 | % frame in the movie has a truecolor MxNx3 cdata field and 18 | % an empty colormap field. 19 | % 20 | % [R, G, B] = mpgread('filename', frames) will perform the same 21 | % operation as above, except that the decoded MPEG frames will 22 | % be placed into the matrices R, G, B, where R contains the red 23 | % component for each frame, G, the green component, and B, the 24 | % blue component. 25 | % 26 | -------------------------------------------------------------------------------- /graphics/french.m: -------------------------------------------------------------------------------- 1 | function h = french(m,flag) 2 | %FRENCH French's flag color map. 3 | % FRENCH(M) returns an M-by-3 matrix containing a "french flag" colormap. 4 | % FRENCH, by itself, is the same length as the current colormap. 5 | % 6 | % FRENCH(M,FLAG) enables a modification of the colormap, where 7 | % FLAG can be either 1 (default) or 2. 8 | % 9 | % For example, to reset the colormap of the current figure: 10 | % 11 | % colormap(french) 12 | % 13 | % See also HOT, HSV, GRAY, PINK, COOL, BONE, COPPER, FLAG, 14 | % COLORMAP, RGBPLOT. 15 | 16 | % Copyright (c) 2002 by AMRON 17 | % Norbert Marwan, Potsdam University, Germany 18 | % http://www.agnld.uni-potsdam.de 19 | % 20 | % Last Revision: 2002-11-08 21 | % Version: 1.1 22 | 23 | 24 | if nargin < 1 25 | m = size(get(gcf,'colormap'),1); 26 | else 27 | if isempty(m) 28 | m = size(get(gcf,'colormap'),1); 29 | end 30 | end 31 | if nargin < 2, flag = 1; end 32 | 33 | n1 = fix(3*m/8); 34 | n2 = fix(m/4); 35 | n3 = fix(m/2); 36 | 37 | switch flag 38 | case 1 39 | r = [ones(n3,1); (sqrt(1-((1:n3)/n3).^2))']; 40 | g = [flipud( (sqrt(1-((1:n3)/n3).^2))'); (sqrt(1-((1:n3)/n3).^2))']; 41 | b = [flipud((sqrt(1-((1:n3)/n3).^2))'); ones(n3,1)]; 42 | case 2 43 | r = [ones(n1+n2,1); (n1-1:-1:0)'/n1;]; 44 | g = [(0:n1-1)'/n1; ones(n2,1); (n1-1:-1:0)'/n1;]; 45 | b = [(0:n1-1)'/n1; ones(n1+n2,1);]; 46 | end 47 | 48 | h = [r g b]; 49 | 50 | if size(h,1) 0 & rmax > 0 26 | if rmin/rmax <= 0.25 27 | rmin = 0; 28 | end 29 | elseif rmin < 0 & rmax < 0 30 | if rmax/rmin <= 0.25 31 | rmax = 0; 32 | end 33 | end 34 | 35 | % Compute a step which guarantees between 1 and 10 steps between rmin and rmax 36 | % If within 20% of preferred step then use that, otherwise look for 37 | % a value of step which gives (in most cases) between 4 and 7 labels. 38 | if rdiff > 0 39 | step = 10^floor(log(abs(rdiff))/log(10)); 40 | 41 | if preferredStep ~= 0 & abs(preferredStep - step )/step < 0.20 42 | step = preferredStep; 43 | elseif rdiff/step < 1.4 44 | step = step/4; 45 | elseif rdiff/step < 3 46 | step = step/2; 47 | end 48 | if rdiff/step > 6 49 | step = step*2; 50 | end 51 | 52 | smin = floor(rmin/step)*step; 53 | smax = ceil(rmax/step)*step; 54 | else 55 | smin=rmin; 56 | smax=rmax; 57 | step=0; 58 | end 59 | 60 | axis = [smin,step,smax]; 61 | -------------------------------------------------------------------------------- /graphics/spectral.m: -------------------------------------------------------------------------------- 1 | function c = spectral(m) 2 | 3 | %SPECTRAL Black-purple-blue-green-yellow-red-white color map. 4 | % 5 | % map = spectral(num_colors) 6 | % 7 | % SPECTRAL(M) returns an M-by-3 matrix containing a "spectral" colormap. 8 | % SPECTRAL, by itself, is the same length as the current colormap. 9 | % 10 | % For example, to reset the colormap of the current figure: 11 | % 12 | % colormap(spectral) 13 | % 14 | % See also HSV, GRAY, PINK, HOT, COOL, BONE, COPPER, FLAG, 15 | % COLORMAP, RGBPLOT. 16 | 17 | % $Id: spectral.m,v 1.4 1997/10/20 18:23:22 greg Rel $ 18 | % $Name: emma_v0_9_5 $ 19 | 20 | % Copyright (c) 1984-92 by The MathWorks, Inc. 21 | % Spectral version made by Gabriel Leger, MBIC, MNI (c) 1993 22 | 23 | if nargin<1, m = size(get(gcf,'colormap'),1); end 24 | 25 | base = [ 0.0000 0.0000 0.0000 26 | 0.4667 0.0000 0.5333 27 | 0.5333 0.0000 0.6000 28 | 0.0000 0.0000 0.6667 29 | 0.0000 0.0000 0.8667 30 | 0.0000 0.4667 0.8667 31 | 0.0000 0.6000 0.8667 32 | 0.0000 0.6667 0.6667 33 | 0.0000 0.6667 0.5333 34 | 0.0000 0.6000 0.0000 35 | 0.0000 0.7333 0.0000 36 | 0.0000 0.8667 0.0000 37 | 0.0000 1.0000 0.0000 38 | 0.7333 1.0000 0.0000 39 | 0.9333 0.9333 0.0000 40 | 1.0000 0.8000 0.0000 41 | 1.0000 0.6000 0.0000 42 | 1.0000 0.0000 0.0000 43 | 0.8667 0.0000 0.0000 44 | 0.8000 0.0000 0.0000 45 | 0.8000 0.8000 0.8000 46 | ]; 47 | 48 | % interpolate colormap 49 | n = length(base); 50 | t = linspace(1,n,m); 51 | n = 1:n; 52 | r = interp1(n,base(:,1),t,'linear'); 53 | g = interp1(n,base(:,2),t,'linear'); 54 | b = interp1(n,base(:,3),t,'linear'); 55 | 56 | % compose colormap 57 | c = [r(:),g(:),b(:)]; 58 | -------------------------------------------------------------------------------- /graphics/private/UpdateDisplay.m: -------------------------------------------------------------------------------- 1 | function UpdateDisplay(hobj,evdt) 2 | 3 | if nargin==1 4 | handles = hobj; 5 | else 6 | handles = guidata(hobj); 7 | end 8 | 9 | lowhigh = cell2mat(get(handles.Range,'Value')); 10 | if length(handles.ImagePanel)==1 11 | DisplayImage(handles.ImagePanel,handles.data,lowhigh); 12 | return; 13 | end 14 | 15 | [ny,nx,nz] = size(handles.data); 16 | point = get(handles.Point,'Value'); 17 | [sx,sy,sz] = deal(point{:}); 18 | [sx,sy,sz] = deal(round(sx),round(sy),round(sz)); 19 | sy = ny-sy+1; 20 | 21 | data = DisplayData(handles.data,'x',sx); 22 | DisplayImage(handles.ImagePanel(1),data,lowhigh); 23 | set(handles.ImageLine(1,1),'XData',[sz sz]); 24 | set(handles.ImageLine(1,2),'YData',[sy sy]); 25 | set(handles.PointText(1),'String',num2str(sx)); 26 | 27 | data = DisplayData(handles.data,'y',sy); 28 | DisplayImage(handles.ImagePanel(2),data,lowhigh); 29 | set(handles.ImageLine(2,1),'XData',[sx sx]); 30 | set(handles.ImageLine(2,2),'YData',[sz sz]); 31 | set(handles.PointText(2),'String',num2str(sy)); 32 | 33 | data = DisplayData(handles.data,'z',sz); 34 | DisplayImage(handles.ImagePanel(3),data,lowhigh); 35 | set(handles.ImageLine(3,1),'XData',[sx sx]); 36 | set(handles.ImageLine(3,2),'YData',[sy sy]); 37 | set(handles.PointText(3),'String',num2str(sz)); 38 | 39 | 40 | % -------------------------------------------------------------------- 41 | function DisplayImage(h,data,range) 42 | 43 | set(h,'UserData',double(data)); 44 | nlev = size(colormap,1); 45 | if diff(range) 46 | data = 1+(nlev-1)*(data-range(1))/(range(2)-range(1)); 47 | end 48 | set(h,'CData',data); 49 | 50 | 51 | % -------------------------------------------------------------------- 52 | function data = DisplayData(data,type,indx) 53 | 54 | switch type 55 | case 'x' 56 | data = permute(data(:,indx,:),[1,3,2]); 57 | case 'y' 58 | data = permute(data(indx,:,:),[3,2,1]); 59 | case 'z' 60 | data = data(:,:,indx); 61 | end 62 | -------------------------------------------------------------------------------- /graphics/hotmetal.m: -------------------------------------------------------------------------------- 1 | function c = hotmetal(m) 2 | 3 | %HOTMETAL a better hot metal color map. 4 | % 5 | % map = metal(num_colors) 6 | % 7 | % HOTMETAL(M) returns an M-by-3 matrix containing a "hot" colormap. 8 | % HOTMETAL, by itself, is the same length as the current colormap. 9 | % 10 | % For example, to reset the colormap of the current figure: 11 | % 12 | % colormap(hotmetal) 13 | % 14 | % See also HSV, GRAY, PINK, HOT, COOL, BONE, COPPER, FLAG, 15 | % COLORMAP, RGBPLOT, SPECTRAL. 16 | 17 | % $Id: metal.m,v 1.2 1997/10/20 18:23:20 greg Rel $ 18 | % $Name: emma_v0_9_5 $ 19 | 20 | % Copyright (c) 1984-92 by The MathWorks, Inc. 21 | % metal version made by Mark Wolforth, MBIC, MNI (c) 1993 22 | 23 | if nargin<1, m = size(get(gcf,'colormap'),1); end 24 | 25 | base = [ 0.000000 0.000000 0.000000 26 | 0.100000 0.000000 0.000000 27 | 0.200000 0.000000 0.000000 28 | 0.300000 0.000000 0.000000 29 | 0.400000 0.000000 0.000000 30 | 0.500000 0.000000 0.000000 31 | 0.600000 0.100000 0.000000 32 | 0.700000 0.200000 0.000000 33 | 0.800000 0.300000 0.000000 34 | 0.900000 0.400000 0.000000 35 | 1.000000 0.500000 0.000000 36 | 1.000000 0.600000 0.100000 37 | 1.000000 0.700000 0.200000 38 | 1.000000 0.800000 0.300000 39 | 1.000000 0.900000 0.400000 40 | 1.000000 1.000000 0.500000 41 | 1.000000 1.000000 0.600000 42 | 1.000000 1.000000 0.700000 43 | 1.000000 1.000000 0.800000 44 | 1.000000 1.000000 0.900000 45 | 1.000000 1.000000 1.000000 46 | ]; 47 | 48 | % interpolate colormap 49 | n = length(base); 50 | t = linspace(1,n,m); 51 | n = 1:n; 52 | r = interp1(n,base(:,1),t,'linear'); 53 | g = interp1(n,base(:,2),t,'linear'); 54 | b = interp1(n,base(:,3),t,'linear'); 55 | 56 | % compose colormap 57 | c = [r(:),g(:),b(:)]; 58 | -------------------------------------------------------------------------------- /graphics/combcolor.m: -------------------------------------------------------------------------------- 1 | function c = combcolor(m) 2 | 3 | if nargin<1, m = size(get(gcf,'colormap'),1); end 4 | 5 | base = 4*[0:61]; 6 | base = base(ones(1,3),:).'; 7 | 8 | base = [ base 9 | 0 13 50 10 | 1 17 61 11 | 2 25 76 12 | 3 32 94 13 | 4 39 104 14 | 4 46 116 15 | 5 51 125 16 | 6 65 150 17 | 7 75 174 18 | 10 87 199 19 | 11 98 223 20 | 11 104 237 21 | 14 116 254 22 | 16 127 250 23 | 18 138 246 24 | 20 150 241 25 | 23 163 230 26 | 27 175 223 27 | 29 186 211 28 | 31 191 195 29 | 33 203 178 30 | 39 211 155 31 | 43 218 131 32 | 47 221 114 33 | 51 224 97 34 | 56 227 82 35 | 59 231 74 36 | 62 235 66 37 | 67 239 61 38 | 75 243 59 39 | 80 246 57 40 | 84 250 55 41 | 89 253 54 42 | 93 250 53 43 | 101 246 53 44 | 109 242 52 45 | 116 238 49 46 | 123 236 47 47 | 130 233 46 48 | 138 229 45 49 | 148 223 44 50 | 154 218 43 51 | 164 214 41 52 | 174 209 40 53 | 184 199 40 54 | 192 190 38 55 | 200 179 37 56 | 211 167 35 57 | 222 158 33 58 | 233 147 32 59 | 238 138 30 60 | 240 129 28 61 | 244 119 26 62 | 249 108 24 63 | 253 99 22 64 | 250 88 20 65 | 247 76 18 66 | 242 67 16 67 | 235 59 14 68 | 227 49 12 69 | 216 44 10 70 | 202 40 9 71 | 189 30 10 72 | 88 12 4 73 | ]/255; 74 | 75 | % interpolate colormap 76 | n = length(base); 77 | t = linspace(1,n,m); 78 | n = 1:n; 79 | r = interp1(n,base(:,1),t,'linear'); 80 | g = interp1(n,base(:,2),t,'linear'); 81 | b = interp1(n,base(:,3),t,'linear'); 82 | 83 | % compose colormap 84 | c = [r(:),g(:),b(:)]; 85 | -------------------------------------------------------------------------------- /Parallel_Rebinning_CB_Flat.m: -------------------------------------------------------------------------------- 1 | function PProj = Parallel_Rebinning_CB_Flat(Proj,ScanGeom) 2 | % Rebin the spiral cone-beam projections into cone-parallel geometry 3 | %ScanGeom = struct( 'ScDet', [SO DO YL ZL DecWidth DecHeigh YLC ZLC h], ... 4 | % 'Proj', [BetaS BetaE ViewN N_2pi], ... 5 | % 'Obj', [ObjR XN YN ZN XC YC ZC]... 6 | % 'Rec', [delta HSCoef k1]); 7 | 8 | SO = ScanGeom.ScDet(1); 9 | DO = ScanGeom.ScDet(2); 10 | YL = ScanGeom.ScDet(3); 11 | ZL = ScanGeom.ScDet(4); 12 | dYL= ScanGeom.ScDet(5)/YL; 13 | YLC= ScanGeom.ScDet(7); 14 | 15 | ViewN = ScanGeom.Proj(3); 16 | DeltaFai= (ScanGeom.Proj(2)-ScanGeom.Proj(1))/(ViewN-1); 17 | DeltaTheta = DeltaFai; 18 | DeltaT = dYL; 19 | 20 | PProj = zeros(ViewN,YL,ZL); 21 | for i=1:ViewN 22 | Theta=(i-1)*DeltaTheta; % the view for the parallel projection 23 | for j=1:YL 24 | t = (j-YLC)*DeltaT; % the distance from origin to ray for parallel beam 25 | Beta = asin(t/(SO)); % the fan_angle for cone_beam projection 26 | Fai = Theta+Beta; % the view for cone_beam projecton 27 | a = (SO+DO)*t/sqrt(SO^2-t^2);% the position of this ray on the flat detector 28 | FaiIndex = (Fai/DeltaFai)+1;% Matlab index begins with 1 instead of 0 29 | UIndex = (a/dYL)+YLC; 30 | FI = ceil(FaiIndex); 31 | UI = ceil(UIndex); 32 | coeXB = FI-FaiIndex; 33 | coeXU = 1-coeXB; 34 | coeYB = UI-UIndex; 35 | coeYU = 1-coeYB; 36 | if (FI<=1) 37 | IndexXU = 1; 38 | IndexXB = 1; 39 | elseif(FI> ViewN) 40 | IndexXU = ViewN; 41 | IndexXB = ViewN; 42 | else 43 | IndexXU = FI; 44 | IndexXB = FI-1; 45 | end; 46 | if (UI<=1) 47 | IndexYU = 1; 48 | IndexYB = 1; 49 | elseif(UI>YL) 50 | IndexYU = YL; 51 | IndexYB = YL; 52 | else 53 | IndexYU=UI; 54 | IndexYB=UI-1; 55 | end; 56 | PProj(i,j,:)=coeXB*coeYB*Proj(IndexXB,IndexYB,:)+coeXU*coeYB*Proj(IndexXU,IndexYB,:)+coeXB*coeYU*Proj(IndexXB,IndexYU,:)+coeXU*coeYU*Proj(IndexXU,IndexYU,:); 57 | end;% end for j 58 | end;% end for i=:ViewN 59 | 60 | -------------------------------------------------------------------------------- /Parallel_Rebinning_CB_Curve.m: -------------------------------------------------------------------------------- 1 | function PProj = Parallel_Rebinning_CB_Curve(Proj,ScanGeom) 2 | % Rebin the spiral cone-beam projections into cone-parallel geometry 3 | %ScanGeom = struct( 'ScDet', [SO DO YL ZL DecAngle DecHeigh YLC ZLC h], ... 4 | % 'Proj', [BetaS BetaE ViewN N_2pi], ... 5 | % 'Obj', [ObjR XN YN ZN XC YC ZC]... 6 | % 'Rec', [delta HSCoef k1]); 7 | 8 | SO = ScanGeom.ScDet(1); 9 | DO = ScanGeom.ScDet(2); 10 | YL = ScanGeom.ScDet(3); 11 | ZL = ScanGeom.ScDet(4); 12 | dYA= ScanGeom.ScDet(5)/YL; 13 | YLC= ScanGeom.ScDet(7); 14 | 15 | ViewN = ScanGeom.Proj(3); 16 | DeltaFai= (ScanGeom.Proj(2)-ScanGeom.Proj(1))/(ViewN-1); 17 | DeltaTheta = DeltaFai; 18 | DeltaT = tan(ScanGeom.ScDet(5)*0.5)*(SO+DO)*2/YL; 19 | 20 | PProj = zeros(ViewN,YL,ZL); 21 | for i=1:ViewN 22 | Theta=(i-1)*DeltaTheta; % the view for the parallel projection 23 | for j=1:YL 24 | t = (j-YLC)*DeltaT; % the distance from origin to ray for parallel beam 25 | Beta = asin(t/(SO)); % the fan_angle for cone_beam projection 26 | Fai = Theta+Beta; % the view for cone_beam projecton 27 | a = atan(t/sqrt(SO^2-t^2)); % the position of this ray on the flat detector 28 | FaiIndex = (Fai/DeltaFai)+1;% Matlab index begins with 1 instead of 0 29 | UIndex = (a/dYA)+YLC; 30 | FI = ceil(FaiIndex); 31 | UI = ceil(UIndex); 32 | coeXB = FI-FaiIndex; 33 | coeXU = 1-coeXB; 34 | coeYB = UI-UIndex; 35 | coeYU = 1-coeYB; 36 | if (FI<=1) 37 | IndexXU = 1; 38 | IndexXB = 1; 39 | elseif(FI> ViewN) 40 | IndexXU = ViewN; 41 | IndexXB = ViewN; 42 | else 43 | IndexXU = FI; 44 | IndexXB = FI-1; 45 | end; 46 | if (UI<=1) 47 | IndexYU = 1; 48 | IndexYB = 1; 49 | elseif(UI>YL) 50 | IndexYU = YL; 51 | IndexYB = YL; 52 | else 53 | IndexYU=UI; 54 | IndexYB=UI-1; 55 | end; 56 | PProj(i,j,:)=coeXB*coeYB*Proj(IndexXB,IndexYB,:)+coeXU*coeYB*Proj(IndexXU,IndexYB,:)+coeXB*coeYU*Proj(IndexXB,IndexYU,:)+coeXU*coeYU*Proj(IndexXU,IndexYU,:); 57 | end;% end for j 58 | end;% end for i=:ViewN 59 | 60 | -------------------------------------------------------------------------------- /graphics/private/VRMLpg.m: -------------------------------------------------------------------------------- 1 | function VRMLpg(fid,xlabels, xstart, xfinish, xscale, ylabels, ystart, yfinish, yscale, labelSize) 2 | % 3 | % Function to plot a grid of lines in VRML 2.0 format 4 | % 5 | % Copyright Craig Sayers and WHOI 1996. 6 | % 7 | 8 | xdirn = (xfinish-xstart)/norm(xfinish-xstart); 9 | ydirn = (yfinish-ystart)/norm(yfinish-ystart); 10 | 11 | fprintf(fid,'Shape\n'); 12 | fprintf(fid,'{'); 13 | fprintf(fid,'geometry IndexedLineSet'); 14 | fprintf(fid,'{'); 15 | fprintf(fid,'colorPerVertex FALSE '); 16 | fprintf(fid,'coord Coordinate'); 17 | fprintf(fid,'{'); 18 | fprintf(fid,'point\n'); 19 | fprintf(fid,'['); 20 | 21 | % Begin by drawing lines parallel to the y axis 22 | for x=xlabels(1):xlabels(2):xlabels(3) 23 | a = ystart + (x-xlabels(1))*xscale * xdirn; 24 | b = yfinish + (x-xlabels(1))*xscale * xdirn; 25 | fprintf(fid,'%g %g %g,', a(1),a(2),a(3)); 26 | fprintf(fid,'%g %g %g,\n', b(1),b(2),b(3)); 27 | end 28 | if x ~=xlabels(3) 29 | x = xlabels(3); 30 | a = ystart + (x-xlabels(1))*xscale * xdirn; 31 | b = yfinish + (x-xlabels(1))*xscale * xdirn; 32 | fprintf(fid,'%g %g %g,', a(1),a(2),a(3)); 33 | fprintf(fid,'%g %g %g,\n', b(1),b(2),b(3)); 34 | end 35 | 36 | % Now draw lines parallel to the x axis 37 | for y=ylabels(1):ylabels(2):ylabels(3) 38 | a = xstart + (y-ylabels(1))*yscale * ydirn; 39 | b = xfinish + (y-ylabels(1))*yscale * ydirn; 40 | fprintf(fid,'%g %g %g,', a(1),a(2),a(3)); 41 | fprintf(fid,'%g %g %g,\n', b(1),b(2),b(3)); 42 | end 43 | if y ~= ylabels(3) 44 | y = ylabels(3); 45 | a = xstart + (y-ylabels(1))*yscale * ydirn; 46 | b = xfinish + (y-ylabels(1))*yscale * ydirn; 47 | fprintf(fid,'%g %g %g,', a(1),a(2),a(3)); 48 | fprintf(fid,'%g %g %g,\n', b(1),b(2),b(3)); 49 | end 50 | fprintf(fid,']'); 51 | fprintf(fid,'}'); 52 | fprintf(fid,'coordIndex\n'); 53 | fprintf(fid,'['); 54 | 55 | % Index lines parallel to the y axis 56 | count=0; 57 | for x=xlabels(1):xlabels(2):xlabels(3) 58 | fprintf(fid,'%g %g -1\n',count,count+1); 59 | count = count+2; 60 | end 61 | if x ~=xlabels(3) 62 | fprintf(fid,'%g %g -1\n',count,count+1); 63 | count = count+2; 64 | end 65 | % Index lines parallel to the x axis 66 | for y=ylabels(1):ylabels(2):ylabels(3) 67 | fprintf(fid,'%g %g -1\n',count,count+1); 68 | count = count+2; 69 | end 70 | if y ~= ylabels(3) 71 | fprintf(fid,'%g %g -1\n',count,count+1); 72 | count = count+2; 73 | end 74 | 75 | fprintf(fid,']'); 76 | fprintf(fid,'color Color { color [ 1.0 0.0 0.0]}'); 77 | fprintf(fid,'colorIndex'); 78 | fprintf(fid,'['); 79 | 80 | % Color lines parallel to the y axis 81 | for x=xlabels(1):xlabels(2):xlabels(3) 82 | fprintf(fid,'0\n',count); 83 | end 84 | if x ~=xlabels(3) 85 | fprintf(fid,'0\n',count); 86 | end 87 | 88 | % Color lines parallel to the x axis 89 | for y=ylabels(1):ylabels(2):ylabels(3) 90 | fprintf(fid,'0\n',count); 91 | end 92 | if y ~= ylabels(3) 93 | fprintf(fid,'0\n',count); 94 | end 95 | 96 | fprintf(fid,']'); 97 | fprintf(fid,'}'); 98 | fprintf(fid,'}\n'); 99 | -------------------------------------------------------------------------------- /graphics/gecolor.m: -------------------------------------------------------------------------------- 1 | function c = gecolor(m) 2 | 3 | %GECOLOR - Color map used by GE software. 4 | % 5 | % map = gecolor(num_colors) 6 | % 7 | % GECOLOR(M) returns an M-by-3 matrix containing a GE colormap. 8 | % GECOLOR, by itself, is the same length as the current colormap. 9 | % 10 | % For example, to reset the colormap of the current figure: 11 | % 12 | % colormap(gecolor) 13 | % 14 | % See also HSV, GRAY, PINK, HOT, COOL, BONE, COPPER, FLAG, 15 | % COLORMAP, RGBPLOT. 16 | 17 | % $Id: gecolor.m,v 1.2 1997/10/20 18:23:23 greg Rel $ 18 | % $Name: emma_v0_9_5 $ 19 | 20 | % Copyright (c) 1984-92 by The MathWorks, Inc. 21 | % gecolor version made by Mark Wolforth, McBIC, MNI (c) 1993 22 | 23 | if nargin<1, m = size(get(gcf,'colormap'),1); end 24 | 25 | base = [ 0 0 0 26 | 0 0.0321 0.0314 27 | 0 0.0643 0.0627 28 | 0 0.0964 0.0941 29 | 0 0.1325 0.1255 30 | 0 0.1647 0.1569 31 | 0 0.1968 0.1882 32 | 0 0.2289 0.2196 33 | 0 0.2610 0.2510 34 | 0 0.2932 0.2824 35 | 0 0.3253 0.3137 36 | 0 0.3574 0.3451 37 | 0 0.3936 0.3765 38 | 0 0.4257 0.4078 39 | 0 0.4578 0.4392 40 | 0 0.4900 0.4706 41 | 0.0078 0.5060 0.5020 42 | 0.0392 0.4739 0.5294 43 | 0.0706 0.4418 0.5608 44 | 0.1020 0.4096 0.5922 45 | 0.1333 0.3815 0.6235 46 | 0.1647 0.3494 0.6549 47 | 0.1922 0.3173 0.6863 48 | 0.2235 0.2851 0.7176 49 | 0.2549 0.2530 0.7490 50 | 0.2863 0.2209 0.7804 51 | 0.3176 0.1888 0.8118 52 | 0.3490 0.1566 0.8431 53 | 0.3804 0.1285 0.8745 54 | 0.4118 0.0964 0.9059 55 | 0.4431 0.0643 0.9373 56 | 0.4745 0.0321 0.9686 57 | 0.5020 0 1.0000 58 | 0.5333 0.0321 0.9373 59 | 0.5647 0.0643 0.8745 60 | 0.5961 0.0964 0.8118 61 | 0.6275 0.1285 0.7490 62 | 0.6588 0.1606 0.6863 63 | 0.6902 0.1928 0.6235 64 | 0.7216 0.2249 0.5608 65 | 0.7529 0.2570 0.5020 66 | 0.7843 0.2892 0.4392 67 | 0.8157 0.3213 0.3765 68 | 0.8431 0.3534 0.3137 69 | 0.8745 0.3855 0.2510 70 | 0.9059 0.4177 0.1882 71 | 0.9373 0.4498 0.1255 72 | 0.9686 0.4819 0.0627 73 | 1.0000 0.5181 0 74 | 1.0000 0.5502 0.0627 75 | 1.0000 0.5823 0.1255 76 | 1.0000 0.6145 0.1922 77 | 1.0000 0.6466 0.2549 78 | 1.0000 0.6787 0.3176 79 | 1.0000 0.7108 0.3804 80 | 1.0000 0.7430 0.4431 81 | 1.0000 0.7751 0.5098 82 | 1.0000 0.8072 0.5725 83 | 1.0000 0.8394 0.6353 84 | 1.0000 0.8715 0.6980 85 | 1.0000 0.9036 0.7608 86 | 1.0000 0.9357 0.8235 87 | 1.0000 0.9679 0.8902 88 | 1.0000 1.0000 0.9529 89 | ]; 90 | 91 | % interpolate colormap 92 | n = length(base); 93 | t = linspace(1,n,m); 94 | n = 1:n; 95 | r = interp1(n,base(:,1),t,'linear'); 96 | g = interp1(n,base(:,2),t,'linear'); 97 | b = interp1(n,base(:,3),t,'linear'); 98 | 99 | % compose colormap 100 | c = [r(:),g(:),b(:)]; 101 | -------------------------------------------------------------------------------- /graphics/gecolour.m: -------------------------------------------------------------------------------- 1 | function c = gecolour(m) 2 | 3 | %GECOLOUR - Colour map used by GE software. 4 | % 5 | % map = gecolour(num_colors) 6 | % 7 | % GECOLOUR(M) returns an M-by-3 matrix containing a GE colormap. 8 | % GECOLOUR, by itself, is the same length as the current colormap. 9 | % 10 | % For example, to reset the colormap of the current figure: 11 | % 12 | % colormap(gecolour) 13 | % 14 | % See also HSV, GRAY, PINK, HOT, COOL, BONE, COPPER, FLAG, 15 | % COLORMAP, RGBPLOT. 16 | 17 | % $Id: gecolour.m,v 1.2 1997/10/20 18:23:23 greg Rel $ 18 | % $Name: emma_v0_9_5 $ 19 | 20 | % Copyright (c) 1984-92 by The MathWorks, Inc. 21 | % gecolour version made by Mark Wolforth, McBIC, MNI (c) 1993 22 | 23 | if nargin < 1, m = size(get(gcf,'colormap'),1); end 24 | 25 | base = [ 0 0 0 26 | 0 0.0321 0.0314 27 | 0 0.0643 0.0627 28 | 0 0.0964 0.0941 29 | 0 0.1325 0.1255 30 | 0 0.1647 0.1569 31 | 0 0.1968 0.1882 32 | 0 0.2289 0.2196 33 | 0 0.2610 0.2510 34 | 0 0.2932 0.2824 35 | 0 0.3253 0.3137 36 | 0 0.3574 0.3451 37 | 0 0.3936 0.3765 38 | 0 0.4257 0.4078 39 | 0 0.4578 0.4392 40 | 0 0.4900 0.4706 41 | 0.0078 0.5060 0.5020 42 | 0.0392 0.4739 0.5294 43 | 0.0706 0.4418 0.5608 44 | 0.1020 0.4096 0.5922 45 | 0.1333 0.3815 0.6235 46 | 0.1647 0.3494 0.6549 47 | 0.1922 0.3173 0.6863 48 | 0.2235 0.2851 0.7176 49 | 0.2549 0.2530 0.7490 50 | 0.2863 0.2209 0.7804 51 | 0.3176 0.1888 0.8118 52 | 0.3490 0.1566 0.8431 53 | 0.3804 0.1285 0.8745 54 | 0.4118 0.0964 0.9059 55 | 0.4431 0.0643 0.9373 56 | 0.4745 0.0321 0.9686 57 | 0.5020 0 1.0000 58 | 0.5333 0.0321 0.9373 59 | 0.5647 0.0643 0.8745 60 | 0.5961 0.0964 0.8118 61 | 0.6275 0.1285 0.7490 62 | 0.6588 0.1606 0.6863 63 | 0.6902 0.1928 0.6235 64 | 0.7216 0.2249 0.5608 65 | 0.7529 0.2570 0.5020 66 | 0.7843 0.2892 0.4392 67 | 0.8157 0.3213 0.3765 68 | 0.8431 0.3534 0.3137 69 | 0.8745 0.3855 0.2510 70 | 0.9059 0.4177 0.1882 71 | 0.9373 0.4498 0.1255 72 | 0.9686 0.4819 0.0627 73 | 1.0000 0.5181 0 74 | 1.0000 0.5502 0.0627 75 | 1.0000 0.5823 0.1255 76 | 1.0000 0.6145 0.1922 77 | 1.0000 0.6466 0.2549 78 | 1.0000 0.6787 0.3176 79 | 1.0000 0.7108 0.3804 80 | 1.0000 0.7430 0.4431 81 | 1.0000 0.7751 0.5098 82 | 1.0000 0.8072 0.5725 83 | 1.0000 0.8394 0.6353 84 | 1.0000 0.8715 0.6980 85 | 1.0000 0.9036 0.7608 86 | 1.0000 0.9357 0.8235 87 | 1.0000 0.9679 0.8902 88 | 1.0000 1.0000 0.9529 89 | ]; 90 | 91 | % interpolate colormap 92 | n = length(base); 93 | t = linspace(1,n,m); 94 | n = 1:n; 95 | r = interp1(n,base(:,1),t,'linear'); 96 | g = interp1(n,base(:,2),t,'linear'); 97 | b = interp1(n,base(:,3),t,'linear'); 98 | 99 | % compose colormap 100 | c = [r(:),g(:),b(:)]; 101 | -------------------------------------------------------------------------------- /graphics/imdisp2.m: -------------------------------------------------------------------------------- 1 | function h = imdisp(varargin) 2 | 3 | % h = imdisp([subplot], [xx], [yy], zz, [scale], [title]) 4 | % show matrix zz as an image 5 | % options: choose subplot, show proper (x,y) axes, scale factor, title 6 | 7 | % Copyright (C) 2000-2003 Shiying Zhao 8 | % Copyright (C) 2004 CT/Micro-CT Laboratory 9 | % Department of Radiology, University of Iowa 10 | 11 | DISP_COLORMAP = get(gcf,'colormap'); 12 | if length(DISP_COLORMAP)<256, DISP_COLORMAP = gray(256); end 13 | 14 | scale = 1; 15 | titlestr = ''; 16 | axisstr = 'image'; 17 | xx = []; 18 | yy = []; 19 | isxy = 0; 20 | ii = 1; 21 | 22 | % subplot 23 | if length(varargin{1})==1 24 | if varargin{1}>111 25 | subplot(varargin{1}) 26 | end 27 | ii = ii+1; 28 | end 29 | 30 | % xx, yy 31 | if ii>nargin, help(mfilename), error args; end 32 | if ndims(varargin{ii})==2 & min(size(varargin{ii}))==1 33 | xx = varargin{ii}; 34 | ii = ii+1; 35 | if ii>nargin, help(mfilename), error 'need both xx,yy'; end 36 | if min(size(varargin{ii}))~=1, error 'both xx,yy need to be 1D'; end 37 | yy = varargin{ii}; 38 | ii = ii+1; 39 | isxy = 1; 40 | end 41 | 42 | % zz 43 | if ii<=nargin 44 | zz = double(varargin{ii}); 45 | ii = ii+1; 46 | else 47 | error 'no image?'; 48 | end 49 | 50 | % title, scale 51 | while ii<=nargin 52 | arg = varargin{ii}; 53 | if ischar(arg) 54 | if strcmp(arg,'equal') 55 | axisstr = arg; 56 | elseif strcmp(arg,'normal') 57 | ydirstr = arg; 58 | else 59 | titlestr = arg; 60 | end 61 | elseif isa(arg,'double') 62 | scale = arg; 63 | %if max(size(arg))~=1, error 'nonscalar scale?'; end 64 | else 65 | error 'unknown arg'; 66 | end 67 | ii = ii+1; 68 | end 69 | 70 | if issparse(zz), zz = full(zz); end 71 | if any(size(zz)==1), zz = squeeze(zz); end 72 | 73 | if length(scale)==1 74 | zmin = min(zz(:)); 75 | zmax = max(zz(:)); 76 | else 77 | zmin = scale(1); 78 | zmax = scale(2); 79 | if length(scale)>2 80 | scale = scale(3); 81 | else 82 | scale = 1; 83 | end 84 | end 85 | 86 | if scale==0 87 | zmin = 0; 88 | scale = 1; 89 | elseif scale<0 90 | zmin = 0; 91 | scale = -scale; 92 | end 93 | if (zmax==zmin) 94 | fprintf('Uniform image %g [',zmin) 95 | fprintf(' %g',size(zz)) 96 | fprintf(' ]\n') 97 | return 98 | end 99 | 100 | colormap(DISP_COLORMAP) 101 | n = size(colormap,1); 102 | zz = (n-1)*(zz-zmin)/(zmax-zmin); 103 | zz = 1+round(scale*zz); 104 | zz = min(zz,n); 105 | zz = max(zz,1); 106 | 107 | if ndims(zz)<3 108 | %zz = zz'; 109 | if isxy 110 | hh = image(xx,yy,zz); 111 | else 112 | hh = image(zz); 113 | end 114 | else 115 | hh = image(Montage(zz)); 116 | end 117 | 118 | set(gca,'TickDir','out') 119 | if exist('ydirstr','var'), set(gca,'YDir',ydirstr); end 120 | 121 | if nargout>0, h = hh; end 122 | 123 | axis(axisstr) 124 | xlabel(['Range: [' num2str(zmin) ', ' num2str(zmax) ']']) 125 | 126 | if ~isempty(titlestr), title(titlestr); end 127 | 128 | 129 | function xo = Montage(xi) 130 | 131 | % Arrange 3d image slices as a 2d rectangular montage. 132 | 133 | if ndims(xi)>3, warning('4d not done'); end 134 | 135 | [nx,order] = sort(size(xi)); 136 | %xi = permute(xi,[order(2:3),order(1)]); 137 | if order(1)~=3, xi = xi(end:-1:1,:,:); end 138 | 139 | % add white border 140 | %xi(:,end+1,:) = 256; 141 | %xi(end+1,:,:) = 256; 142 | 143 | [nx,ny,nz] = size(xi); 144 | if nx0), 63 | Z = k; 64 | R = 1; 65 | return; 66 | end; 67 | end 68 | 69 | %% check if this is element name or known compound 70 | X = PhysProps(Name); 71 | if (~isnan(X{1})), Name = X{3}; end 72 | 73 | %% check if this is a compound 74 | s1 = regexprep(Name,'(\D)([A-Z])', '$11$2'); % letter before upper case -> separate with '1' 75 | s1 = regexprep(s1 ,'(\D)([A-Z])', '$11$2'); % for some reason have to do it twice 76 | if (isempty(regexp(s1(length(s1)), '\d','once'))), s1 = [s1,'1']; end % string does not end with digit -> add '1' 77 | s2 = regexp(s1,'([A-Z][a-z]*|\d+)', 'match'); 78 | El = s2(1:2:end); 79 | z = zeros(1, length(El)); 80 | for i=1:length(El) 81 | j = find(strcmp(El{i}, ElName),1); 82 | if (~isempty(j)), z(i) = j; end 83 | end 84 | if (mod(length(s2),2)==0) && (all(z>0)) 85 | Z = z; 86 | N = str2num(char(s2(2:2:end)))'; 87 | R = AMass(Z).*N; 88 | R = R/sum(R(:)); % normalize ratios so they add-up to 1 89 | R = R(:); Z = Z(:); 90 | return; 91 | end 92 | 93 | %% check if this is a mixture of elements and/or compounds 94 | s1 = regexprep(Name,')|(', ' '); % replace parenthesis with spaces 95 | s2 = regexp([' ',s1],'\s([\.\+\-]|\w)+', 'tokens'); 96 | s3 = [s2{:}]; % convert from array of arrays of strints to array of strings 97 | Mt = s3(1:2:end); 98 | Rt = str2num(char(s3(2:2:end))); 99 | if (isempty(Rt)), return; end 100 | for j = 1:length(Mt) 101 | [ZZ, RR] = ParseChemicalFormula(Mt{j}); 102 | if (isempty(ZZ) || isempty(Rt(j))), return; end 103 | Z = [Z; ZZ]; 104 | R = [R; RR*Rt(j)]; 105 | end 106 | 107 | %% make sure all Z's are unique 108 | [Z idx] = sort(Z); 109 | R = R(idx); 110 | while (any(diff(Z)==0)) 111 | i = find(diff(Z)==0, 1); 112 | idx = find(Z==Z(i)); 113 | R(i) = sum(R(idx)); 114 | idx(1) = []; 115 | Z(idx) = []; 116 | R(idx) = []; 117 | end 118 | 119 | R = R/sum(R(:)); 120 | R = R(:); Z = Z(:); 121 | -------------------------------------------------------------------------------- /graphics/rainbow.m: -------------------------------------------------------------------------------- 1 | function c = rainbow(m) 2 | 3 | if nargin<1, m = size(get(gcf,'colormap'),1); end 4 | 5 | base = [ 0 0 0 6 | 8 0 8 7 | 14 0 14 8 | 24 0 23 9 | 34 0 33 10 | 44 0 43 11 | 54 0 53 12 | 64 0 63 13 | 74 0 72 14 | 85 0 83 15 | 95 0 93 16 | 97 0 102 17 | 92 0 112 18 | 87 0 122 19 | 82 0 132 20 | 77 0 142 21 | 73 0 151 22 | 68 0 161 23 | 63 0 171 24 | 58 0 181 25 | 53 0 191 26 | 49 0 200 27 | 44 0 202 28 | 39 0 205 29 | 34 0 208 30 | 29 0 211 31 | 25 0 212 32 | 19 6 215 33 | 15 15 218 34 | 9 22 221 35 | 5 29 223 36 | 1 38 226 37 | 0 45 229 38 | 0 53 232 39 | 0 61 234 40 | 0 68 236 41 | 0 76 239 42 | 0 84 242 43 | 0 92 245 44 | 0 99 247 45 | 0 107 250 46 | 0 115 253 47 | 0 122 252 48 | 0 130 246 49 | 0 138 240 50 | 0 145 233 51 | 0 153 227 52 | 0 161 221 53 | 0 168 215 54 | 0 176 209 55 | 0 184 203 56 | 0 191 197 57 | 0 199 191 58 | 0 202 184 59 | 0 206 178 60 | 0 210 172 61 | 0 213 166 62 | 0 217 160 63 | 0 220 154 64 | 0 224 148 65 | 0 227 142 66 | 0 231 135 67 | 0 234 129 68 | 0 238 123 69 | 0 241 117 70 | 0 245 111 71 | 0 249 103 72 | 0 253 95 73 | 0 255 91 74 | 0 255 87 75 | 0 255 80 76 | 0 255 74 77 | 0 255 68 78 | 1 255 62 79 | 13 255 56 80 | 25 255 50 81 | 38 255 43 82 | 50 255 38 83 | 62 255 31 84 | 74 255 25 85 | 87 255 19 86 | 99 255 13 87 | 111 255 7 88 | 123 255 1 89 | 136 255 0 90 | 148 255 0 91 | 160 255 0 92 | 172 255 0 93 | 184 255 0 94 | 197 255 0 95 | 209 255 0 96 | 221 255 0 97 | 233 255 0 98 | 246 255 0 99 | 255 252 0 100 | 255 244 0 101 | 255 237 0 102 | 255 229 0 103 | 255 221 0 104 | 255 214 0 105 | 255 206 0 106 | 255 198 0 107 | 255 191 0 108 | 255 183 0 109 | 255 175 0 110 | 255 168 0 111 | 255 160 0 112 | 255 152 0 113 | 255 145 0 114 | 255 137 0 115 | 255 129 0 116 | 255 121 0 117 | 255 114 0 118 | 255 106 0 119 | 255 98 0 120 | 255 91 0 121 | 255 83 0 122 | 255 75 0 123 | 255 68 0 124 | 255 60 0 125 | 255 52 0 126 | 255 45 0 127 | 255 37 0 128 | 255 29 0 129 | 255 22 0 130 | 255 14 0 131 | 255 5 0 132 | 255 0 0 133 | ]/255; 134 | 135 | % interpolate colormap 136 | n = length(base); 137 | t = linspace(1,n,m); 138 | n = 1:n; 139 | r = interp1(n,base(:,1),t,'linear'); 140 | g = interp1(n,base(:,2),t,'linear'); 141 | b = interp1(n,base(:,3),t,'linear'); 142 | 143 | % compose colormap 144 | c = [r(:),g(:),b(:)]; 145 | -------------------------------------------------------------------------------- /Helical_Rec_Flat.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This is to demonstrate the applicaiton of analytic cone-beam reconstrution with flat-plane detector. 3 | % The codes were developed by Huihua Kong and Hengyong Yu, Department of 4 | % Electrical and Computer Engineering, University of Massachusetts Lowell. 5 | % Email: hengyong-yu@ieee.org 6 | % Version 2, Dec. 21, 2015 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | clear all; 9 | close all; 10 | time = cputime; 11 | % Rebinning (Convert conebeam to parallel beam) 12 | % The following lines 13-23 are used to define the helical scanning geometry for a micro-CT 13 | SO = 10; % The distance from source to object (cm) 14 | DO = 5; % The distance from detector to object (cm) 15 | YL = 350; % Detector cell number along the horizontal direction of detector array 16 | YLC= (1+YL)*0.5; % Detector center along the horizontal direction of detector array 17 | ZL = 20; % Detector cell number along the vertical direction of detector array 18 | ZLC= (1+ZL)*0.5; % Detector center along the vertical direction of detector array 19 | DecWidth = 3.5; % Detector array width along the horizontal direction (cm) 20 | DecHeigh = 0.2; % Detector array height along the vertical direction (cm) 21 | N_Turn = 3; % The number of turns for the whole helical scan 22 | N_2pi = 360; % The projections/views number for each turn of scan 23 | h = 1; % Helical pitch related to detector height 24 | %The following line 25-28 are used to define the reconstruction paramters 25 | WtInd = 3; %1:Redundancy weighting; 2:2D weigthing; 3: 3D weighting 26 | k1 = 5; % The order to define the 3D weighting function 27 | delta = 60; % The range to define smoothness of 2D weigthing function 28 | HSCoef = 0.6; % This is used to define the half-scan range 29 | 30 | ObjR = 1.1; % Diameter of imaginh object 31 | SSO = 64; % Define the size of the reconstructed image 32 | XN = 2*SSO; 33 | YN = 2*SSO; 34 | ZN = 2*SSO; 35 | XC = (XN+1)*0.5; 36 | YC = (YN+1)*0.5; 37 | ZC = (ZN+1)*0.5; 38 | BetaS = -N_Turn*pi; 39 | BetaE = N_Turn*pi; 40 | ViewN = N_Turn*N_2pi+1; 41 | dYL = DecWidth/YL; 42 | dZL = DecHeigh/ZL; 43 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 44 | ScanGeom = struct( 'ScDet', [SO DO YL ZL DecWidth DecHeigh YLC ZLC h], ... 45 | 'Proj', [BetaS BetaE ViewN N_2pi], ... 46 | 'Obj', [ObjR XN YN ZN XC YC ZC], ... 47 | 'Rec', [delta HSCoef k1]); 48 | % Generating projections or load the projections 49 | disp('Generating the cone beam projections'); 50 | [ScPos Proj] = Conebeam_Flat_CreateProj_CB_Helical_Spectrum(ScanGeom); 51 | %load SpectralProjections; 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 53 | % Rebinning conebeam to parallel beam 54 | disp('Paralllel rebinning from the conebeam projections'); 55 | Proj = Parallel_Rebinning_CB_Flat(Proj,ScanGeom); 56 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 57 | %Preweighting the conebeam projections 58 | disp('PreWeighting the cone beam projection'); 59 | %for i=1:ViewN 60 | for j=1:YL 61 | t=(j-YLC)*dYL; 62 | for k=1:ZL 63 | b=(k-ZLC)*dZL; 64 | Proj(:,j,k) = Proj(:,j,k)*SO*SO/sqrt(SO^4+(SO*b)^2-(b*t)^2); 65 | end 66 | end 67 | %end 68 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 69 | %Perform Ramp filtering 70 | disp('Filtering the cone beam projection'); 71 | n = -YL:YL; 72 | hsl=-2./((pi^2)*(4*n.*n-1))/dYL; 73 | %plot(n,hsl); 74 | NN = 2^ceil(log(YL*3)/log(2)); 75 | HS = zeros(1,NN); 76 | HS(1:YL+1)= hsl(YL+1:2*YL+1); 77 | HS(end-YL+1:end)=hsl(1:YL); 78 | FtS = fft(HS); 79 | fpwd = zeros(size(Proj)); 80 | for i=1:ViewN 81 | for k=1:ZL 82 | FtP = fft(Proj(i,:,k),NN); 83 | tep = ifft(FtS.*FtP); 84 | fpwd(i,:,k) = real(tep(1:YL)); 85 | end 86 | end 87 | %save fpwd.mat fpwd; 88 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 89 | %Backproject the filtered data into the 3D space 90 | disp('BackProjection the filtered projection'); 91 | ctimage = zeros(XN,YN,ZN); 92 | switch(WtInd) 93 | case 1 %1/2 redundancy weigthing 94 | Parallel_FDK_Helical_NOWeighting(ScanGeom,fpwd,ctimage); 95 | save RecResNoW ctimage; 96 | case 2 % 2D weighting 97 | Parallel_FDK_Helical_2DWeighting(ScanGeom,fpwd,ctimage); 98 | save RecRes2DW ctimage; 99 | case 3 %3D weighting 100 | Parallel_FDK_Helical_3DWeighting(ScanGeom,fpwd,ctimage); 101 | save RecRes3DW ctimage; 102 | otherwise %1/2 redundancy weigthing 103 | Parallel_FDK_Helical_NOWeighting(ScanGeom,fpwd,ctimage); 104 | save RecResNoW ctimage; 105 | end; 106 | imdisp(ctimage) 107 | 108 | time =cputime-time 109 | 110 | 111 | -------------------------------------------------------------------------------- /Helical_Rec_Curve.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This is to demonstrate the applicaiton of analytic cone-beam reconstrution withe curved detector. 3 | % The codes were developed by Hengyong Yu, Department of Electrical and Computer Engineering, University of Massachusetts Lowell. 4 | % Email: hengyong-yu@ieee.org 5 | % Version 2, Dec. 23, 2015 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | clear all; 8 | close all; 9 | time = cputime; 10 | % Rebinning (Convert conebeam to parallel beam) 11 | % The following lines 13-23 are used to define the helical scanning geometry for a micro-CT 12 | SO = 10; % The distance from source to object (cm) 13 | DO = 5; % The distance from detector to object center(cm) 14 | YL = 350; % Detector cell number along the horizontal direction of detector array 15 | YLC= (1+YL)*0.5; % Detector center along the horizontal direction of detector array 16 | ZL = 20; % Detector cell number along the vertical direction of detector array 17 | ZLC= (1+ZL)*0.5; % Detector center along the vertical direction of detector array 18 | DecAngle = 0.232; % Detector array beam angle along the horizontal direction (rad) 19 | DecHeigh = 0.2; % Detector array height along the vertical direction (cm) 20 | N_Turn = 3; % The number of turns for the whole helical scan 21 | N_2pi = 360; % The projections/views number for each turn of scan 22 | h = 1; % Helical pitch related to detector height 23 | %The following line 25-28 are used to define the reconstruction paramters 24 | WtInd = 3; %1:Redundancy weighting; 2:2D weigthing; 3: 3D weighting 25 | k1 = 5; % The order to define the 3D weighting function 26 | delta = 60; % The range to define smoothness of 2D weigthing function 27 | HSCoef = 0.6; % This is used to define the half-scan range 28 | 29 | ObjR = 1.1; % Diameter of imaginh object 30 | SSO = 64; % Define the size of the reconstructed image 31 | XN = 2*SSO; 32 | YN = 2*SSO; 33 | ZN = 2*SSO; 34 | XC = (XN+1)*0.5; 35 | YC = (YN+1)*0.5; 36 | ZC = (ZN+1)*0.5; 37 | BetaS = -N_Turn*pi; 38 | BetaE = N_Turn*pi; 39 | ViewN = N_Turn*N_2pi+1; 40 | 41 | DecWidth = tan(DecAngle*0.5)*(SO+DO)*2; 42 | dYL = DecWidth/YL; 43 | dZL = DecHeigh/ZL; 44 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 45 | ScanGeom = struct( 'ScDet', [SO DO YL ZL DecAngle DecHeigh YLC ZLC h], ... 46 | 'Proj', [BetaS BetaE ViewN N_2pi], ... 47 | 'Obj', [ObjR XN YN ZN XC YC ZC], ... 48 | 'Rec', [delta HSCoef k1]); 49 | % Generating projections or load the projections 50 | disp('Generating the cone beam projections'); 51 | [ScPos Proj] = Conebeam_Curve_CreateProj_CB_Helical_Spectrum(ScanGeom); 52 | %load SpectralProjections; 53 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 54 | % Rebinning conebeam to parallel beam 55 | disp('Paralllel rebinning from the conebeam projections'); 56 | Proj = Parallel_Rebinning_CB_Curve(Proj,ScanGeom); 57 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 58 | %Preweighting the conebeam projections 59 | disp('PreWeighting the cone beam projection'); 60 | %for i=1:ViewN 61 | for j=1:YL 62 | t=(j-YLC)*dYL; 63 | for k=1:ZL 64 | b=(k-ZLC)*dZL; 65 | Proj(:,j,k) = Proj(:,j,k)*SO*SO/sqrt(SO^4+(SO*b)^2-(b*t)^2); 66 | end 67 | end 68 | %end 69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 70 | %Perform Ramp filtering 71 | disp('Filtering the cone beam projection'); 72 | n = -YL:YL; 73 | hsl=-2./((pi^2)*(4*n.*n-1))/dYL; 74 | %plot(n,hsl); 75 | NN = 2^ceil(log(YL*3)/log(2)); 76 | HS = zeros(1,NN); 77 | HS(1:YL+1)= hsl(YL+1:2*YL+1); 78 | HS(end-YL+1:end)=hsl(1:YL); 79 | FtS = fft(HS); 80 | fpwd = zeros(size(Proj)); 81 | for i=1:ViewN 82 | for k=1:ZL 83 | FtP = fft(Proj(i,:,k),NN); 84 | tep = ifft(FtS.*FtP); 85 | fpwd(i,:,k) = real(tep(1:YL)); 86 | end 87 | end 88 | %save fpwd.mat fpwd; 89 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 90 | %Backproject the filtered data into the 3D space 91 | ScanGeom.ScDet(5) = DecWidth; 92 | disp('BackProjection the filtered projection'); 93 | ctimage = zeros(XN,YN,ZN); 94 | switch(WtInd) 95 | case 1 %1/2 redundancy weigthing 96 | Parallel_FDK_Helical_NOWeighting(ScanGeom,fpwd,ctimage); 97 | save RecResNoW ctimage; 98 | case 2 % 2D weighting 99 | Parallel_FDK_Helical_2DWeighting(ScanGeom,fpwd,ctimage); 100 | save RecRes2DW ctimage; 101 | case 3 %3D weighting 102 | Parallel_FDK_Helical_3DWeighting(ScanGeom,fpwd,ctimage); 103 | save RecRes3DW ctimage; 104 | otherwise %1/2 redundancy weigthing 105 | Parallel_FDK_Helical_NOWeighting(ScanGeom,fpwd,ctimage); 106 | save RecResNoW ctimage; 107 | end; 108 | imdisp(ctimage) 109 | 110 | time =cputime-time 111 | 112 | 113 | -------------------------------------------------------------------------------- /graphics/private/VRMLpa.m: -------------------------------------------------------------------------------- 1 | function VRMLpa(fid, title, labels, start, finish, down, flip, labelSize) 2 | % 3 | % Function to plot graph axis in VRML 2.0 format 4 | % Axis labels go [lables(1):labels(2):labels(3) 5 | % Tick marks are located along a line from start to finish 6 | % Axis labels are located beneath each tick mark with orientation 7 | % determined by the down normal 8 | % e.g. for a planar x,y graph the x axis would lie along the bottom 9 | % of the graph and be the right way up for a viewer looking down the z axis 10 | % if down was [ 0 -1 0 ]. 11 | % 12 | % Copyright Craig Sayers and WHOI 1996. 13 | % 14 | 15 | axscale = norm(finish-start)/(labels(3)-labels(1)); 16 | % 17 | % Compute rotation so that x axis goes from start to finish 18 | % and y axis points up 19 | % 20 | x = [ finish(1)-start(1), finish(2)-start(2), finish(3)-start(3) ]; 21 | x = x / norm(x); 22 | y = - down; 23 | 24 | % 25 | % Now rotate frame to align world x axis with label x axis 26 | % 27 | axis1 = cross([1,0,0],x); 28 | angle1 = acos( x * [1;0;0]); 29 | 30 | % Compute new y axis location 31 | newX = VRMLra( axis1(1),axis1(2),axis1(3), angle1 ) * [1;0;0]; 32 | newY = VRMLra( axis1(1),axis1(2),axis1(3), angle1 ) * [0;1;0]; 33 | 34 | % Now rotate about x by cos(down, newY) 35 | axis2 = [1,0,0]; 36 | angle2 = acos(-down * newY); 37 | c = cross(newY,y) * newX; 38 | if cross(newY,y) * newX < 0 39 | angle2 = -angle2; 40 | end 41 | 42 | % Begin by drawing the tick marks 43 | % 44 | fprintf(fid,'Transform'); 45 | fprintf(fid,'{'); 46 | fprintf(fid,'translation %g %g %g\n',start(1),start(2),start(3)); 47 | fprintf(fid,'children'); 48 | fprintf(fid,'['); 49 | fprintf(fid,'Transform'); 50 | fprintf(fid,'{'); 51 | if angle1 ~= 0 52 | fprintf(fid,'rotation %g %g %g %g\n',axis1(1),axis1(2),axis1(3),angle1); 53 | end 54 | fprintf(fid,'children'); 55 | fprintf(fid,'['); 56 | fprintf(fid,'Transform'); 57 | fprintf(fid,'{'); 58 | if angle2 ~= 0 59 | fprintf(fid,'rotation %g %g %g %g\n',axis2(1),axis2(2),axis2(3),angle2); 60 | end 61 | fprintf(fid,'children'); 62 | fprintf(fid,'['); 63 | for i=labels(1):labels(2):labels(3) 64 | xpos = (i-labels(1))*axscale; 65 | fprintf(fid,'Transform'); 66 | fprintf(fid,'{'); 67 | fprintf(fid,'translation %g 0 0\n',xpos); 68 | if flip ~= 0 69 | fprintf(fid,'rotation 0 1 0 %g\n',pi); 70 | end 71 | fprintf(fid,'children'); 72 | fprintf(fid,'['); 73 | fprintf(fid,'Shape\n'); 74 | fprintf(fid,'{'); 75 | fprintf(fid,'geometry IndexedLineSet'); 76 | fprintf(fid,'{'); 77 | fprintf(fid,'colorPerVertex FALSE '); 78 | fprintf(fid,'coord Coordinate'); 79 | fprintf(fid,'{'); 80 | fprintf(fid,'point\n'); 81 | fprintf(fid,'['); 82 | fprintf(fid,' 0 0 %g, 0 %g %g',labelSize*0.02,-labelSize*0.2,labelSize*0.02); 83 | fprintf(fid,']'); 84 | fprintf(fid,'}'); 85 | fprintf(fid,'coordIndex\n'); 86 | fprintf(fid,'[ 0 1 ]'); 87 | fprintf(fid,'color Color { color [ 1.0 0.0 0.0]}'); 88 | fprintf(fid,'colorIndex'); 89 | fprintf(fid,'[ 0 ]'); 90 | fprintf(fid,'}'); 91 | fprintf(fid,'}'); 92 | 93 | fprintf(fid,'Transform'); 94 | fprintf(fid,'{'); 95 | fprintf(fid,'translation 0 %g %g\n',-labelSize,labelSize*0.02); 96 | fprintf(fid,'children'); 97 | fprintf(fid,'['); 98 | fprintf(fid,'labelShape'); 99 | fprintf(fid,'{'); 100 | fprintf(fid,'label "%g"\n',i); 101 | if i == labels(1) 102 | if flip == 0 103 | fprintf(fid,'just "BEGIN"',i); 104 | else 105 | fprintf(fid,'just "END"',i); 106 | end 107 | elseif i == labels(3) 108 | if flip == 0 109 | fprintf(fid,'just "END"',i); 110 | else 111 | fprintf(fid,'just "BEGIN"',i); 112 | end 113 | else 114 | fprintf(fid,'just "MIDDLE"',i); 115 | end 116 | fprintf(fid,'size %g',labelSize); 117 | fprintf(fid,'}'); 118 | fprintf(fid,']'); 119 | fprintf(fid,'}'); 120 | fprintf(fid,']'); 121 | fprintf(fid,'}\n'); 122 | end 123 | fprintf(fid,'Transform'); 124 | fprintf(fid,'{'); 125 | fprintf(fid,'translation %g %g 0\n',((labels(3)+labels(1))/2-labels(1))*axscale,-2*labelSize); 126 | if flip ~= 0 127 | fprintf(fid,'rotation 0 1 0 %g\n',pi); 128 | end 129 | fprintf(fid,'children'); 130 | fprintf(fid,'['); 131 | fprintf(fid,'Transform'); 132 | fprintf(fid,'{'); 133 | fprintf(fid,'translation 0 0 %g\n',labelSize*0.02); 134 | fprintf(fid,'children'); 135 | fprintf(fid,'['); 136 | fprintf(fid,'Shape'); 137 | fprintf(fid,'{ '); 138 | fprintf(fid,'geometry Text \n'); 139 | fprintf(fid,'{'); 140 | fprintf(fid,'string "%s"\n',title); 141 | fprintf(fid,'fontStyle FontStyle\n'); 142 | fprintf(fid,'{'); 143 | fprintf(fid,'size %g\n',labelSize); 144 | fprintf(fid,'justify "MIDDLE"\n'); 145 | fprintf(fid,'}'); 146 | fprintf(fid,'}'); 147 | fprintf(fid,'appearance Appearance'); 148 | fprintf(fid,'{'); 149 | fprintf(fid,'material Material'); 150 | fprintf(fid,'{'); 151 | fprintf(fid,'diffuseColor 1 0 0\n'); 152 | fprintf(fid,'emissiveColor 0.3 0 0\n'); 153 | fprintf(fid,'}'); 154 | fprintf(fid,'}'); 155 | fprintf(fid,'}'); 156 | fprintf(fid,']'); 157 | fprintf(fid,'}'); 158 | fprintf(fid,']'); 159 | fprintf(fid,'}'); 160 | fprintf(fid,']'); 161 | fprintf(fid,'}'); 162 | fprintf(fid,']'); 163 | fprintf(fid,'}'); 164 | fprintf(fid,']'); 165 | fprintf(fid,'}\n'); 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /Parallel_FDK_Helical_NOWeighting.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////// 2 | // Imaging and Informatics Lab 3 | // Department of Electrical and Computer Engineering 4 | // University of Massachusetts Lowell 5 | // Parallel-cone backprojection 6 | // Nov. 14, 2015 7 | ////////////////////////////////// 8 | 9 | #include 10 | #include 11 | #include 12 | #define DOUBLE_PRECISION 13 | #define TYPE double 14 | const static double pi = 3.14159265358979; 15 | static const double *geom[4]; 16 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 17 | { 18 | TYPE ObjR,XNC,YNC,ZNC,SO,DO,DecWidth,DecHeigh,h,dYL,dZL,YLC,ZLC,dx,dy,dz,DeltaFai,BetaS; 19 | int YL,ZL,XN,YN,ZN,N_2pi,N_pi,PN,i,j,k; 20 | TYPE *ctimage; 21 | const TYPE *fp; 22 | 23 | 24 | 25 | /* Check for proper number of arguments */ 26 | if (nrhs != 3) { 27 | mexErrMsgTxt("Backward projection needs 3 inputs."); 28 | } 29 | if (nlhs != 0) { 30 | mexErrMsgTxt("Backward projection does not need any output."); 31 | } 32 | //Parallel_FDK_Helical_NOWeighting(ScanGeom,fpwd,ctimage); 33 | // ScanGeom = struct( 'ScDet', [SO DO YL ZL DecWidth DecHeigh YLC ZLC h], ... 34 | // 'Proj', [BetaS BetaE ViewN N_2pi], ... 35 | // 'Obj', [ObjR XN YN ZN XC YC ZC], ... 36 | // 'Rec', [delta HSCoef k1]); 37 | geom[0] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 0)); 38 | SO = geom[0][0]; 39 | DO = geom[0][1]; 40 | YL = int(geom[0][2]+0.5); 41 | ZL = int(geom[0][3]+0.5); 42 | DecWidth = geom[0][4]; 43 | DecHeigh = geom[0][5]; 44 | YLC = geom[0][6]-1; 45 | ZLC = geom[0][7]-1; 46 | h = geom[0][8]*DecHeigh; 47 | 48 | geom[1] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 1)); 49 | BetaS = geom[1][0]; 50 | PN = geom[1][2]; 51 | N_2pi = int(geom[1][3]); 52 | 53 | geom[2] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 2)); 54 | ObjR = geom[2][0]; 55 | XN = int(geom[2][1]+0.5); 56 | YN = int(geom[2][2]+0.5); 57 | ZN = int(geom[2][3]+0.5); 58 | XNC = geom[2][4]-1; 59 | YNC = geom[2][5]-1; 60 | ZNC = geom[2][6]-1; 61 | 62 | fp = mxGetPr(prhs[1]); 63 | ctimage = mxGetPr(prhs[2]); 64 | 65 | N_pi = N_2pi/2; 66 | dx = 2*ObjR/XN; 67 | dy = 2*ObjR/YN; 68 | dz = 2*ObjR/ZN; 69 | dYL = DecWidth/YL; 70 | dZL = DecHeigh/ZL; 71 | 72 | DeltaFai = 2*pi/N_2pi; 73 | 74 | if (mxGetClassID(prhs[1]) == mxSINGLE_CLASS) 75 | { 76 | mexErrMsgTxt("Single precision is not supported in this version.\n"); 77 | return; 78 | } 79 | else 80 | { 81 | //////begin of the main code for backprojection 82 | TYPE x,y,z,Dey,Dez,touying,UU,U1,V1,Beta0,Yr,Zr,View,weight; 83 | int ProjInd,xi,yi,zi,U,V,s0,s1,s2,d1,d2; 84 | 85 | for(zi = 0; zi0)) 94 | { 95 | if (s1 < 0) {s1 = 0;} 96 | if (s2 > PN-1) {s2 = PN-1;} 97 | for (ProjInd = s1; ProjInd <= s2; ProjInd++ ) 98 | { 99 | View = BetaS + ProjInd* DeltaFai; 100 | for(yi=0;yi0) && (U0) && (V0)) 130 | } //zi 131 | 132 | //////end of the main code 133 | }/// if (mxGetClassID(prhs[1]) == mxSINGLE_CLASS) 134 | } 135 | 136 | -------------------------------------------------------------------------------- /graphics/arrow.m: -------------------------------------------------------------------------------- 1 | function handles = arrow( x1,y1,x2,y2,varargin ) 2 | % 3 | % arrow - plots an arrow to the current plot 4 | % 5 | % format: handles = arrow( x1,y1,x2,y2 [,options...] ) 6 | % 7 | % input: x1,y1 - starting point 8 | % x2,y2 - end point 9 | % options - come as pairs of "property","value" as defined for 10 | % "line" and "patch" controls, see matlab help for 11 | % listing of these properties. note that not all 12 | % properties where added, one might add them at the 13 | % end of this file. 14 | % 15 | % additional options are: 16 | % 'headwidth': relative to complete arrow size, 17 | % default value is 0.07 'headheight': relative to 18 | % complete arrow size, default value is 0.15 (encoded 19 | % are maximal values if pixels, for the case that the 20 | % arrow is very long) 21 | % 22 | % output: handles - handles of the graphical elements building the arrow 23 | % 24 | % Example: arrow( -1,-1,15,12,'linewidth',2,'color',[0.5 0.5 0.5], ... 25 | % 'facecolor',[0.5 0.5 0.5] ); 26 | % arrow( -1,-1,15,12,'linewidth',2,'colors',[0.5 0.5 0.5] ); 27 | % arrow( 0,0,5,4,'linewidth',2,'headwidth',0.25,'headheight',0.33 ); 28 | 29 | % ============================================= 30 | % constants (can be edited) 31 | % ============================================= 32 | alpha = 0.15; % head length 33 | beta = 0.07; % head width 34 | max_length = 22; 35 | max_width = 10; 36 | 37 | % ============================================= 38 | % check if head properties are given 39 | % ============================================= 40 | % if ratio is always fixed, this section can be removed! 41 | if ~isempty( varargin ) 42 | for c = 1:floor(length(varargin)/2) 43 | try 44 | switch lower(varargin{c*2-1}) 45 | % head properties - do nothing, since handled above already 46 | case 'headheight',alpha = max( min( varargin{c*2},1 ),0.01 ); 47 | case 'headwidth', beta = max( min( varargin{c*2},1 ),0.01 ); 48 | end 49 | catch 50 | fprintf( 'unrecognized property or value for: %s\n',varargin{c*2-1} ); 51 | end 52 | end 53 | end 54 | 55 | % ============================================= 56 | % calculate the arrow head coordinates 57 | % ============================================= 58 | x = zeros(3,length(x1)); 59 | y = x; 60 | z = x; 61 | for k=1:length(x1) 62 | [x(:,k),y(:,k),z(:,k)] = HeadCoords(x1(k),y1(k),x2(k),y2(k), ... 63 | alpha,beta,max_length,max_width); 64 | end 65 | 66 | % ============================================= 67 | % plot arrow (= line + patch of a triangle) 68 | % ============================================= 69 | h1 = plot( [x1;x2],[y1;y2],'k' ); 70 | h2 = patch( x,y,z ); 71 | 72 | % ============================================= 73 | % return handles 74 | % ============================================= 75 | handles = [h1; h2]; 76 | 77 | % ============================================= 78 | % check if styling is required 79 | % ============================================= 80 | % if no styling, this section can be removed! 81 | if ~isempty( varargin ) 82 | for c = 1:floor(length(varargin)/2) 83 | try 84 | switch lower(varargin{c*2-1}) 85 | 86 | % only patch properties 87 | case 'edgecolor' 88 | set( h2,'EdgeColor',varargin{c*2} ); 89 | case 'facecolor' 90 | set( h2,'FaceColor',varargin{c*2} ); 91 | case 'facelighting' 92 | set( h2,'FaceLighting',varargin{c*2} ); 93 | case 'edgelighting' 94 | set( h2,'EdgeLighting',varargin{c*2} ); 95 | 96 | % only line properties 97 | case 'color' 98 | set( h1,'Color',varargin{c*2} ); 99 | 100 | % all colors 101 | case 'colors' 102 | set( h2,'EdgeColor',varargin{c*2} ); 103 | set( h2,'FaceColor',varargin{c*2} ); 104 | set( h2,'FaceLighting',varargin{c*2} ); 105 | set( h2,'EdgeLighting',varargin{c*2} ); 106 | set( h1,'Color',varargin{c*2} ); 107 | 108 | % shared properties 109 | case 'linestyle' 110 | set( handles,'LineStyle',varargin{c*2} ); 111 | case 'linewidth' 112 | set( handles,'LineWidth',varargin{c*2} ); 113 | case 'parent' 114 | set( handles,'parent',varargin{c*2} ); 115 | 116 | % head properties - do nothing, since handled above already 117 | case 'headwidth' 118 | case 'headheight' 119 | 120 | end 121 | catch 122 | fprintf( 'unrecognized property or value for: %s\n',varargin{c*2-1} ); 123 | end 124 | end 125 | end 126 | 127 | 128 | function [x,y,z] = HeadCoords(x1,y1,x2,y2,alpha,beta,max_length,max_width) 129 | 130 | den = x2 - x1 + eps; % make sure no devision by zero occurs 131 | teta = atan( (y2-y1)/den ) + pi*(x2> L = [ 0 0 0; 17 | # 1 pi/2 0; 18 | # 2 pi/2 pi/2; 19 | # 4 0 0 ]; 20 | # 21 | # >> VRMLplot(L,'animation=robotTemplate.wrl') 22 | # 23 | # This generates an animation which rotates joint 1 by pi/2 radians 24 | # in the first second, rotates joint 2 by pi/2 radians during the next 25 | # second and then moves back to the starting position. 26 | # 27 | # Note - the name of the PROTO at the top of this file must be the same as the 28 | # filename for this file (minus the .wrl extension) - otherwise VRMLplot won't 29 | # parse it correctly. 30 | # 31 | # To use your own robot model: 32 | # 1) save this file under a new name: "yourNewFilename.wrl" 33 | # 2) change "PROTO robotTemplate" to "PROTO yourNewFilename" 34 | # 3) Then edit the PROTO definition - add an evenIn for each joint 35 | # you wish to animate. Field types can be either SFRotation or 36 | # SFTranslation, field labels should end in either transxyz, transx, 37 | # transy, transz, rotx, roty or rotz. VRMLplot uses the field type and the 38 | # end of the field label to determine the mappings between input columns 39 | # and events. For example, in the case of an event: 40 | # eventIn SFRotation test_rotx 41 | # it will create an orientation interpolator with rotation about the 42 | # x axis and use the values from one column of the input matrix to 43 | # specify the angle of rotation. 44 | # 4) Next create a model of your own articulated structure using the event 45 | # labels in places where you wish a motion to occur. For example, the 46 | # following will rotate its children about the xaxis using the eventIn 47 | # defined above. 48 | # 49 | # Transform 50 | # { 51 | # set_rotation IS test_rotx 52 | # children [ ... ] 53 | # } 54 | # 55 | # If you use the PROTO field values for transparency and color in your 56 | # model then VRMLplot will be able to do a better job of automatically 57 | # coloring and adding shadows. 58 | # 59 | # This file may be freely copied and altered BUT IF YOU CHANGE IT, 60 | # PLEASE RENAME IT AND COMMENT THE CHANGES 61 | # Copyright Craig Sayers and WHOI 1996. 62 | # 63 | Group{ 64 | PROTO robotTemplate [ field SFColor color 0.3 0.3 0.3 65 | field SFFloat transparency 0.0 66 | eventIn SFRotation joint1_rotz 67 | eventIn SFRotation joint2_rotz 68 | ] 69 | { 70 | Transform 71 | { 72 | children 73 | [ 74 | Transform 75 | { 76 | translation 0 0 0.035 77 | children Shape 78 | { 79 | appearance DEF defaultApp Appearance 80 | { 81 | material Material 82 | { 83 | diffuseColor IS color 84 | transparency IS transparency 85 | } 86 | } 87 | geometry Box 88 | { 89 | size 0.21 0.21 0.07 90 | } 91 | } 92 | } 93 | DEF joint1 Transform 94 | { 95 | translation 0 0 0.12 96 | set_rotation IS joint1_rotz 97 | children 98 | [ 99 | Transform 100 | { 101 | rotation 1 0 0 1.57 102 | children Shape 103 | { 104 | appearance DEF link1App Appearance 105 | { 106 | material Material 107 | { 108 | diffuseColor IS color 109 | transparency IS transparency 110 | } 111 | } 112 | geometry Cylinder { radius 0.1 height 0.1 } 113 | } 114 | } 115 | Transform 116 | { 117 | translation 0.5 0 0 118 | rotation 0 0 1 1.57 119 | children Shape 120 | { 121 | appearance USE link1App 122 | geometry Cylinder { radius 0.05 height 0.85 } 123 | } 124 | } 125 | 126 | Transform 127 | { 128 | translation 1 0 0 129 | children 130 | [ 131 | Transform 132 | { 133 | translation 0 0 0.025 134 | rotation 1 0 0 1.57 135 | children Shape 136 | { 137 | appearance USE link1App 138 | geometry Cylinder { radius 0.1 height 0.05 } 139 | } 140 | } 141 | DEF joint2 Transform 142 | { 143 | set_rotation IS joint2_rotz 144 | children 145 | [ 146 | Transform 147 | { 148 | translation 0 0 -0.025 149 | rotation 1 0 0 1.57 150 | children Shape 151 | { 152 | appearance DEF link2App Appearance 153 | { 154 | material Material 155 | { 156 | diffuseColor IS color 157 | transparency IS transparency 158 | } 159 | } 160 | geometry Cylinder { radius 0.1 height 0.05 } 161 | } 162 | } 163 | Transform 164 | { 165 | translation 0.525 0 0 166 | rotation 0 0 1 1.57 167 | children Shape 168 | { 169 | appearance USE link2App 170 | geometry Cylinder { radius 0.05 height 0.95 } 171 | } 172 | } 173 | ] 174 | } 175 | ] 176 | } 177 | ] 178 | } 179 | ] 180 | } 181 | } 182 | 183 | } -------------------------------------------------------------------------------- /CreateProjSlice_Helical_Flat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** Imaging and Informatic Lab 3 | ** Department of Electrical and Computer Engineering 4 | ** University of Massachusetts Lowell 5 | ** Version of 2015.12.22 6 | */ 7 | 8 | #include 9 | #include 10 | #define DOUBLE_PRECISION 11 | #define TYPE double 12 | #define PI 3.14159265358979 13 | #define ZAV 0.2 14 | static const double *geom[2]; 15 | static const double PhPar[14][7] = { 16 | {0.9000, 0.9000, 100, 0, 0, 0, 0}, 17 | {0.1500, 0.1500, ZAV, 0, 0, 0, 0}, 18 | {0.1500, 0.1500, ZAV, 0, 0.5, 0, 0}, 19 | {0.1500, 0.1500, ZAV, 0.4330, 0.2500, 0, 0}, 20 | {0.1500, 0.1500, ZAV, 0.4300, -0.2500, 0, 0}, 21 | {0.1500, 0.1500, ZAV, 0, -0.5, 0, 0}, 22 | {0.1500, 0.1500, ZAV, -0.4300, -0.2500, 0, 0}, 23 | {0.1500, 0.1500, ZAV, -0.4300, 0.2500, 0, 0}, 24 | {0.0800, 0.0800, ZAV, 0, 0.2500, 0, 0}, 25 | {0.0400, 0.0400, ZAV, 0.2165, 0.1250, 0, 0}, 26 | {0.0200, 0.0200, ZAV, 0.2165, -0.1250, 0, 0}, 27 | {0.0100, 0.0100, ZAV, 0, -0.25, 0, 0}, 28 | {0.0050, 0.0050, ZAV, -0.2165, -0.1250, 0, 0}, 29 | {0.0025, 0.0025, ZAV, -0.2165, 0.1250, 0, 0}}; 30 | 31 | void 32 | mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 33 | { 34 | TYPE Sx, Sy, Sz, SO,DO,costheta,sintheta,DecWidth,DecHeigh,dYL,dZL,YCenter,ZCenter;//,ObjR; 35 | int YL, ZL; 36 | TYPE *ProjSlice; 37 | const TYPE *Coef; 38 | 39 | /* Check for proper number of arguments */ 40 | if (nrhs != 2) { 41 | mexErrMsgTxt("cone beam projection need two inputs."); 42 | } 43 | if (nlhs != 1) { 44 | mexErrMsgTxt("cone beam projection need one output."); 45 | } 46 | /* The input parameters*/ 47 | //Slice = CreateProjSlice_Helical_Flat(SliceProjGeom,EnAttenuationCoef); 48 | //SliceProjGeom = struct( 'Sc', [Sx Sy Sz SO DO costheta sintheta], ... 49 | // 'Det', [YL ZL DecWidsth DecHeigh YC ZC]); 50 | 51 | geom[0] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 0)); 52 | Sx = geom[0][0]; 53 | Sy = geom[0][1]; 54 | Sz = geom[0][2]; 55 | SO = geom[0][3]; 56 | DO = geom[0][4]; 57 | costheta = geom[0][5]; 58 | sintheta = geom[0][6]; 59 | 60 | geom[1] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 1)); 61 | YL = int(geom[1][0]+0.5); 62 | ZL = int(geom[1][1]+0.5); 63 | DecWidth = geom[1][2]; 64 | DecHeigh = geom[1][3]; 65 | YCenter = geom[1][4]-1; 66 | ZCenter = geom[1][5]-1; 67 | 68 | //mexPrintf("Sx=%f,Sy=%f,Sz=%f,SO=%d,DO=%f,costheta=%f,sintheata=%f,YL=%d,ZL=%d,DecWidth=%f,DecHeigh=%f,YC=%f,ZC=%f\n",Sx, Sy,Sz,SO, DO, costheta, sintheta, YL, ZL, DecWidth, DecHeigh, YCenter, ZCenter); 69 | 70 | Coef = mxGetPr(prhs[1]); 71 | 72 | dYL = DecWidth/YL; 73 | dZL = DecHeigh/ZL; 74 | 75 | if (mxGetClassID(prhs[1]) == mxSINGLE_CLASS) 76 | { 77 | mexErrMsgTxt("Single precision is not supported in this version.\n"); 78 | return; 79 | } 80 | else 81 | { 82 | plhs[0] = mxCreateNumericMatrix(YL, ZL, mxDOUBLE_CLASS, mxREAL); 83 | /* Assign pointers to the various parameters */ 84 | ProjSlice = mxGetPr(plhs[0]); 85 | //The following is the actural projection part 86 | //computer some necessary constants 87 | TYPE Dx, Dy; 88 | Dx=-DO*costheta; 89 | Dy=-DO*sintheta; 90 | int Yindex,Zindex,ElpIndex; 91 | TYPE PS[3],SPS[3],XS[3],SXS[3],DX[3],tpdata,tempvar,AA,BB,CC,t1,t2,InterZ1,InterZ2,d,delta; 92 | TYPE pcos[14],psin[14],AxisSquare[14][3]; 93 | //TYPE PhPar[10][8]; 94 | 95 | XS[0] = Sx; 96 | XS[1] = Sy; 97 | XS[2] = Sz; 98 | 99 | for (ElpIndex=0;ElpIndex<14;ElpIndex++) 100 | { 101 | tpdata = PhPar[ElpIndex][6]*PI/180; 102 | pcos[ElpIndex] = cos(tpdata); 103 | psin[ElpIndex] = sin(tpdata); 104 | AxisSquare[ElpIndex][0] = pow(PhPar[ElpIndex][0],2); 105 | AxisSquare[ElpIndex][1] = pow(PhPar[ElpIndex][1],2); 106 | AxisSquare[ElpIndex][2] = pow(PhPar[ElpIndex][2],2); 107 | } 108 | 109 | for (Yindex=0;Yindex=0) 152 | { 153 | 154 | tpdata = tpdata+2*sqrt(delta)*tempvar*Coef[ElpIndex]/AA; 155 | 156 | } 157 | }//for (ElpIndex=0;ElpIndex<10;ElpIndex++) 158 | ProjSlice[Zindex*YL+Yindex]=tpdata; 159 | }//for (Zindex=0;Zindex 9 | #include 10 | #define DOUBLE_PRECISION 11 | #define TYPE double 12 | #define PI 3.14159265358979 13 | #define ZAV 0.2//100 14 | static const double *geom[2]; 15 | static const double PhPar[14][7] = { 16 | {0.9000, 0.9000, 100, 0, 0, 0, 0}, 17 | {0.1500, 0.1500, ZAV, 0, 0, 0, 0}, 18 | {0.1500, 0.1500, ZAV, 0, 0.5, 0, 0}, 19 | {0.1500, 0.1500, ZAV, 0.4330, 0.2500, 0, 0}, 20 | {0.1500, 0.1500, ZAV, 0.4300, -0.2500, 0, 0}, 21 | {0.1500, 0.1500, ZAV, 0, -0.5, 0, 0}, 22 | {0.1500, 0.1500, ZAV, -0.4300, -0.2500, 0, 0}, 23 | {0.1500, 0.1500, ZAV, -0.4300, 0.2500, 0, 0}, 24 | {0.0800, 0.0800, ZAV, 0, 0.2500, 0, 0}, 25 | {0.0400, 0.0400, ZAV, 0.2165, 0.1250, 0, 0}, 26 | {0.0200, 0.0200, ZAV, 0.2165, -0.1250, 0, 0}, 27 | {0.0100, 0.0100, ZAV, 0, -0.25, 0, 0}, 28 | {0.0050, 0.0050, ZAV, -0.2165, -0.1250, 0, 0}, 29 | {0.0025, 0.0025, ZAV, -0.2165, 0.1250, 0, 0}}; 30 | 31 | void 32 | mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 33 | { 34 | TYPE Sx, Sy, Sz, SO,DO,costheta,sintheta,DecAngle,DecHeigh,dYL,dZL,YCenter,ZCenter;//,ObjR; 35 | int YL, ZL; 36 | TYPE *ProjSlice; 37 | const TYPE *Coef; 38 | 39 | /* Check for proper number of arguments */ 40 | if (nrhs != 2) { 41 | mexErrMsgTxt("cone beam projection need two inputs."); 42 | } 43 | if (nlhs != 1) { 44 | mexErrMsgTxt("cone beam projection need one output."); 45 | } 46 | /* The input parameters*/ 47 | //Slice = CreateProjSlice_Helical_Flat(SliceProjGeom,EnAttenuationCoef); 48 | //SliceProjGeom = struct( 'Sc', [Sx Sy Sz SO DO costheta sintheta], ... 49 | // 'Det', [YL ZL DecAngle DecHeigh YC ZC]); 50 | 51 | geom[0] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 0)); 52 | Sx = geom[0][0]; 53 | Sy = geom[0][1]; 54 | Sz = geom[0][2]; 55 | SO = geom[0][3]; 56 | DO = geom[0][4]; 57 | costheta = geom[0][5]; 58 | sintheta = geom[0][6]; 59 | 60 | geom[1] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 1)); 61 | YL = int(geom[1][0]+0.5); 62 | ZL = int(geom[1][1]+0.5); 63 | DecAngle = geom[1][2]; 64 | DecHeigh = geom[1][3]; 65 | YCenter = geom[1][4]-1; 66 | ZCenter = geom[1][5]-1; 67 | 68 | //mexPrintf("Sx=%f,Sy=%f,Sz=%f,SO=%d,DO=%f,costheta=%f,sintheata=%f,YL=%d,ZL=%d,DecWidth=%f,DecHeigh=%f,YC=%f,ZC=%f\n",Sx, Sy,Sz,SO, DO, costheta, sintheta, YL, ZL, DecWidth, DecHeigh, YCenter, ZCenter); 69 | 70 | Coef = mxGetPr(prhs[1]); 71 | 72 | dYL = DecAngle/YL; 73 | dZL = DecHeigh/ZL; 74 | 75 | if (mxGetClassID(prhs[1]) == mxSINGLE_CLASS) 76 | { 77 | mexErrMsgTxt("Single precision is not supported in this version.\n"); 78 | return; 79 | } 80 | else 81 | { 82 | plhs[0] = mxCreateNumericMatrix(YL, ZL, mxDOUBLE_CLASS, mxREAL); 83 | /* Assign pointers to the various parameters */ 84 | ProjSlice = mxGetPr(plhs[0]); 85 | //The following is the actural projection part 86 | //computer some necessary constants 87 | TYPE Dx, Dy; 88 | Dx=-DO*costheta; 89 | Dy=-DO*sintheta; 90 | int Yindex,Zindex,ElpIndex; 91 | TYPE PS[3],SPS[3],XS[3],SXS[3],DX[3],tpdata,tempvar,AA,BB,CC,t1,t2,InterZ1,InterZ2,d,delta; 92 | TYPE pcos[14],psin[14],AxisSquare[14][3]; 93 | //TYPE PhPar[10][8]; 94 | 95 | XS[0] = Sx; 96 | XS[1] = Sy; 97 | XS[2] = Sz; 98 | 99 | for (ElpIndex=0;ElpIndex<14;ElpIndex++) 100 | { 101 | tpdata = PhPar[ElpIndex][6]*PI/180; 102 | pcos[ElpIndex] = cos(tpdata); 103 | psin[ElpIndex] = sin(tpdata); 104 | AxisSquare[ElpIndex][0] = pow(PhPar[ElpIndex][0],2); 105 | AxisSquare[ElpIndex][1] = pow(PhPar[ElpIndex][1],2); 106 | AxisSquare[ElpIndex][2] = pow(PhPar[ElpIndex][2],2); 107 | } 108 | 109 | for (Yindex=0;Yindex=0) 152 | { 153 | 154 | tpdata = tpdata+2*sqrt(delta)*tempvar*Coef[ElpIndex]/AA; 155 | 156 | } 157 | }//for (ElpIndex=0;ElpIndex<10;ElpIndex++) 158 | ProjSlice[Zindex*YL+Yindex]=tpdata; 159 | }//for (Zindex=0;Zindex= length(F)-7-length(protoname) 76 | disp(' '); 77 | disp(['VRMLplot error - unable to find "PROTO ' protoname '" in file:' filename]); 78 | error=-1; 79 | return; 80 | end 81 | 82 | for pos=pos:length(F) 83 | if F(pos) == '[' 84 | break 85 | end 86 | end 87 | 88 | if pos >= length(F) 89 | disp(' '); 90 | disp(['VRMLplot error - unable to find "[" after "PROTO ' protoname '" in file:' filename]); 91 | error=-1; 92 | return; 93 | end 94 | 95 | % Now read definitions - assume each is on a separate line 96 | % ( This is not optimal but neither are matlab's string functions! ) 97 | % 98 | foundColor=0; 99 | foundTransparency=0; 100 | col=1; 101 | space=' '; 102 | while( F(pos) ~= ']' & pos < length(F) ) 103 | if F(pos) == '#' 104 | while F(pos) ~= 10 & F(pos) ~= 13 & pos < length(F) pos=pos+1; end 105 | elseif strcmp(setstr(F(pos:pos+18))','field SFColor color') == 1 106 | pos=pos+18; 107 | foundColor=1; 108 | elseif strcmp(setstr(F(pos:pos+25))','field SFFloat transparency') == 1 109 | pos=pos+25; 110 | foundTransparency=1; 111 | elseif strcmp(setstr(F(pos:pos+6))','eventIn') == 1 112 | pos = pos+8; 113 | while ( F(pos) == 32 | F(pos) < 16 ) & pos < length(F) pos=pos+1; end 114 | eventType = []; 115 | while F(pos) ~=32 & F(pos) > 16 & pos < length(F) 116 | eventType = [ eventType F(pos) ]; 117 | pos = pos+1; 118 | end 119 | while ( F(pos) == 32 | F(pos) < 16 ) & pos < length(F) pos=pos+1; end 120 | eventName = []; 121 | while F(pos) ~=32 & F(pos) > 16 & pos < length(F) 122 | eventName = [ eventName F(pos) ]; 123 | pos = pos+1; 124 | end 125 | eventType = setstr(eventType); 126 | eventName= setstr(eventName); 127 | colDefNames(col,:) = [ eventName space(1:32-length(eventName)) ]; 128 | eventName = [ space(8) eventName ]; 129 | if strcmp(eventType,'SFRotation')==1 130 | if strcmp(eventName(length(eventName)-3:length(eventName)),'rotx') 131 | colDefTypes(col) = FORMAT_ROTX; 132 | elseif strcmp(eventName(length(eventName)-3:length(eventName)),'roty') 133 | colDefTypes(col) = FORMAT_ROTY; 134 | elseif strcmp(eventName(length(eventName)-3:length(eventName)),'rotz') 135 | colDefTypes(col) = FORMAT_ROTZ; 136 | else 137 | disp(' ') 138 | disp(['VRMLplot error - unrecognized rotational event name in file:' filename]) 139 | disp(' names of rotational events must end in rotx, roty or rotz') 140 | error=-1; 141 | return; 142 | end 143 | elseif strcmp(eventType,'SFVec3f')==1 144 | if strcmp(eventName(length(eventName)-7:length(eventName)),'transxyz') 145 | colDefTypes(col) = FORMAT_TRANSXYZ; 146 | elseif strcmp(eventName(length(eventName)-5:length(eventName)),'transx') 147 | colDefTypes(col) = FORMAT_TRANSX; 148 | elseif strcmp(eventName(length(eventName)-5:length(eventName)),'transy') 149 | colDefTypes(col) = FORMAT_TRANSY; 150 | elseif strcmp(eventName(length(eventName)-5:length(eventName)),'transz') 151 | colDefTypes(col) = FORMAT_TRANSZ; 152 | else 153 | disp(' ') 154 | disp(['VRMLplot error - unrecognized SFVec3f event name in file:' filename]) 155 | disp(' names of translational events must end in transx, transy, transz or transxyz') 156 | error=-1; 157 | return; 158 | end 159 | elseif strcmp(eventType,'SFFloat')==1 160 | colDefTypes(col) = FORMAT_SCALAR; 161 | else 162 | disp(' ') 163 | disp(['VRMLplot - error reading eventIn ' eventName ' in file:' filename]) 164 | disp(' currently only SFVec3f and SFRotation events are supported.') 165 | error=-1; 166 | return; 167 | end 168 | col = col+1; 169 | else 170 | pos=pos+1; 171 | end 172 | end 173 | 174 | if foundColor==0 175 | disp(' ') 176 | disp(['VRMLplot - error reading file:' filename]) 177 | disp(' Prototype definition did not contain a color entry.') 178 | disp(' It should contain: field SFColor color 0.3 0.3 0.3.') 179 | error=-1; 180 | return; 181 | end 182 | 183 | if foundTransparency==0 184 | disp(' ') 185 | disp(['VRMLplot - error reading file:' filename]) 186 | disp(' Prototype definition did not contain a transparency entry.') 187 | disp(' It should contain: field SFFloat transparency 0.0') 188 | error=-1; 189 | return; 190 | end 191 | 192 | % 193 | fclose(freadid); 194 | error=0; 195 | -------------------------------------------------------------------------------- /graphics/private/vehicleTemplate.wrl: -------------------------------------------------------------------------------- 1 | #VRML V2.0 utf8 2 | # 3 | # Generic Vehicle template - translates and rotates vehicle object in 3-D space 4 | # Designed for use with VRMLplot version 1.1 5 | # 6 | # To use with VRMLplot.m, pass VRMLplot a matrix containing 7 columns and 7 | # ask it to use that matrix to animate this file. 8 | # 9 | # The order of the columns in the input matrix is: 10 | # 1. time (seconds) 11 | # 2. position along world x axis (meters) 12 | # 3. position along world y axis (meters) 13 | # 4. position along world z axis (meters) 14 | # 5. rotation about vehicle z axis (radians) 15 | # 6. rotation about vehicle y axis (radians) 16 | # 7. rotation about vehicle x axis (radians) 17 | # 18 | # Example: 19 | # 20 | # >> L = [ 0 0 0 0 0 0 0 ; 21 | # 1 0 0 1 0 0 0 ; 22 | # 2 0 0 1 0 0 pi/2; 23 | # 4 0 0 0 0 0 0 ]; 24 | # 25 | # >> VRMLplot(L,'animation=vehicleTemplate.wrl') 26 | # 27 | # This generates an animated set of axes which moves 1 meter in the +z 28 | # direction in the first second, rotates pi/2 radians about the +x 29 | # axis during the next second and then moves back to the starting position. 30 | # 31 | # To use your own vehicle model: 32 | # 1) save this file under a new name: "yourNewFilename.wrl" 33 | # 2) change "PROTO vehicleTemplate" to "PROTO yourNewFilename" 34 | # 3) Then insert a model for your own object/vehicle in the space indicated by 35 | # comments later in this file. (You could use an EXTERNPROTO.) 36 | # If you use the PROTO field values for transparency and color in your 37 | # model then VRMLplot will be able to do a better job of automatically 38 | # coloring and adding shadows. 39 | # 40 | # Note - the name of the PROTO at the top of this file must be the same as the 41 | # filename for this file (minus the .wrl extension) - otherwise VRMLplot won't 42 | # parse it correctly. 43 | # 44 | # This file may be freely copied and altered BUT IF YOU CHANGE IT, 45 | # PLEASE RENAME IT AND COMMENT THE CHANGES 46 | # Copyright Craig Sayers and WHOI 1996. 47 | # 48 | Group{ 49 | PROTO vehicleTemplate[ field SFColor color 0.3 0.3 0.3 50 | field SFFloat transparency 0.0 51 | eventIn SFVec3f transxyz 52 | eventIn SFRotation rotz 53 | eventIn SFRotation roty 54 | eventIn SFRotation rotx 55 | ] 56 | { 57 | Transform 58 | { 59 | set_translation IS transxyz 60 | children Transform 61 | { 62 | set_rotation IS rotz 63 | children Transform 64 | { 65 | set_rotation IS roty 66 | children Transform 67 | { 68 | set_rotation IS rotx 69 | children 70 | [ 71 | # REPLACE FOLLOWING LINES WITH YOUR OWN VEHICLE MODEL 72 | # 73 | # The following lines build a shape to represent the x,y and z axes 74 | # The transparency of all shapes are set by the field in the PROTO definition 75 | # The color of the cylinders along each axis is also set by the PROTO defn 76 | # while the color of the cones at the tip of each axis are hard coded - 77 | # red for x axis, green for y axis and blue for z axis. 78 | Shape 79 | { 80 | appearance DEF axesApp Appearance 81 | { 82 | material Material 83 | { 84 | diffuseColor IS color 85 | transparency IS transparency 86 | } 87 | } 88 | geometry Sphere{radius 0.075} 89 | } 90 | Transform 91 | { 92 | translation 0.4 0 0 93 | rotation 0 0 1 -1.5701 94 | children 95 | [ 96 | Shape 97 | { 98 | appearance USE axesApp 99 | geometry DEF cylGeom Cylinder { radius 0.075 height 0.8 } 100 | } 101 | Transform 102 | { 103 | translation 0 0.45 0 104 | children Shape 105 | { 106 | appearance Appearance 107 | { 108 | material Material 109 | { 110 | transparency IS transparency 111 | diffuseColor 0.6 0.1 0.1 112 | } 113 | } 114 | geometry DEF coneGeom Cone{bottomRadius 0.175 height 0.3} 115 | } 116 | } 117 | ] 118 | } 119 | Transform 120 | { 121 | translation 0 0.4 0 122 | children 123 | [ 124 | Shape 125 | { 126 | appearance USE axesApp 127 | geometry USE cylGeom 128 | } 129 | Transform 130 | { 131 | translation 0 0.45 0 132 | children Shape 133 | { 134 | appearance Appearance 135 | { 136 | material Material 137 | { 138 | transparency IS transparency 139 | diffuseColor 0.1 0.6 0.1 140 | } 141 | } 142 | geometry USE coneGeom 143 | } 144 | } 145 | ] 146 | } 147 | Transform 148 | { 149 | translation 0 0 0.4 150 | rotation 1 0 0 1.5701 151 | children 152 | [ 153 | Shape 154 | { 155 | appearance USE axesApp 156 | geometry USE cylGeom 157 | } 158 | Transform 159 | { 160 | translation 0 0.45 0 161 | children Shape 162 | { 163 | appearance Appearance 164 | { 165 | material Material 166 | { 167 | transparency IS transparency 168 | diffuseColor 0.1 0.1 0.6 169 | } 170 | } 171 | geometry USE coneGeom 172 | } 173 | } 174 | ] 175 | } 176 | 177 | # REPLACE PRECEEDING LINES WITH YOUR OWN VEHICLE MODEL 178 | ] 179 | } 180 | } 181 | } 182 | } 183 | } 184 | 185 | } -------------------------------------------------------------------------------- /Parallel_FDK_Helical_2DWeighting.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////// 2 | // Imaging and Informatics Lab 3 | // Department of Electrical and Computer Engineering 4 | // University of Massachusetts Lowell 5 | // Parallel-cone backprojection 6 | // Dec. 22, 2015 7 | ////////////////////////////////// 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #define DOUBLE_PRECISION 14 | #define TYPE double 15 | const static double pi = 3.14159265358979; 16 | static const double *geom[4]; 17 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 18 | { 19 | TYPE ObjR,SO,DO,YLC,ZLC,XNC,YNC,ZNC,DecWidth,DecHeigh,h,dYL,dZL,dx,dy,dz,DeltaFai,BetaS,HSCoef; 20 | int YL,ZL,XN,YN,ZN,N_Circle,N_2pi,delta,N_pi,PN,i,j,k; 21 | TYPE *ctimage,*w; 22 | const TYPE *fp; 23 | //std::vector f; 24 | /* Check for proper number of arguments */ 25 | if (nrhs != 3) { 26 | mexErrMsgTxt("Backward projection need 3 inputs."); 27 | } 28 | if (nlhs != 0) { 29 | mexErrMsgTxt("Backward projection does not need any output."); 30 | } 31 | //Parallel_FDK_Helical_2DWeighting(ScanGeom,ctimage); 32 | // ScanGeom = struct( 'ScDet', [SO DO YL ZL DecWidth DecHeigh YLC ZLC h], ... 33 | // 'Proj', [BetaS BetaE ViewN N_2pi], ... 34 | // 'Obj', [ObjR XN YN ZN XC YC ZC], ... 35 | // 'Rec', [delta HSCoef k1]); 36 | geom[0] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 0)); 37 | SO = geom[0][0]; 38 | DO = geom[0][1]; 39 | YL = int(geom[0][2]+0.5); 40 | ZL = int(geom[0][3]+0.5); 41 | DecWidth = geom[0][4]; 42 | DecHeigh = geom[0][5]; 43 | YLC = geom[0][6]-1; 44 | ZLC = geom[0][7]-1; 45 | h = geom[0][8]*DecHeigh; 46 | 47 | geom[1] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 1)); 48 | BetaS = geom[1][0]; 49 | PN = geom[1][2]; 50 | N_2pi = int(geom[1][3]+0.5); 51 | 52 | geom[2] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 2)); 53 | ObjR = geom[2][0]; 54 | XN = int(geom[2][1]+0.5); 55 | YN = int(geom[2][2]+0.5); 56 | ZN = int(geom[2][3]+0.5); 57 | XNC = geom[2][4]-1; 58 | YNC = geom[2][5]-1; 59 | ZNC = geom[2][6]-1; 60 | 61 | geom[3] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 3)); 62 | delta = int(geom[3][0]+0.5); 63 | HSCoef = geom[3][1];// It is the value of Half_Scan/2*pi; 64 | 65 | fp = mxGetPr(prhs[1]); 66 | ctimage = mxGetPr(prhs[2]); 67 | 68 | N_pi = N_2pi/2; 69 | dx = 2*ObjR/XN; 70 | dy = 2*ObjR/YN; 71 | dz = 2*ObjR/ZN; 72 | dYL = DecWidth/YL; 73 | dZL = DecHeigh/ZL; 74 | 75 | DeltaFai = 2*pi/N_2pi; 76 | 77 | w = new TYPE[N_2pi]; 78 | if (mxGetClassID(prhs[1]) == mxSINGLE_CLASS) 79 | { 80 | mexErrMsgTxt("Single precision is not supported in this version.\n"); 81 | return; 82 | } 83 | else 84 | { 85 | //////begin of the main code 86 | TYPE x,y,z,Dey,Dez,touying,UU,U1,V1,Beta0,Yr,Zr,View,weight; 87 | int ProjInd,xi,yi,zi,U,V,s0,s1,s2,d1,d2,L,Shift; 88 | 89 | for(zi = 0; zi0)) 99 | { 100 | if (s1 < 0) {s1 = 0;} 101 | if (s2 > PN-1) {s2 = PN-1;} 102 | ////////////////////////////////////////// 103 | ////Producing the weighting function 104 | for (int k=0;k= s0) 135 | { 136 | d2 = d1-N_pi; 137 | } 138 | weight = w[d1]/(w[d1]+w[d2]); 139 | 140 | for(yi=0;yi0)&&(U0)&&(V0)) 168 | } //zi 169 | //////end of the main code 170 | }/// if (mxGetClassID(prhs[1]) == mxSINGLE_CLASS) 171 | 172 | delete[] w; 173 | } 174 | 175 | -------------------------------------------------------------------------------- /myHelical_Rec_Curve.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This is to demonstrate the applicaiton of analytic cone-beam reconstrution withe curved detector. 3 | % The codes were developed by Hengyong Yu, Department of Electrical and Computer Engineering, University of Massachusetts Lowell. 4 | % Email: hengyong-yu@ieee.org 5 | % Version 2, Dec. 23, 2015 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | clear all; 8 | close all; 9 | 10 | 11 | % dataFolder = 'D:\Yanbo\Data\From_Robert_20161013\p2\75536_Anonymous_CT__601_RAW_20161005_122612_353008_2016_10_12_16_35_03_864000_417921596_ptr\'; 12 | %dataFolder = 'D:\Yanbo\Data\From_Robert_20161013\p1\75536_Anonymous_CT__601_RAW_20161006_174339_292988_2016_10_12_16_27_45_094000_420600202_ptr\'; 13 | dataFolder = 'D:\UML_Workspace\MatlabFiles\Yu_V1_04162016\75536_Anonymous_CT__601_RAW_20161006_174339_292988_2016_10_12_16_27_45_094000_420600202_ptr\'; 14 | 15 | load([dataFolder, 'dataInfo']) 16 | load([dataFolder, 'dataInfo_UID20']) 17 | load([dataFolder, 'dataInfo_UID50']) 18 | 19 | id_high_low = 1; % id_high_low: 1: high; 2: low 20 | viewStart = 100; 21 | viewEnd = 1800; 22 | proj3D = zeros(viewEnd-viewStart+1, dataInfo.ModeParXML.Type.ChnNum(id_high_low), dataInfo.ModeParXML.ModePar.NoOfSlicesDMS); 23 | j= 1; 24 | for i = viewStart:viewEnd 25 | projName = ['proj_', num2str(i)]; 26 | headerName = ['header_', num2str(i)]; 27 | load([dataFolder, projName], 'proj') 28 | proj=proj{id_high_low}; 29 | proj=proj(end:-1:1,end:-1:1); 30 | proj3D(j, :, :) = proj;%{id_high_low}; 31 | % proj3D(j, :, :) = flipud(fliplr(proj{id_high_low})); 32 | % proj3D(end-j+1, :, :) = (proj{id_high_low}); 33 | % proj3D(end-j+1, :, :) = fliplr(proj{id_high_low}); 34 | % proj3D(end-j+1, :, :) = flipud(proj{id_high_low}); 35 | % proj3D(end-j+1, :, :) = flipud(proj{id_high_low}); 36 | % proj3D(j, :, :) = flipud(proj{id_high_low}); 37 | j = j+1; 38 | end 39 | 40 | Proj = proj3D; 41 | 42 | time = cputime; 43 | % Rebinning (Convert conebeam to parallel beam) 44 | % The following lines 13-23 are used to define the helical scanning geometry for a micro-CT 45 | SO = 59.5;%57;%10; % The distance from source to object (cm) 46 | DO = 108.56-SO;%104-57;%5; % The distance from detector to object center(cm) 47 | YL = dataInfo.ModeParXML.Type.ChnNum(id_high_low);%350; % Detector cell number along the horizontal direction of detector array 48 | YLC= (1+YL)*0.5+1.0; % Detector center along the horizontal direction of detector array 49 | ZL = dataInfo.ModeParXML.ModePar.NoOfSlicesDMS;%20; % Detector cell number along the vertical direction of detector array 50 | ZLC= (1+ZL)*0.5; % Detector center along the vertical direction of detector array 51 | DecAngle = YL*0.10/(SO+DO);%YL*0.06/(SO+DO);%0.232; % Detector array beam angle along the horizontal direction (rad) 52 | DecHeigh = ZL*0.06*(SO+DO)/SO;%0.2; % Detector array height along the vertical direction (cm) 53 | 54 | N_2pi = 2*dataInfo.ScanDescr.FramesPerRotation;%360; % The projections/views number for each turn of scan 55 | N_Turn = (viewEnd-viewStart+1)/N_2pi;%3; % The number of turns for the whole helical scan 56 | 57 | h =abs(dataInfo_UID20.TablePosition(N_2pi+1) - dataInfo_UID20.TablePosition(1))/1000/10/DecHeigh; 58 | % h = 1; % Helical pitch related to detector height 59 | %The following line 25-28 are used to define the reconstruction paramters 60 | WtInd = 3; %1:Redundancy weighting; 2:2D weigthing; 3: 3D weighting 61 | k1 = 5; % The order to define the 3D weighting function 62 | delta = 60; % The range to define smoothness of 2D weigthing function 63 | HSCoef = 0.65; % This is used to define the half-scan range 64 | 65 | ObjR = 20;%1.1; % Diameter of imaginh object 66 | SSO = 128; % Define the size of the reconstructed image 67 | XN = 2*SSO; 68 | YN = 2*SSO; 69 | ZN = SSO;%2*SSO; 70 | XC = (XN+1)*0.5; 71 | YC = (YN+1)*0.5; 72 | ZC = (ZN+1)*0.5; 73 | BetaS = -round((viewEnd-viewStart+1)/2)*2*pi/N_2pi;%-N_Turn*pi; 74 | BetaE = (viewEnd-viewStart )*2*pi/N_2pi+ BetaS; %N_Turn*pi; 75 | ViewN = (viewEnd-viewStart+1);% N_Turn*N_2pi+1; 76 | 77 | DecWidth = tan(DecAngle*0.5)*(SO+DO)*2; 78 | dYL = DecWidth/YL; 79 | dZL = DecHeigh/ZL; 80 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 81 | ScanGeom = struct( 'ScDet', [SO DO YL ZL DecAngle DecHeigh YLC ZLC h], ... 82 | 'Proj', [BetaS BetaE ViewN N_2pi], ... 83 | 'Obj', [ObjR XN YN ZN XC YC ZC], ... 84 | 'Rec', [delta HSCoef k1]); 85 | % Generating projections or load the projections 86 | disp('Generating the cone beam projections'); 87 | % [ScPos Proj] = Conebeam_Curve_CreateProj_CB_Helical_Spectrum(ScanGeom); 88 | %load SpectralProjections; 89 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 90 | % Rebinning conebeam to parallel beam 91 | disp('Paralllel rebinning from the conebeam projections'); 92 | Proj = Parallel_Rebinning_CB_Curve(Proj,ScanGeom); 93 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 94 | %Preweighting the conebeam projections 95 | disp('PreWeighting the cone beam projection'); 96 | %for i=1:ViewN 97 | for j=1:YL 98 | t=(j-YLC)*dYL; 99 | for k=1:ZL 100 | b=(k-ZLC)*dZL; 101 | Proj(:,j,k) = Proj(:,j,k)*SO*SO/sqrt(SO^4+(SO*b)^2-(b*t)^2); 102 | end 103 | end 104 | %end 105 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 106 | %Perform Ramp filtering 107 | disp('Filtering the cone beam projection'); 108 | n = -YL:YL; 109 | hsl=-2./((pi^2)*(4*n.*n-1))/dYL; 110 | %plot(n,hsl); 111 | NN = 2^ceil(log(YL*3)/log(2)); 112 | HS = zeros(1,NN); 113 | HS(1:YL+1)= hsl(YL+1:2*YL+1); 114 | HS(end-YL+1:end)=hsl(1:YL); 115 | FtS = fft(HS); 116 | fpwd = zeros(size(Proj)); 117 | for i=1:ViewN 118 | for k=1:ZL 119 | FtP = fft(Proj(i,:,k),NN); 120 | tep = ifft(FtS.*FtP); 121 | fpwd(i,:,k) = real(tep(1:YL)); 122 | end 123 | end 124 | %save fpwd.mat fpwd; 125 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 126 | %Backproject the filtered data into the 3D space 127 | ScanGeom.ScDet(5) = DecWidth; 128 | disp('BackProjection the filtered projection'); 129 | ctimage = zeros(XN,YN,ZN); 130 | switch(WtInd) 131 | case 1 %1/2 redundancy weigthing 132 | Parallel_FDK_Helical_NOWeighting(ScanGeom,fpwd,ctimage); 133 | % save RecResNoW ctimage; 134 | case 2 % 2D weighting 135 | Parallel_FDK_Helical_2DWeighting(ScanGeom,fpwd,ctimage); 136 | % save RecRes2DW ctimage; 137 | case 3 %3D weighting 138 | Parallel_FDK_Helical_3DWeighting(ScanGeom,fpwd,ctimage); 139 | % save RecRes3DW ctimage; 140 | otherwise %1/2 redundancy weigthing 141 | Parallel_FDK_Helical_NOWeighting(ScanGeom,fpwd,ctimage); 142 | % save RecResNoW ctimage; 143 | end; 144 | imdisp(ctimage) 145 | 146 | time =cputime-time 147 | 148 | 149 | -------------------------------------------------------------------------------- /graphics/imdisp.m: -------------------------------------------------------------------------------- 1 | function h = imdisp(varargin) 2 | 3 | name = inputname(1); 4 | data = squeeze(varargin{1}); 5 | if nargin>1 6 | displims = varargin{2}; 7 | else 8 | displims = []; 9 | end 10 | 11 | [hfig,himgs,hline,hlines] = DispLayout(name,size(data)); 12 | DisplayConsole(hfig,data,displims); 13 | handles = guihandles(hfig); 14 | handles.ImagePanel = himgs; 15 | handles.CrossLine = hline; 16 | if ~isempty(hlines) 17 | handles.ImageLine = hlines; 18 | end 19 | handles.data = data; 20 | 21 | guidata(hfig,handles); 22 | UpdateDisplay(handles); 23 | set(hfig,'Visible','on'); 24 | if nargout, h = handles; end 25 | 26 | 27 | % -------------------------------------------------------------------- 28 | function [hfig,himgs,hline,hlines] = DispLayout(name,dtsz) 29 | 30 | % Display figure 31 | uipos = get(0,'defaultfigurePosition'); 32 | uipos = [624 390 920 710]; 33 | set(0,'ShowHiddenHandles','on'); 34 | hfig = figure(... 35 | 'Name',name,... 36 | 'BackingStore','on',... 37 | 'Menubar','figure',... 38 | 'Toolbar','figure',... 39 | 'NumberTitle','off',... 40 | 'Color',0.8*[1 1 1],... 41 | 'Colormap', gray(256),... 42 | 'DoubleBuffer','on',... 43 | 'Position',uipos,... 44 | 'ResizeFcn',{@ResizeCallback}',... 45 | 'PaperPositionMode','auto',... 46 | 'Visible','off',... 47 | 'Tag','imfig'); 48 | if isempty(name) 49 | set(hfig,'Name',['Imdisp No. ' num2str(hfig)]); 50 | end 51 | 52 | % Projection view 53 | uipos = get(hfig,'Position'); 54 | [uipos,width,height] = PanelSize(0.235,uipos,dtsz); 55 | h = uipanel(... 56 | 'BackgroundColor',get(0,'DefaultUicontrolBackgroundColor'),... 57 | 'Position',uipos,... 58 | 'BorderWidth',0,... 59 | 'Tag','DisplayPanel'); 60 | 61 | % Image panels 62 | axes(... 63 | 'Parent',h,... 64 | 'Layer','top',... 65 | 'Units','normalized',... 66 | 'Position',[0 0 width(1) height(1)],... 67 | 'Visible','off'); 68 | 69 | himgs = image(zeros(dtsz(1),dtsz(2))); 70 | axis image off; 71 | set(himgs,'ButtonDownFcn',{@ButtonDownCallback,'z',dtsz}); 72 | hold on; 73 | hline = plot([1 1],[1 dtsz(1)],'y'); 74 | set(hline,'Visible','off',... 75 | 'HitTest','off'); 76 | 77 | if length(dtsz)==2 78 | hlines = []; 79 | hold off; 80 | return; 81 | end 82 | 83 | hlines(3,1) = plot([1 1],[1 dtsz(1)],'b'); 84 | hlines(3,2) = plot([1 dtsz(2)],[1 1],'g'); 85 | hold off; 86 | 87 | axes(... 88 | 'Parent',h,... 89 | 'Layer','top',... 90 | 'Units','normalized',... 91 | 'Position',[0 height(1) width(1) height(2)],... 92 | 'Visible','off'); 93 | himgs(3) = himgs; 94 | himgs(2) = image(zeros(dtsz(3),dtsz(2)),... 95 | 'ButtonDownFcn',{@ButtonDownCallback,'y',dtsz}); 96 | axis image xy off; 97 | hold on; 98 | hlines(2,1) = plot([1 1],[1 dtsz(3)],'b'); 99 | hlines(2,2) = plot([1 dtsz(2)],[1 1],'r'); 100 | hold off; 101 | 102 | axes(... 103 | 'Parent',h,... 104 | 'Layer','top',... 105 | 'Units','normalized',... 106 | 'Position',[width(1) 0 width(2) height(1)],... 107 | 'Visible','off'); 108 | himgs(1) = image(zeros(dtsz(1),dtsz(3)),... 109 | 'ButtonDownFcn',{@ButtonDownCallback,'x',dtsz}); 110 | axis image off; 111 | hold on; 112 | hlines(1,1) = plot([1 1],[1 dtsz(1)],'r'); 113 | hlines(1,2) = plot([1 dtsz(3)],[1 1],'g'); 114 | hold off; 115 | set(hlines,'HitTest','off'); 116 | 117 | 118 | % -------------------------------------------------------------------- 119 | function ButtonDownCallback(hobj,evdt,type,dtsz) 120 | 121 | handles = guidata(hobj); 122 | hline = handles.CrossLine; 123 | pos = get(gca,'CurrentPoint'); 124 | pos = round(pos(1,1:2)); 125 | 126 | if strcmp(get(gcf,'SelectionType'),'alt') 127 | % right button 128 | set(hline,'Visible','off'); 129 | set(gcf,'WindowButtonMotionFcn',{@LineMotionCallback,hline,pos}, ... 130 | 'WindowButtonUpFcn',{@LineStopCallback,hline,pos}); 131 | 132 | else 133 | 134 | set(hline,'Visible','off'); 135 | try 136 | cur = cell2mat(get(handles.Point,'Value')); 137 | switch type 138 | case 'x' 139 | pos(2) = dtsz(1)-pos(2)+1; 140 | cur([3 2]) = pos(:); 141 | case 'y' 142 | cur([1 3]) = pos(:); 143 | case 'z' 144 | pos(2) = dtsz(1)-pos(2)+1; 145 | cur([1 2]) = pos(:); 146 | end 147 | set(handles.Point,{'Value'},num2cell(cur)); 148 | catch 149 | end 150 | UpdateDisplay(hobj,evdt); 151 | 152 | end 153 | 154 | 155 | % -------------------------------------------------------------------- 156 | function cur = LineMotionCallback(hobj,evdt,hline,pos) 157 | 158 | cur = get(gca,'CurrentPoint'); 159 | cur = round(cur(1,1:2)); 160 | set(hline,'Parent',gca, ... 161 | 'XData',[pos(1),cur(1)], ... 162 | 'YData',[pos(2),cur(2)], ... 163 | 'Visible','on'); 164 | drawnow; 165 | 166 | 167 | % -------------------------------------------------------------------- 168 | function LineStopCallback(hobj,evdt,hline,pos) 169 | 170 | set(gcf,'WindowButtonMotionFcn','', ... 171 | 'WindowButtonUpFcn',''); 172 | cur = LineMotionCallback(hobj,evdt,hline,pos); 173 | 174 | if pos(1)==cur(1) & pos(2)==cur(2) 175 | return; 176 | end 177 | 178 | h = findobj(get(hline,'Parent'),'type','image'); 179 | data = get(h,'UserData'); 180 | handles = guidata(hobj); 181 | 182 | figure; 183 | improfile(data,[pos(1),cur(1)],[pos(2),cur(2)]); 184 | grid on; 185 | 186 | 187 | % -------------------------------------------------------------------- 188 | function [uipos,width,height] = PanelSize(uipos,fgpos,dtsiz) 189 | 190 | margin = 10/fgpos(3); 191 | uipos = uipos+margin; 192 | if length(dtsiz)==2 193 | uipos = [uipos margin 1-uipos-margin 1-2*margin]; 194 | width = 1; 195 | height = 1; 196 | else 197 | width = dtsiz([2 3])+[0 2]; 198 | height = dtsiz([1 3])+[0 2]; 199 | sums = [sum(width) sum(height)]; 200 | width = width/sums(1); 201 | height = height/sums(2); 202 | 203 | ratio = sums(1)/sums(2)*fgpos(4)/fgpos(3); 204 | horz = (1-uipos-margin)*[1,1/ratio]; 205 | vert = (1-2*margin)*[ratio 1]; 206 | wtht = min(horz,vert); 207 | uipos = [uipos margin]; 208 | uipos = max(uipos,[uipos(1) 0]+(1-uipos-wtht)/2); 209 | uipos = [uipos wtht]; 210 | end 211 | 212 | 213 | % -------------------------------------------------------------------- 214 | function ResizeCallback(hobj,evdt) 215 | 216 | handles = guidata(hobj); 217 | if isempty(handles) return; end 218 | 219 | fgpos = get(handles.imfig,'Position'); 220 | uipos = get(handles.ConsolePanel,'Position'); 221 | if uipos(4)>fgpos(4) 222 | uipos(4) = fgpos(4)-20; 223 | else 224 | uipos(2) = fgpos(4)-uipos(4)-10; 225 | 226 | end 227 | set(handles.ConsolePanel,'Position',uipos); 228 | uipos = PanelSize(uipos(3)/fgpos(3),fgpos,size(handles.data)); 229 | set(handles.DisplayPanel,'Position',uipos); 230 | -------------------------------------------------------------------------------- /Parallel_FDK_Helical_3DWeighting.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////// 2 | // Imaging and Informatics Lab 3 | // Department of Electrical and Computer Engineering 4 | // University of Massachusetts Lowell 5 | // Parallel-cone backprojection 6 | // Dec. 22, 2015 7 | ////////////////////////////////// 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #define DOUBLE_PRECISION 14 | #define TYPE double 15 | const static double pi = 3.14159265358979; 16 | static const double *geom[4]; 17 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 18 | { 19 | TYPE ObjR,SO,DO,YLC,ZLC,XNC,YNC,ZNC,DecWidth,DecHeigh,h,dYL,dZL,dx,dy,dz,DeltaFai,BetaS,k1,HSCoef; 20 | int YL,ZL,XN,YN,ZN,N_2pi,delta,N_pi,PN,i,j,k; 21 | TYPE *ctimage,*w; 22 | const TYPE *fp; 23 | /* Check for proper number of arguments */ 24 | if (nrhs != 3) { 25 | mexErrMsgTxt("Backward projection needs 3 inputs."); 26 | } 27 | if (nlhs != 0) { 28 | mexErrMsgTxt("Backward projection does not need any output."); 29 | } 30 | //Parallel_FDK_Helical_3DWeighting(ObjR,SO,DO,YL,ZL,DecWidth,DecHeigh,XN,YN,ZN,N_Turn,N_2pi,h,k1,delta,fpwd,ctimage,HSCoef); 31 | //Parallel_FDK_Helical_3DWeighting(ScanGeom,ctimage); 32 | // ScanGeom = struct( 'ScDet', [SO DO YL ZL DecWidth DecHeigh YLC ZLC h], ... 33 | // 'Proj', [BetaS BetaE ViewN N_2pi], ... 34 | // 'Obj', [ObjR XN YN ZN XC YC ZC], ... 35 | // 'Rec', [delta HSCoef k1]); 36 | geom[0] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 0)); 37 | SO = geom[0][0]; 38 | DO = geom[0][1]; 39 | YL = int(geom[0][2]+0.5); 40 | ZL = int(geom[0][3]+0.5); 41 | DecWidth = geom[0][4]; 42 | DecHeigh = geom[0][5]; 43 | YLC = geom[0][6]-1; 44 | ZLC = geom[0][7]-1; 45 | h = geom[0][8]*DecHeigh; 46 | 47 | geom[1] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 1)); 48 | BetaS = geom[1][0]; 49 | PN = geom[1][2]; 50 | N_2pi = int(geom[1][3]); 51 | 52 | geom[2] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 2)); 53 | ObjR = geom[2][0]; 54 | XN = int(geom[2][1]+0.5); 55 | YN = int(geom[2][2]+0.5); 56 | ZN = int(geom[2][3]+0.5); 57 | XNC = geom[2][4]-1; 58 | YNC = geom[2][5]-1; 59 | ZNC = geom[2][6]-1; 60 | 61 | geom[3] = mxGetPr(mxGetFieldByNumber(prhs[0], 0, 3)); 62 | delta = int(geom[3][0]+0.5); 63 | HSCoef = geom[3][1];// It is the value of Half_Scan/2*pi; 64 | k1 = geom[3][2]*geom[0][8]; 65 | 66 | fp = mxGetPr(prhs[1]); 67 | ctimage = mxGetPr(prhs[2]); 68 | 69 | 70 | N_pi = N_2pi/2; 71 | dx = 2*ObjR/XN; 72 | dy = 2*ObjR/YN; 73 | dz = 2*ObjR/ZN; 74 | dYL = DecWidth/YL; 75 | dZL = DecHeigh/ZL; 76 | DeltaFai = 2*pi/N_2pi; 77 | 78 | w = new TYPE[N_2pi]; 79 | if (mxGetClassID(prhs[1]) == mxSINGLE_CLASS) 80 | { 81 | mexErrMsgTxt("Single precision is not supported in this version.\n"); 82 | return; 83 | } 84 | else 85 | { 86 | 87 | //////begin of the main code 88 | TYPE x,y,z,Dey,Dez,touying,UU,U1,V1,Beta0,Yr,Zr,View,weight,weight1,weight2,Gama,Gama_C,m1,m2; 89 | int ProjInd,xi,yi,zi,U,V,s0,s1,s2,d1,d2,L,Shift; 90 | 91 | for(zi = 0; zi0)) 101 | { 102 | if (s1 < 0) {s1 = 0;} 103 | if (s2 > PN-1) {s2 = PN-1;} 104 | ////////////////////////////////////////// 105 | ////Producing the weighting function 106 | for (int k=0;k= s0) 138 | { 139 | d2 = d1-N_pi; 140 | } 141 | 142 | for(yi=0;yi0)&&(U0)&&(V0)) 186 | } //zi 187 | //////end of the main code 188 | }/// if (mxGetClassID(prhs[1]) == mxSINGLE_CLASS) 189 | 190 | delete[] w; 191 | 192 | } 193 | 194 | -------------------------------------------------------------------------------- /graphics/rgb.m: -------------------------------------------------------------------------------- 1 | % rgb.m: translates a colour from multiple formats into matlab colour format 2 | % type 'rgb demo' to get started 3 | % 4 | % [matlabcolor]=rgb(col) 5 | % matlab colors are in the format [R G B] 6 | % 7 | % if 'col' is a string, it is interpreted as 8 | % 9 | % [[modifier] descriptor] colour_name 10 | % 11 | % where 12 | % modifier is one of (slightly, normal, very, extremely) 13 | % descriptor is one of (light/pale, normal, dark) 14 | % colorname is a name of a colour 15 | % (type 'rgb list' or 'rgb demo' to see them all) 16 | % 17 | % if 'col' is an integer between 0 and &HFFFFFF inclusive, 18 | % it is interpreted as a double word RGB value in the form 19 | % [0][R][G][B] 20 | % 21 | % if 'col' is a negative integer between -1 and -&HFFFFFF 22 | % inclusive, it is interpreted as the complement of a double 23 | % word RGB value in the form [0][B][G][R] 24 | % 25 | % if 'col' is a string of the form 'qbX' or 'qbXX' where X 26 | % is a digit then the number part is interpreted as a qbasic 27 | % color 28 | % 29 | % if 'col' is one of {k,w,r,g,b,y,m,c} a sensible result is 30 | % returned 31 | % 32 | % if 'col' is already in matlab format, it is unchanged 33 | 34 | % VERSION: 06/06/2002 35 | % AUTHOR: ben mitch 36 | % CONTACT: footballpitch@theconnexion.zzn.com 37 | % WWW: www.benmitch.co.uk\matlab (not yet) 38 | % LOCATION: figures\colors\ 39 | 40 | function out=rgb(in) 41 | 42 | if isa(in,'char') 43 | if in(1)=='x' 44 | if in(2)==' ' 45 | in=in(3:end); 46 | else 47 | in=in(2:end); 48 | end 49 | n = str2num(in); 50 | if isempty(n) 51 | out=XwinColor(in); 52 | else 53 | out=XwinColor(n); 54 | end 55 | elseif length(in)==1 56 | out=translatecolorchar(in); 57 | elseif length(in)>2 & length(in)<5 & strcmpi('qb',in(1:2)) 58 | out=qbcolor(sscanf(in(3:end),'%i')); 59 | else 60 | if strcmp(in,'demo') rgb_demo; return; end 61 | if strcmp(in,'list') rgb_list; return; end 62 | try 63 | out=translatecolorstring(in); 64 | catch 65 | out=XwinColor(in); 66 | end 67 | end 68 | elseif isa(in,'double') 69 | if size(in,1)==1 & size(in,2)==1 & abs(in)<16777216 70 | out=translatecolorRGB(in); 71 | elseif size(in,1)==1 & size(in,2)==3 72 | out=in; 73 | else 74 | warning('Unrecognised color format, black assumed'); 75 | out=[0 0 0]; 76 | end 77 | else 78 | warning('Unrecognised color format, black assumed'); 79 | out=[0 0 0]; 80 | end 81 | 82 | 83 | function out=translatecolorchar(in) 84 | switch(in) 85 | case 'k', out=[0 0 0]; 86 | case 'w', out=[1 1 1]; 87 | case 'r', out=[1 0 0]; 88 | case 'g', out=[0 1 0]; 89 | case 'b', out=[0 0 1]; 90 | case 'y', out=[1 1 0]; 91 | case 'm', out=[1 0 1]; 92 | case 'c', out=[0 1 1]; 93 | otherwise 94 | warning(['Unrecognised colour "' in '", black assumed']) 95 | out=[0 0 0]; 96 | return; 97 | end 98 | 99 | 100 | function out=translatecolorstring(in) 101 | args.tokens=rgb_parse(in); 102 | args.N=length(args.tokens); 103 | if args.N>3 104 | warning(['Too many words in color description, any more than 3 will' ... 105 | ' be ignored']); 106 | end 107 | while(args.N<3) 108 | args.tokens=[{'normal'};args.tokens]; 109 | args.N=args.N+1; 110 | end 111 | 112 | cols=get_cols; 113 | col=[]; 114 | for n=1:size(cols,1) 115 | names=cols{n,1}; 116 | for m=1:length(names) 117 | if strcmp(args.tokens{3},names{m}) col=cols{n,2}; break; end 118 | end 119 | if ~isempty(col) break; end 120 | end 121 | 122 | if isempty(col) 123 | error(['Unrecognised colour "' args.tokens{3} '", black assumed']) 124 | out=[0 0 0]; 125 | return; 126 | end 127 | 128 | switch args.tokens{1} 129 | case 'slightly', fac=0.75; 130 | case 'normal', fac=0.5; 131 | case 'very', fac=0.25; 132 | case 'extremely', fac=0.125; 133 | otherwise 134 | warning(['Unrecognised modifier "' args.tokens{1} '", normal assumed']) 135 | fac=0.5; 136 | end 137 | 138 | switch args.tokens{2} 139 | case {'light','pale'}, out=1-(1-col)*fac; 140 | case 'normal', out=col; 141 | case 'dark', out=col*fac; 142 | otherwise 143 | warning(['Unrecognised descriptor "' args.tokens{2} '", normal assumed']) 144 | out=col; 145 | end 146 | 147 | 148 | function out=translatecolorRGB(in) 149 | 150 | BGR=0; 151 | if in<0 152 | in=-in; 153 | BGR=1; 154 | end 155 | 156 | b=bytes4(in); 157 | if BGR out=b(4:-1:2); else out=b(2:4); end 158 | 159 | 160 | function out=qbcolor(in) 161 | 162 | % rgb value from basic colour code 163 | % 0-7 are normal, 8-15 are bright 164 | % 0 - black 165 | % 1 - red, 2 - green, 3 - blue 166 | % 4 - cyan, 5 - magenta, 6 - yellow 167 | % 7 - white 168 | 169 | bright=0.5; 170 | if in>7 in=in-8; bright=1; end 171 | 172 | switch in 173 | case 0, rgb=[0 0 0]; 174 | case 1, rgb=[1 0 0]; 175 | case 2, rgb=[0 1 0]; 176 | case 3, rgb=[0 0 1]; 177 | case 4, rgb=[0 1 1]; 178 | case 5, rgb=[1 0 1]; 179 | case 6, rgb=[1 1 0]; 180 | case 7, rgb=[1 1 1]; 181 | otherwise 182 | warning('Unrecognised QBasic color, black assumed'); 183 | out=[0 0 0]; 184 | return; 185 | end 186 | 187 | out=rgb*bright; 188 | 189 | 190 | function tokens=rgb_parse(str) 191 | 192 | % parse string to obtain all tokens 193 | % quoted strings count as single tokens 194 | 195 | inquotes=0; 196 | intoken=0; 197 | pos=1; 198 | l=length(str); 199 | st=0; 200 | ed=0; 201 | token=''; 202 | tab=char(9); 203 | tokens=cell(0); 204 | while(pos<=l) 205 | ch=str(pos); 206 | if inquotes 207 | if ch=='"' 208 | inquotes=0; 209 | tokens={tokens{:} token}; 210 | else 211 | token=[token ch]; 212 | end 213 | elseif intoken 214 | if ch==' ' | ch==tab 215 | intoken=0; 216 | tokens={tokens{:} token}; 217 | elseif ch=='"' 218 | error(['Quote misplace in <' str '>']); 219 | else 220 | token=[token ch]; 221 | end 222 | else 223 | if ch==' ' | ch==tab 224 | % do nothing 225 | elseif ch=='"' 226 | token=''; 227 | inquotes=1; 228 | else 229 | token=ch; 230 | intoken=1; 231 | end 232 | end 233 | pos=pos+1; 234 | end 235 | 236 | if intoken tokens={tokens{:} token}; end 237 | if inquotes error(['Unpaired quotes in <' str '>']); end 238 | 239 | tokens=tokens'; 240 | 241 | 242 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 243 | % DEMO 244 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 245 | function rgb_demo 246 | 247 | figure(1) 248 | clf 249 | cols = get_cols; 250 | cols = {cols{:,1}}'; 251 | cols = { cols{:}, ... 252 | 'k', ... 253 | 'r', ... 254 | 'g', ... 255 | 'b', ... 256 | 'y', ... 257 | 'm', ... 258 | 'c', ... 259 | 'w', ... 260 | '', ... 261 | 'extremely dark green', ... 262 | 'very dark green', ... 263 | 'dark green', ... 264 | 'slightly dark green', ... 265 | 'green', ... 266 | 'slightly pale green', ... 267 | 'pale green', ... 268 | 'very pale green', ... 269 | 'extremely pale green', ... 270 | }; 271 | 272 | height=9; 273 | x=0; 274 | y=0; 275 | for n=1:length(cols) 276 | rect(x,y,cols{n}) 277 | y=y+1; 278 | if y==height 279 | x=x+2; 280 | y=0; 281 | end 282 | end 283 | if y==0 x=x-2; end 284 | axis([0 (x+2) 0 height]) 285 | title('names on different rows are alternates') 286 | 287 | function rect(x,y,col) 288 | if isempty(col) return; end 289 | r=rectangle('position',[x+0.1 y+0.1 1.8 0.8]); 290 | col_=col; 291 | if iscell(col) col=col{1}; end 292 | colrgb=rgb(col); 293 | if strcmp(col(1),'u') & length(col)==2 294 | t=text(x+1,y+0.5,{'unnamed',['colour (' col(2) ')']}); 295 | set(r,'facecolor',colrgb); 296 | else 297 | t=text(x+1,y+0.5,col_); 298 | set(r,'facecolor',colrgb); 299 | if sum(colrgb)<1.5 set(t,'color',[1 1 1]); end 300 | end 301 | set(t,'horizontalalignment','center') 302 | set(t,'fontsize',10) 303 | 304 | function rgb_list 305 | cols=get_cols; 306 | disp(' ') 307 | for n=1:size(cols,1) 308 | code=cols{n,2}; 309 | str=cols{n,1}; 310 | str_=[]; 311 | for m=1:length(str) 312 | str_=[str_ str{m} ', ']; 313 | end 314 | str_=str_(1:end-2); 315 | if strcmp(str_(1),'u') & length(str_)==2 316 | str_=['* (' str_(2) ')']; 317 | end 318 | disp([' [' sprintf('%.1f %.1f %.1f',code) '] - ' str_]) 319 | end 320 | disp([10 '* colours marked thus are not named - if you know their' 10 ' designation, or if you feel sure a colour is mis-named,' 10 ' email me (address via help) or comment at' 10 ' www.mathworks.com/matlabcentral - "rgb demo" to see them' 10]) 321 | 322 | function cols=get_cols 323 | 324 | cols={ 325 | 'black', [0 0 0]; ... 326 | 'navy', [0 0 0.5]; ... 327 | 'blue', [0 0 1]; ... 328 | 'u1', [0 0.5 0]; ... 329 | {'teal','turquoise'}, [0 0.5 0.5]; ... 330 | 'slateblue', [0 0.5 1]; ... 331 | {'green','lime'}, [0 1 0]; ... 332 | 'springgreen', [0 1 0.5]; ... 333 | {'cyan','aqua'}, [0 1 1]; ... 334 | 'maroon', [0.5 0 0]; ... 335 | 'purple', [0.5 0 0.5]; ... 336 | 'u2', [0.5 0 1]; ... 337 | 'olive', [0.5 0.5 0]; ... 338 | {'gray','grey'}, [0.5 0.5 0.5]; ... 339 | 'u3', [0.5 0.5 1]; ... 340 | {'mediumspringgreen','chartreuse'}, [0.5 1 0]; ... 341 | 'u4', [0.5 1 0.5]; ... 342 | 'sky', [0.5 1 1]; ... 343 | 'red', [1 0 0]; ... 344 | 'u5', [1 0 0.5]; ... 345 | {'magenta','fuchsia'}, [1 0 1]; ... 346 | 'orange', [1 0.5 0]; ... 347 | 'u6', [1 0.5 0.5]; ... 348 | 'u7', [1 0.5 1]; ... 349 | 'yellow', [1 1 0]; ... 350 | 'u8', [1 1 0.5]; ... 351 | 'white', [1 1 1]; ... 352 | }; 353 | 354 | for n=1:size(cols,1) 355 | if ~iscell(cols{n,1}) cols{n,1}={cols{n,1}}; end 356 | end 357 | 358 | % converts a DWORD into a four byte row vector 359 | function out=bytes4(in) 360 | 361 | out=[0 0 0 0]; 362 | if in<0 | in>(2^32-1) 363 | warning('DWORD out of range, zero assumed'); 364 | return; 365 | end 366 | 367 | N=4; 368 | while(in>0) 369 | out(N)=mod(in,256); 370 | in=(in-out(N))/256; 371 | N=N-1; 372 | end 373 | -------------------------------------------------------------------------------- /graphics/imhdr.m: -------------------------------------------------------------------------------- 1 | function ret = imhdr(P,varargin) 2 | 3 | %imhdr: Read or write ANALYZE compatible image header file. 4 | 5 | if nargin == 0 6 | ret = struct('dimens', [1,1,1], ... 7 | 'voxel', [1,1,1], ... 8 | 'scale', 1, ... 9 | 'type', 2, ... 10 | 'offset', 0, ... 11 | 'origin', [0,0,0], ... 12 | 'endian', 'B', ... 13 | 'header', 0, ... 14 | 'descrip', ['ANALYZE compatible']); 15 | return; 16 | end 17 | 18 | % ensure correct suffix {.hdr} 19 | P = deblank(P); 20 | q = length(P); 21 | if q >= 4 & P(q - 3) == '.', P = P(1:(q - 4)); end 22 | P = [P '.hdr']; 23 | 24 | if nargin == 1 25 | ret = ReadHeader(P); 26 | else 27 | ret = WriteHeader(P,varargin{:}); 28 | end 29 | %_______________________________________________________________________ 30 | 31 | 32 | function params = ReadHeader(P) 33 | % reads a header 34 | % FORMAT [DIM VOX SCALE TYPE OFFSET ORIGIN DESCRIP] = spm_hread(P); 35 | % 36 | % P - filename (e.g spm or spm.img) 37 | % DIM - image size [i j k [l]] (voxels) 38 | % VOX - voxel size [x y z [t]] (mm [secs]) 39 | % SCALE - scale factor 40 | % TYPE - datatype (integer - see spm_type) 41 | % OFFSET - offset (bytes) 42 | % ORIGIN - origin [i j k] 43 | % DESCRIP - description string 44 | %___________________________________________________________________________ 45 | % 46 | % spm_hread reads variables into working memory from a SPM/ANALYZE 47 | % compatible header file. If the header does not exist global defaults 48 | % are used. The 'originator' field of the ANALYZE format has been 49 | % changed to ORIGIN in the SPM version of the header. funused1 of the 50 | % ANALYZE format is used for SCALE 51 | % 52 | % see also dbh.h (ANALYZE) spm_hwrite.m and spm_type.m 53 | % 54 | %__________________________________________________________________________ 55 | % @(#)spm_hread.m 2.7 99/10/29 56 | 57 | % open header file 58 | fid = fopen(P,'r','native'); 59 | 60 | if fid == -1 61 | error(['Error opening the header file ' P '.']); 62 | end 63 | 64 | % read (struct) header_key 65 | fseek(fid,0,'bof'); 66 | 67 | otherendian = 0; 68 | sizeof_hdr = fread(fid,1,'int32'); 69 | if sizeof_hdr==1543569408, 70 | % Appears to be other-endian Re-open other-endian 71 | fclose(fid); 72 | [COMPUTER,MAXSIZE,ENDIAN] = computer; 73 | if ENDIAN == 'B' 74 | fid = fopen(P,'r','ieee-le'); 75 | else, 76 | fid = fopen(P,'r','ieee-be'); 77 | end; 78 | fseek(fid,0,'bof'); 79 | sizeof_hdr = fread(fid,1,'int32'); 80 | otherendian = 1; 81 | end; 82 | 83 | data_type = SetString(fread(fid,10,'char'))'; 84 | db_name = SetString(fread(fid,18,'char'))'; 85 | extents = fread(fid,1, 'int32'); 86 | session_error = fread(fid,1, 'int16'); 87 | regular = SetString(fread(fid,1, 'char'))'; 88 | hkey_un0 = SetString(fread(fid,1, 'char'))'; 89 | 90 | % read (struct) image_dimension 91 | fseek(fid,40,'bof'); 92 | 93 | dim = fread(fid,8, 'int16'); 94 | vox_units = SetString(fread(fid,4, 'char'))'; 95 | cal_units = SetString(fread(fid,8, 'char'))'; 96 | unused1 = fread(fid,1, 'int16'); 97 | datatype = fread(fid,1, 'int16'); 98 | bitpix = fread(fid,1, 'int16'); 99 | dim_un0 = fread(fid,1, 'int16'); 100 | pixdim = fread(fid,8, 'float'); 101 | vox_offset = fread(fid,1, 'float'); 102 | funused1 = fread(fid,1, 'float'); 103 | funused2 = fread(fid,1, 'float'); 104 | funused3 = fread(fid,1, 'float'); 105 | cal_max = fread(fid,1, 'float'); 106 | cal_min = fread(fid,1, 'float'); 107 | compressed = fread(fid,1, 'int32'); 108 | verified = fread(fid,1, 'int32'); 109 | glmax = fread(fid,1, 'int32'); 110 | glmin = fread(fid,1, 'int32'); 111 | 112 | % read (struct) data_history 113 | fseek(fid,148,'bof'); 114 | 115 | descrip = SetString(fread(fid,80, 'char'))'; 116 | aux_file = SetString(fread(fid,24, 'char'))'; 117 | orient = fread(fid,1, 'char'); 118 | origin = fread(fid,5, 'int16'); 119 | generated = SetString(fread(fid,10, 'char'))'; 120 | scannum = SetString(fread(fid,10, 'char'))'; 121 | patient_id = SetString(fread(fid,10, 'char'))'; 122 | exp_date = SetString(fread(fid,10, 'char'))'; 123 | exp_time = SetString(fread(fid,10, 'char'))'; 124 | hist_un0 = SetString(fread(fid,3, 'char'))'; 125 | views = fread(fid,1, 'int32'); 126 | vols_added = fread(fid,1, 'int32'); 127 | start_field = fread(fid,1, 'int32'); 128 | field_skip = fread(fid,1, 'int32'); 129 | omax = fread(fid,1, 'int32'); 130 | omin = fread(fid,1, 'int32'); 131 | smax = fread(fid,1, 'int32'); 132 | smin = fread(fid,1, 'int32'); 133 | 134 | fclose(fid); 135 | 136 | if isempty(smin) 137 | error(['There is a problem with the header file ' P '.']); 138 | end 139 | 140 | params.dimens = dim(2:4)'; 141 | params.voxel = pixdim(2:4)'; 142 | params.scale = ~funused1 + funused1; 143 | if otherendian == 1 & datatype ~= 2, 144 | params.type = datatype*256; 145 | else 146 | params.type = datatype; 147 | end; 148 | params.offset = vox_offset; 149 | params.origin = origin(1:3)'; 150 | params.endian = hkey_un0; 151 | params.header = dim_un0; 152 | params.descrip = descrip(1:max(find(descrip))); 153 | %_______________________________________________________________________ 154 | 155 | 156 | function out = SetString(in) 157 | tmp = find(in == 0); 158 | tmp = min([min(tmp) length(in)]); 159 | out = setstr(in(1:tmp)); 160 | %_______________________________________________________________________ 161 | 162 | 163 | function s = WriteHeader(P,DIM,VOX,SCALE,TYPE,OFFSET,ORIGIN,DESCRIP) 164 | % writes a header 165 | % FORMAT [s] = spm_hwrite(P,DIM,VOX,SCALE,TYPE,OFFSET,ORIGIN,DESCRIP); 166 | % 167 | % P - filename (e.g 'spm' or 'spm.img') 168 | % DIM - image size [i j k [l]] (voxels) 169 | % VOX - voxel size [x y z [t]] (mm [sec]) 170 | % SCALE - scale factor 171 | % TYPE - datatype (integer - see spm_type) 172 | % OFFSET - offset (bytes) 173 | % ORIGIN - [i j k] of origin (default = [0 0 0]) 174 | % DESCRIP - description string (default = 'spm compatible') 175 | % 176 | % s - number of elements successfully written (should be 348) 177 | %___________________________________________________________________________ 178 | % 179 | % spm_hwrite writes variables from working memory into a SPM/ANALYZE 180 | % compatible header file. The 'originator' field of the ANALYZE format has 181 | % been changed to ORIGIN in the SPM version of the header. funused1 182 | % of the ANALYZE format is used for SCALE 183 | % 184 | % see also dbh.h (ANALYZE) spm_hread.m and spm_type.m 185 | % 186 | %__________________________________________________________________________ 187 | % @(#)spm_hwrite.m 2.2 99/10/29 188 | 189 | if nargin == 2 190 | params = DIM; 191 | DIM = params.dimens; 192 | VOX = params.voxel; 193 | SCALE = params.scale; 194 | TYPE = params.type; 195 | OFFSET = params.offset; 196 | ORIGIN = params.origin; 197 | ENDIAN = params.endian; 198 | DESCRIP = params.descrip; 199 | end 200 | 201 | % For byte swapped data-types, also swap the bytes around in the headers. 202 | mach = 'native'; 203 | if 0 204 | if TYPE == 1, 205 | [COMPUTER,MAXSIZE,ENDIAN] = computer; 206 | if ENDIAN == 'B', 207 | mach = 'ieee-le'; 208 | else, 209 | mach = 'ieee-be'; 210 | end; 211 | %TYPE = spm_type(spm_type(TYPE)); 212 | end; 213 | end 214 | fid = fopen(P,'w',mach); 215 | 216 | if (fid == -1), 217 | error(['Error opening ' P '. Check that you have write permission.']); 218 | end; 219 | data_type = ['dsr ' 0]; 220 | 221 | P = [P ' ']; 222 | db_name = [P(1:17) 0]; 223 | 224 | % set header variables 225 | DIM = DIM(:)'; if size(DIM,2) < 4; DIM = [DIM 1]; end 226 | VOX = VOX(:)'; if size(VOX,2) < 4; VOX = [VOX 0]; end 227 | dim = [4 DIM(1:4) 0 0 0]; 228 | pixdim = [0 VOX(1:4) 0 0 0]; 229 | vox_offset = OFFSET; 230 | funused1 = SCALE; 231 | glmax = 1; 232 | glmin = 0; 233 | bitpix = 0; 234 | descrip = zeros(1,80); 235 | aux_file = ['none ' 0]; 236 | origin = [0 0 0 0 0]; 237 | 238 | if TYPE == 1; bitpix = 1; glmax = 1; glmin = 0; end 239 | if TYPE == 2; bitpix = 8; glmax = 255; glmin = 0; end 240 | if TYPE == 4; bitpix = 16; glmax = 32767; glmin = 0; end 241 | if TYPE == 8; bitpix = 32; glmax = (2^31-1); glmin = 0; end 242 | if TYPE == 16; bitpix = 32; glmax = 1; glmin = 0; end 243 | if TYPE == 64; bitpix = 64; glmax = 1; glmin = 0; end 244 | 245 | if exist('ORIGIN','var'), origin = [ORIGIN(:)' 0 0]; end 246 | if ~exist('ENDIAN','var'), ENDIAN = '0'; end 247 | if ~exist('DESCRIP','var'), DESCRIP = 'ANALYZE compatible'; end 248 | 249 | d = 1:min([length(DESCRIP) 79]); 250 | descrip(d) = DESCRIP(d); 251 | 252 | fseek(fid,0,'bof'); 253 | 254 | % write (struct) header_key 255 | fwrite(fid,348, 'int32'); 256 | fwrite(fid,data_type, 'char' ); 257 | fwrite(fid,db_name, 'char' ); 258 | fwrite(fid,0, 'int32'); 259 | fwrite(fid,0, 'int16'); 260 | fwrite(fid,'r', 'char' ); 261 | fwrite(fid,ENDIAN, 'char' ); 262 | 263 | % write (struct) image_dimension 264 | fseek(fid,40,'bof'); 265 | 266 | fwrite(fid,dim, 'int16'); 267 | fwrite(fid,'mm', 'char' ); 268 | fwrite(fid,0, 'char' ); 269 | fwrite(fid,0, 'char' ); 270 | 271 | fwrite(fid,zeros(1,8),'char' ); 272 | fwrite(fid,0, 'int16'); 273 | fwrite(fid,TYPE, 'int16'); 274 | fwrite(fid,bitpix, 'int16'); 275 | fwrite(fid,0, 'int16'); 276 | fwrite(fid,pixdim, 'float'); 277 | fwrite(fid,vox_offset,'float'); 278 | fwrite(fid,funused1, 'float'); 279 | fwrite(fid,0, 'float'); 280 | fwrite(fid,0, 'float'); 281 | fwrite(fid,0, 'float'); 282 | fwrite(fid,0, 'float'); 283 | fwrite(fid,0, 'int32'); 284 | fwrite(fid,0, 'int32'); 285 | fwrite(fid,glmax, 'int32'); 286 | fwrite(fid,glmin, 'int32'); 287 | 288 | % write (struct) image_dimension 289 | fwrite(fid,descrip, 'char'); 290 | fwrite(fid,aux_file, 'char'); 291 | fwrite(fid,0, 'char'); 292 | fwrite(fid,origin, 'int16'); 293 | if fwrite(fid,zeros(1,85), 'char')~=85 294 | fclose(fid); 295 | %spm_unlink(P); 296 | error(['Error writing ' P '. Check your disk space.']); 297 | end 298 | 299 | s = ftell(fid); 300 | fclose(fid); 301 | -------------------------------------------------------------------------------- /PhotonAttenuation.m: -------------------------------------------------------------------------------- 1 | function X = PhotonAttenuation(Material, Energy, Options, Thickness) 2 | % PhotonAttenuation provides photon attenuation in different materials. 3 | % 4 | % X = PhotonAttenuation(Material, Energy, Options, Thickness) 5 | % Function providing the attenuation and energy absorption of x-ray and 6 | % gamma-ray photons in various materials including mixtures and compounds, 7 | % based on NIST report 5632, by J. Hubbell and S.M. Seltzer. 8 | % 9 | % Input : 10 | % 1) Material - string, number or array of strings, numbers or cells 11 | % describing material type. 12 | % - Element atomic number Z - in 1 to 100 range 13 | % - Element symbols - 'Pb', 'Fe' 14 | % - Element names - 'Lead', 'Iron', 'Cesium' or 'Caesium' 15 | % - Some common names and full compound names - 'Water', 'Polyethylene' 16 | % (see function PhysProps for more details) 17 | % - Compound formulas - 'H2SO4', 'C3H7NO2'- those are case sensitive 18 | % - Mixtures of any of above with fractions by weight - like 19 | % 'H(0.057444)C(0.774589)O(0.167968)' for Bakelite or 20 | % 'B(10)H(11)C(58)O(21)' for Borated Polyethylene (BPE-10) 21 | % Note: For 'Options' other than 'mac' or 'meac', 'Material' has to be 22 | % recognized by 'PhysProps' function since densities are needed for 23 | % calculation. 24 | % 2) Energy - Energy of the photons. Can be single energy or vector of 25 | % energies. Several formats are allowed: 26 | % - Energy in MeV, should be in [0.001, 20] MeV range. 27 | % - Wavelengths in nano-meters. Encoded as negative numbers. The valid 28 | % range is 6.1982e-5 to 1.2396 nm; 29 | % - Continuous Spectrum - Encoded in 2 columns: column one contains 30 | % energy in MeV and column two contains relative number of photons at that 31 | % energy. Spectrum is assumed to be continuous and output is 32 | % calculated through integration using 'trapz' function. 33 | % 3) Options - specifies what to return. String or number: 34 | % 1 - 'mac' - function returns Mass Attenuation Coefficients in cm^2/g 35 | % 2 - 'meac' - function returns Mass Energy-Absorption Coefficients 36 | % in cm^2/g. See link below for more info: 37 | % http://physics.nist.gov/PhysRefData/XrayMassCoef/chap3.html 38 | % 3 - 'cross section' or 'x' - function returns cross section in barns per 39 | % atom (convert to cm^2 per atom by multiplying by 10^-24). 40 | % Available only for elements. 41 | % 4 - 'mean free path' or 'mfp' - function returns mean free path (in cm) of 42 | % photon in the given material. 43 | % 5 - 'transmission' or 't' - fraction of protons absorbed by given thickness 44 | % of material 45 | % 6 - 'ln_T' - log of transmission 46 | % 7 - 'lac' - Linear Attenuation Coefficients in 1/cm same as 1/(Cross 47 | % Section) or mac*density. 48 | % 8 - 'half value layer' or 'hvl' - function returns half-value layer (in cm) of 49 | % photon in the given material . Available only for chemicals 50 | % recognized by 'CompoundProps' function (since density is needed). 51 | % 9 - 'tenth value layer' or 'tvl' - analogous to 'hvl' . 52 | % 4) Thickness - Thickness of material in cm. Either scalar or vector of 53 | % the same length as number of materials. Negative numbers indicate 54 | % mass thickness measured in g/cm^2 (density*thickness). Needed only 55 | % if energy spectrum is used or in case of Options set to 56 | % 'Transmission'. 57 | % Output : 58 | % X - output depends on 'Options' parameter. Columns always correspond 59 | % to the materials and rows correspond to energy. In case of spectrum 60 | % input only single row is returned. 61 | % 62 | % History: 63 | % Written by Jarek Tuszynski (SAIC), 2006 64 | % Updated by Jarek Tuszynski (Leidos), 2014, jaroslaw.w.tuszynski@leidos.com 65 | % Inspired by John Schweppe Mathematica code available at 66 | % http://library.wolfram.com/infocenter/MathSource/4267/ 67 | % Tables are based on NIST's XAAMDI and XCOM databases. See 68 | % PhotonAttenuationQ function for more details. 69 | % 70 | % Examples: 71 | % %% Plot Cross sections of elements for different energy photons 72 | % figure 73 | % Z = 1:100; % elements with Z in 1-100 range 74 | % E = logspace(log10(0.001), log10(20), 500); % define energy grid 75 | % X = PhotonAttenuation(Z, E, 'cross section'); 76 | % imagesc(log10(X)); colorbar; 77 | % title('Cross sections of elements for different energy photons'); 78 | % xlabel('Atomic Number of Elements'); 79 | % ylabel('Photon Energy in MeV'); 80 | % set(gca,'YTick',linspace(1, length(E), 10)); 81 | % set(gca,'YTickLabel',1e-3*round(1e3*logspace(log10(0.001), log10(20), 10))) 82 | % 83 | % %% Plot Photon Attenuation Coefficients, using different input styles 84 | % figure 85 | % E = logspace(log10(0.001), log10(20), 500); % define energy grid 86 | % Z = {'Concrete', 'Air', 'B(10)H(11)C(58)O(21)', 100, 'Ag'}; 87 | % mac = PhotonAttenuation(Z, E, 'mac'); 88 | % loglog(E, mac); 89 | % legend({'Concrete', 'Air', 'BPE-10', 'Fermium', 'Silver'}); 90 | % ylabel('Attenuation in cm^2/g'); 91 | % xlabel('Photon Energy in MeV'); 92 | % title('Photon Attenuation Coefficients for different materials'); 93 | mu=0; 94 | %% Process 'Energy' Input Parameter 95 | s = size(Energy); 96 | nEnergy = prod(s); 97 | Spectrum = []; 98 | if (min(s)==2) 99 | if (s(1)==2), Energy=Energy'; end 100 | Spectrum = Energy(:,2); 101 | Energy = Energy(:,1); 102 | Spectrum = Spectrum / trapz(Energy, Spectrum); % normalize spectrum 103 | nEnergy = 1; % this is a spectrum output will be an array instead of matrix 104 | end 105 | Energy = Energy(:); 106 | if (any(Energy<0)) 107 | idx = find(Energy<0); 108 | PlanckConstant = 4.1350e-021; % Planks constant in MeV*sec 109 | SpeedOfLight = 299792458E9; % in nano meters per second 110 | WaveLength = -Energy(idx); 111 | Energy(idx) = (PlanckConstant*SpeedOfLight) ./ WaveLength; 112 | end 113 | if (any(Energy<0.0009) || any(Energy>21)) 114 | warning('PhotonAttenuation:wrongEnergy',... 115 | 'Warning in PhotonAttenuation function: energy is outside of the recomended range from 0.001 MeV to 20 MeV'); 116 | end 117 | 118 | %% Process 'Material' Input Parameter 119 | if (ischar (Material)), Material = {Material}; end 120 | if (isnumeric(Material)), Material = num2cell(Material); end 121 | nMaterial = length(Material); 122 | 123 | %% Process 'Options' Input Parameter 124 | OptNames = {'mac','meac', 'cross section', 'mean free path', 'transmission', 'ln_t', 'lac', 'half value layer', 'tenth value layer', ... 125 | 'mac','meac', 'x', 'mfp', 't', 'log_t', 'lac', 'hvl', 'tvl'}; 126 | nOpt = length(OptNames)/2; 127 | if (nargin<3), Options = 1; end 128 | if (ischar(Options)) 129 | Options = find(strcmpi( Options, OptNames),1); 130 | if (Options>nOpt), Options=Options-nOpt; end 131 | else 132 | if (Options>nOpt), Options=[]; end 133 | end 134 | if (isempty(Options)) 135 | error(['Error in PhotonAttenuation function: Options parameter was not recognized: ', Options]); 136 | end 137 | param = (Options==2)+1; % param=2 if Option==2 and param=1 otherwise 138 | 139 | %% Process 'Thickness' Input Parameter 140 | if (nargin<4), Thickness=1; end 141 | if (length(Thickness)==1 && nMaterial>1) 142 | Thickness = repmat(Thickness(1), 1, nMaterial); 143 | end 144 | if (length(Thickness)>1 && nMaterial==1) 145 | nMaterial = length(Thickness); 146 | Material = repmat(Material(1), 1, nMaterial); 147 | end 148 | if (length(Thickness)~=nMaterial) 149 | error('Error in PhotonAttenuation function: missmatch between lengths or Material and Thickness arrays'); 150 | end 151 | 152 | %% Initialize output variables 153 | if (isempty(Spectrum)), X = zeros(nEnergy,nMaterial); 154 | else X = zeros(1 ,nMaterial); end 155 | u = 1.6605402E-24 ; % atomic mass unit (1/12 of the mass of C-12) 156 | barns = 1E24; % barns 157 | 158 | %% Main Loop: preform calculation for each material 159 | old_material = []; 160 | for iMat = 1:nMaterial 161 | %% Parse material 162 | % VARIABLES: 163 | % Z - array of element numbers contained in the material 164 | % Ratios - array of element ratios in the material 165 | % MatStr - string representation of the material 166 | material = Material{iMat}; 167 | if (isempty(material)) 168 | error('Error in PhotonAttenuation function: compound formula was empty'); 169 | end 170 | if (~isempty(old_material) && length(old_material)==length(material) && all(old_material==material)) 171 | if (Option<3 && isempty(Spectrum)) % a shortcut for common configuration 172 | X(:,iMat) = mu; 173 | continue; 174 | end 175 | end 176 | 177 | if (ischar(material)) % check if this is element name or known compound 178 | [Z, Ratios] = ParseChemicalFormula(material); 179 | if (isempty(Z)) 180 | error(['Error in PhotonAttenuation function: compound formula was not recognized: ', material]); 181 | end 182 | MatStr = material; 183 | elseif (isnumeric(material)) 184 | Z = material; 185 | Ratios = 1; 186 | MatStr = num2str(material); 187 | else 188 | error('Error in PhotonAttenuation function: compound formula was not recognized.'); 189 | end 190 | if (length(Z)>1 && Options==3) 191 | error('Error in PhotonAttenuation function: Cross section "Option" is only supported for elements.'); 192 | end 193 | 194 | %% Look up the data, average contributions of different elements and save 195 | mu = PhotonAttenuationQ(Z, Energy, param); 196 | old_material = material; % old_material will store the name of material for which we calculated mu 197 | Ratios = Ratios(:) / sum(Ratios); % normalize ratios so they add up to one 198 | % if mu is 2D (spectrum and compound) it will become 1D 199 | % if mu is 1D (because of compound) it will become scalar 200 | % if mu is 1D (because of spectrum) it will not change 201 | % if mu is a scalar (monoenergetic & element) it will not change 202 | mu = mu * Ratios; 203 | 204 | %% Lookup density and atomic molar mass if needed 205 | if (Options>=3 || ~isempty(Spectrum)) 206 | PP = PhysProps(material); 207 | Density = PP{1,2}; 208 | A = Z/PP{1,1}; % atomic molar mass in g/mol 209 | end 210 | 211 | %% Calculate Transmission if needed 212 | if (Options==5 || Options==6 || ~isempty(Spectrum)) % a shortcut for common configuration 213 | if(Thickness(iMat)>0), 214 | MassThick = Thickness(iMat)*Density; % mass thickness measured in g/cm^2 215 | else 216 | MassThick = -Thickness(iMat); 217 | end % user provided linear thickness 218 | if ~isnan(MassThick) 219 | MassThick = max(MassThick, 1e-6); 220 | end 221 | T = exp(-mu*MassThick); % always convert to transmission 222 | end 223 | 224 | %% if Energy has a spectrum than integrate 225 | if (~isempty(Spectrum)) 226 | T = trapz(Energy, T.*Spectrum); % integrate over energy (T become a scalar) 227 | mac = -log(T)/MassThick; 228 | else 229 | mac = mu; 230 | end 231 | 232 | %% Cast output in a chosen format 233 | switch (Options) 234 | case {1,2} % mac & meac 235 | x = mac; 236 | case 3 % 'cross section' 237 | x = mac * (barns*u*A); 238 | case 4 % 'mean free path' 239 | x = 1./(mac*Density); 240 | case 5 % 'transmission' 241 | x = T; 242 | case 6 % 'log T' 243 | x = -log(T); 244 | case 7 % 'linear attenuation coefficiant' 245 | x = mac*Density; 246 | case 8 % 'half-value layer' 247 | x = -log(0.5)./(mac*Density); 248 | case 9 % 'tenth-value layer' 249 | x = -log(0.1)./(mac*Density); 250 | end 251 | X(:,iMat) = x; 252 | if (any(isnan(x))) 253 | error(['Error in PhotonAttenuation function: Physical properties of "',... 254 | MatStr,'" not found in PhysProps function.']); 255 | end 256 | 257 | end 258 | -------------------------------------------------------------------------------- /graphics/private/DisplayConsole.m: -------------------------------------------------------------------------------- 1 | function DisplayConsole(hfig,data,lowhigh) 2 | 3 | displims = double([min(data(:)),max(data(:))]); 4 | if isempty(lowhigh), lowhigh = displims; end 5 | maxval = size(data); 6 | bcolor = 0.5*[1 1 1]; 7 | fcolor = [1,0.8431,0]; 8 | 9 | uipos = get(hfig,'Position'); 10 | uipos = [10 10 200 uipos(4)-20]; 11 | h1 = uipanel(... 12 | 'Units','pixels',... 13 | 'Position',uipos,... 14 | 'BackgroundColor',bcolor,... 15 | 'BorderType','none',... 16 | 'BorderWidth',2,... 17 | 'Tag','ConsolePanel'); 18 | 19 | % Check boxes 20 | uipos = [1/20 1-1/4+2/90 1-1/10,1/4-3/90]; 21 | h2 = uipanel(... 22 | 'Parent',h1,... 23 | 'Position',uipos,... 24 | 'Title','Options',... 25 | 'FontWeight','bold',... 26 | 'ForegroundColor',fcolor,... 27 | 'BackgroundColor',bcolor,... 28 | 'BorderType','etchedin',... 29 | 'BorderWidth',1); 30 | 31 | uipos = [1/20 1/20 2/5 1/5]; 32 | uicontrol(... 33 | 'Parent',h2,... 34 | 'Units','normalized',... 35 | 'BackgroundColor',bcolor,... 36 | 'ForegroundColor',[1 1 1],... 37 | 'Callback',@UpdateDisplay,... 38 | 'Position',uipos,... 39 | 'Style','checkbox',... 40 | 'Value',0,... 41 | 'Enable','off',... 42 | 'String','Smooth',... 43 | 'Tag','Smooth'); 44 | 45 | uipos(2) = uipos(2)+1/5; 46 | uicontrol(... 47 | 'Parent',h2,... 48 | 'Units','normalized',... 49 | 'BackgroundColor',bcolor,... 50 | 'ForegroundColor',[1 1 1],... 51 | 'Position',uipos,... 52 | 'Style','checkbox',... 53 | 'Enable','off',... 54 | 'String','Coronal',... 55 | 'Tag','Coronal'); 56 | 57 | uipos(2) = uipos(2)+1/5; 58 | %uipos(1) = uipos(1)+1/2; 59 | uicontrol(... 60 | 'Parent',h2,... 61 | 'Units','normalized',... 62 | 'BackgroundColor',bcolor,... 63 | 'ForegroundColor',[1 1 1],... 64 | 'Position',uipos,... 65 | 'Style','checkbox',... 66 | 'Enable','off',... 67 | 'String','Sagittal',... 68 | 'Tag','Sagittal'); 69 | 70 | uipos = uipos+[0 1/5 2/5 0]; 71 | %uipos = uipos+[-1/2 1/5 2/5 0]; 72 | hpnt = uicontrol(... 73 | 'Parent',h2,... 74 | 'Units','normalized',... 75 | 'BackgroundColor',bcolor,... 76 | 'ForegroundColor',[1 1 1],... 77 | 'Callback',@ShowPointCallback,... 78 | 'Position',uipos,... 79 | 'Style','checkbox',... 80 | 'Enable','off',... 81 | 'Value',0,... 82 | 'String','Point',... 83 | 'Tag','ShowPoint'); 84 | 85 | % Graylevel adjustments 86 | uipos = [1/20 1/2+1/180 1-1/10,1/4]; 87 | h3 = uipanel(... 88 | 'Parent',h1,... 89 | 'Position',uipos,... 90 | 'Title','Intensity',... 91 | 'FontWeight','bold',... 92 | 'ForegroundColor',fcolor,... 93 | 'BackgroundColor',bcolor,... 94 | 'BorderType','etchedin',... 95 | 'BorderWidth',1); 96 | 97 | uipos = [1/20 1/13 9/30 1/8]; 98 | uicontrol(... 99 | 'Parent',h3,... 100 | 'Units','normalized',... 101 | 'Callback',{@DispMinusCallback},... 102 | 'Position',uipos,... 103 | 'String','-'); 104 | 105 | uipos(1) = uipos(1)+uipos(3); 106 | uicontrol(... 107 | 'Parent',h3,... 108 | 'Units','normalized',... 109 | 'Callback',{@DispPlusCallback},... 110 | 'Position',uipos,... 111 | 'String','+'); 112 | 113 | uipos(1) = uipos(1)+uipos(3); 114 | uicontrol(... 115 | 'Parent',h3,... 116 | 'Units','normalized',... 117 | 'Callback',{@DispResetCallback},... 118 | 'Position',uipos,... 119 | 'String','*'); 120 | 121 | uipos = [1/20 uipos(2)+1/6+1/90 3*uipos(3) 1/10]; 122 | uicontrol(... 123 | 'Parent',h3,... 124 | 'BackgroundColor',0.6*[1 1 1],... 125 | 'Units','normalized',... 126 | 'Callback',{@DispWinCallback},... 127 | 'Position',uipos,... 128 | 'String','high',... 129 | 'Style','slider',... 130 | 'SliderStep',[0.005,0.05],... 131 | 'Value',lowhigh(2),... 132 | 'Min',displims(1),... 133 | 'Max',displims(2),... 134 | 'UserData',displims,... 135 | 'Tag','Range'); 136 | 137 | uipos(2) = uipos(2)+1/10; 138 | uicontrol(... 139 | 'Parent',h3,... 140 | 'BackgroundColor',0.3*[1 1 1],... 141 | 'Units','normalized',... 142 | 'Callback',{@DispWinCallback},... 143 | 'Position',uipos,... 144 | 'String','low',... 145 | 'Style','slider',... 146 | 'SliderStep',[0.005,0.05],... 147 | 'Value',lowhigh(1),... 148 | 'Min',displims(1),... 149 | 'Max',displims(2),... 150 | 'Tag','Range',... 151 | 'UserData',displims); 152 | 153 | uipos(2) = uipos(2)+1/8; 154 | uipos(4) = 1/7.5; 155 | uicontrol(... 156 | 'Parent',h3,... 157 | 'Units','normalized',... 158 | 'BackgroundColor','w',... 159 | 'HorizontalAlignment','right',... 160 | 'Callback',{@EditLimitCallback,2},... 161 | 'Position',uipos+[9/20 0 -9/20 0],... 162 | 'String',num2str(lowhigh(2)),... 163 | 'Style','edit',... 164 | 'Tag','RangeText'); 165 | 166 | uicontrol(... 167 | 'Parent',h3,... 168 | 'Units','normalized',... 169 | 'BackgroundColor','w',... 170 | 'HorizontalAlignment','left',... 171 | 'Callback',{@EditLimitCallback,1},... 172 | 'Position',uipos+[0 0 -9/20 0],... 173 | 'String',num2str(lowhigh(1)),... 174 | 'Style','edit',... 175 | 'Tag','RangeText'); 176 | 177 | uipos(2) = uipos(2)+1/6; 178 | uipos(3) = 2/5-2/90; 179 | uicontrol(... 180 | 'Parent',h3,... 181 | 'Units','normalized',... 182 | 'ForegroundColor','w',... 183 | 'BackgroundColor',bcolor,... 184 | 'HorizontalAlignment','left',... 185 | 'Position',uipos,... 186 | 'String','Colormap: ',... 187 | 'Style','text'); 188 | 189 | uipos = uipos+[uipos(3),3/90,1/8+1/90,0]; 190 | uicontrol(... 191 | 'Parent',h3,... 192 | 'Units','normalized',... 193 | 'BackgroundColor','w',... 194 | 'Position',uipos,... 195 | 'Style','popup',... 196 | 'Value',3,... 197 | 'String','Brain|Bone|Gray|Hot Metal|Rainbow|Spectral',... 198 | 'Callback',@SetColormapCallback); 199 | 200 | if ndims(data)==2 201 | axes(... 202 | 'Parent',h1,... 203 | 'Units','normalized',... 204 | 'Position',[0 0 3/4 1/2-3/90],... 205 | 'Visible','off',... 206 | 'Tag','ColorBar'); 207 | %colorbar('north','XTickLabel',{}); 208 | colorbar; %('YTickLabel',[lowhigh(1),lowhigh(2)]); 209 | return; 210 | end 211 | 212 | set(hpnt,'Value',1,'Enable','on'); 213 | 214 | uipos = [1/20 1/90 1-1/10,1/2-2/90]; 215 | h4 = uipanel(... 216 | 'Parent',h1,... 217 | 'Position',uipos,... 218 | 'Title','Position',... 219 | 'FontWeight','bold',... 220 | 'ForegroundColor',fcolor,... 221 | 'BackgroundColor',bcolor,... 222 | 'BorderType','etchedin',... 223 | 'BorderWidth',1); 224 | 225 | % Point sliders 226 | uipos = [1/20+18/30 1/20 9/30 1/15]; 227 | uicontrol(... 228 | 'Parent',h4,... 229 | 'Units','normalized',... 230 | 'BackgroundColor','w',... 231 | 'HorizontalAlignment','right',... 232 | 'Callback',{@EditPointCallback,3},... 233 | 'Position',uipos,... 234 | 'String',num2str(maxval(3)/2),... 235 | 'Style','edit',... 236 | 'Tag','PointText'); 237 | 238 | uipos(1) = uipos(1)-9/30; 239 | uicontrol(... 240 | 'Parent',h4,... 241 | 'Units','normalized',... 242 | 'BackgroundColor','w',... 243 | 'HorizontalAlignment','right',... 244 | 'Callback',{@EditPointCallback,2},... 245 | 'Position',uipos,... 246 | 'String',num2str(maxval(2)/2),... 247 | 'Style','edit',... 248 | 'Tag','PointText'); 249 | 250 | uipos(1) = uipos(1)-9/30; 251 | uicontrol(... 252 | 'Parent',h4,... 253 | 'Units','normalized',... 254 | 'BackgroundColor','w',... 255 | 'HorizontalAlignment','right',... 256 | 'Callback',{@EditPointCallback,1},... 257 | 'Position',uipos,... 258 | 'String',num2str(maxval(1)/2),... 259 | 'Style','edit',... 260 | 'Tag','PointText'); 261 | 262 | uipos = [uipos(1)+22/30 uipos(2)+1/10, 1/12, 15/20]; 263 | uicontrol(... 264 | 'Parent',h4,... 265 | 'BackgroundColor','r',... 266 | 'Units','normalized',... 267 | 'Callback',@UpdateDisplay,... 268 | 'Position',uipos,... 269 | 'String','zcoord',... 270 | 'Style','slider',... 271 | 'SliderStep',[1,10]/maxval(3),... 272 | 'Value',maxval(3)/2,... 273 | 'Min',1,... 274 | 'Max',maxval(3),... 275 | 'Tag','Point'); 276 | 277 | uipos(1) = uipos(1)-9/30; 278 | uicontrol(... 279 | 'Parent',h4,... 280 | 'BackgroundColor','g',... 281 | 'Units','normalized',... 282 | 'Callback',@UpdateDisplay,... 283 | 'Position',uipos,... 284 | 'String','ycoord',... 285 | 'Style','slider',... 286 | 'SliderStep',[1,10]/maxval(1),... 287 | 'Value',maxval(1)/2,... 288 | 'Min',1,... 289 | 'Max',maxval(1),... 290 | 'Tag','Point'); 291 | 292 | uipos(1) = uipos(1)-9/30; 293 | uicontrol(... 294 | 'Parent',h4,... 295 | 'BackgroundColor','b',... 296 | 'Unit','normalized',... 297 | 'Callback',@UpdateDisplay,... 298 | 'Position',uipos,... 299 | 'String','xcoord',... 300 | 'Style','slider',... 301 | 'SliderStep',[1,10]/maxval(2),... 302 | 'Value',maxval(2)/2,... 303 | 'Min',1,... 304 | 'Max',maxval(2),... 305 | 'Tag','Point'); 306 | 307 | uipos = [1/25 uipos(2) 1/10 1/18]; 308 | uicontrol(... 309 | 'Parent',h4,... 310 | 'Units','normalized',... 311 | 'ForegroundColor','w',... 312 | 'BackgroundColor',bcolor,... 313 | 'HorizontalAlignment','right',... 314 | 'Position',uipos,... 315 | 'String','X',... 316 | 'Style','text'); 317 | 318 | uipos(1) = uipos(1)+9/30; 319 | uicontrol(... 320 | 'Parent',h4,... 321 | 'Units','normalized',... 322 | 'ForegroundColor','w',... 323 | 'BackgroundColor',bcolor,... 324 | 'HorizontalAlignment','right',... 325 | 'Position',uipos,... 326 | 'String','Y',... 327 | 'Style','text'); 328 | 329 | uipos(1) = uipos(1)+9/30; 330 | uicontrol(... 331 | 'Parent',h4,... 332 | 'Units','normalized',... 333 | 'ForegroundColor','w',... 334 | 'BackgroundColor',bcolor,... 335 | 'HorizontalAlignment','right',... 336 | 'Position',uipos,... 337 | 'String','Z',... 338 | 'Style','text'); 339 | 340 | 341 | % -------------------------------------------------------------------- 342 | function EditLimitCallback(hobj,evdt,indx) 343 | 344 | handles = guidata(hobj); 345 | set(handles.Range(indx),'Value',str2num(get(hobj,'String'))); 346 | UpdateDisplay(hobj,evdt); 347 | 348 | 349 | % -------------------------------------------------------------------- 350 | function EditPointCallback(hobj,evdt,indx) 351 | 352 | handles = guidata(hobj); 353 | set(handles.Point(indx),'Value',str2num(get(hobj,'String'))); 354 | UpdateDisplay(hobj,evdt); 355 | 356 | 357 | % -------------------------------------------------------------------- 358 | function DispWinCallback(hobj,evdt) 359 | 360 | handles = guidata(hobj); 361 | lowhigh = get(handles.Range,'Value'); 362 | set(handles.RangeText,{'String'},{num2str(lowhigh{1});num2str(lowhigh{2})}); 363 | UpdateDisplay(hobj,evdt); 364 | 365 | 366 | % -------------------------------------------------------------------- 367 | function DispMinusCallback(hobj,evdt) 368 | 369 | handles = guidata(hobj); 370 | lowhigh = cell2mat(get(handles.Range,'Value')); 371 | [low,high] = deal(min(lowhigh),max(lowhigh)); 372 | set(handles.Range,'Min',low); 373 | set(handles.Range,'Max',high); 374 | 375 | 376 | % -------------------------------------------------------------------- 377 | function DispPlusCallback(hobj,evdt) 378 | 379 | handles = guidata(hobj); 380 | lowhigh = cell2mat(get(handles.Range,'Value')); 381 | range = get(handles.Range(1),'UserData'); 382 | extent = diff(lowhigh)*10; 383 | low = max(lowhigh(1)-extent,range(1)); 384 | high = min(lowhigh(2)+extent,range(2)); 385 | [low,high] = deal(min(low,high),max(low,high)); 386 | set(handles.Range,'Min',low); 387 | set(handles.Range,'Max',high); 388 | 389 | 390 | % -------------------------------------------------------------------- 391 | function DispResetCallback(hobj,evdt) 392 | 393 | handles = guidata(hobj); 394 | range = get(handles.Range(1),'UserData'); 395 | set(handles.Range,'Min',range(1)); 396 | set(handles.Range,'Max',range(2)); 397 | set(handles.Range,{'Value'},{range(1);range(2)}); 398 | set(handles.RangeText,{'String'},{num2str(range(1));num2str(range(2))}); 399 | UpdateDisplay(hobj,evdt); 400 | 401 | 402 | % -------------------------------------------------------------------- 403 | function SetColormapCallback(hobj,evdt) 404 | 405 | value = get(hobj,'Value'); 406 | switch value 407 | case 1 408 | colormap(brain); 409 | case 2 410 | colormap(bone); 411 | case 3 412 | colormap(gray); 413 | case 4 414 | colormap(hotmetal); 415 | case 5 416 | colormap(rainbow); 417 | case 6 418 | colormap(spectral); 419 | end 420 | UpdateDisplay(hobj,evdt); 421 | 422 | 423 | % -------------------------------------------------------------------- 424 | function ShowPointCallback(hobj,evdt) 425 | 426 | handles = guidata(hobj); 427 | if get(hobj,'Value') 428 | set(handles.ImageLine,'Visible','on'); 429 | else 430 | set(handles.ImageLine,'Visible','off'); 431 | end 432 | -------------------------------------------------------------------------------- /PhysProps.m: -------------------------------------------------------------------------------- 1 | function P = PhysProps(Name) 2 | %PhysProps returns physical properties of selected materials. 3 | % 4 | % P = PhysProps(Name) returns physical properties of selected materials. 5 | % Input: 6 | % - Name - name (string) or names (cell array) identifying the material. 7 | % Possible name formats: 8 | % * Chemical name, like Carbon, Benzine, or Blood 9 | % * Chemical formula, like C or H2O (caution in case of compound 10 | % formulas there can be a single formula for different chemicals with 11 | % unique properties - only the first one will be returned). 12 | % * In case of elements input of atomic numbers in 1-100 is also allowed. 13 | % 14 | % Output: 15 | % - P - 2D cell array: each row corresponds to one 'name', columns are as 16 | % follows: 17 | % * column 1 - Z/A - mean ratio of atomic number to mass 18 | % * column 2 - density in g/cm^3 19 | % * column 3 - material formula guaranteed to be recognized by 20 | % 'PhotonAttenuation' and 'ParseChemicalFormula' functions 21 | % * column 4 - name of the material (name used in NIST tables) 22 | % 23 | % P = PhysProps('Compound Names') will return a list of about 200 compounds 24 | % and mixtures. 25 | % 26 | % P = PhysProps('Element Data') will return a list of element symbols and 27 | % Z/A's. 28 | 29 | % Sources: 30 | % - elements: http://physics.nist.gov/PhysRefData/XrayMassCoef/tab1.html 31 | % - materials: http://physics.nist.gov/cgi-bin/Star/compos.pl 32 | % 33 | % See Also: 34 | % ParseChemicalFormula, PhotonAttenuation, PhotonAttenuationQ 35 | % 36 | % Written by Jarek Tuszynski (SAIC), 2006 37 | % 38 | % Examples: 39 | % PhysProps({'H', 'Water', 'H2O', 82, 'lead', 'skin'}) 40 | % PhysProps('Compound Names') % list of aviable names 41 | % PhysProps('Element Data') % list of element symbols and Z/A 42 | % PhysProps('All Data') % returns the database variable 43 | % 44 | % % get properties of concrete 45 | % X = PhysProps('Concrete'); 46 | % [Z R] = ParseChemicalFormula(X{3}); 47 | % MFP = PhotonAttenuation(X{3}, 0.662, 'mean free path'); 48 | % Concrete.Density = X{2}; 49 | % Concrete.Z_A = X{1}; 50 | % Concrete.ElementZ = Z'; 51 | % Concrete.ElementRatio = R'; 52 | % Concrete.MeaFreePath = MFP; % of gammas from Cesium-137 source 53 | % Concrete 54 | 55 | %% ----------------------------------------------------------------------- 56 | persistent Props 57 | % Z/A Density Names 58 | Props = {... 59 | 0.99212, 8.375e-005, 'H', 'Hydrogen', '' ;... 60 | 0.49968, 1.663e-004, 'He', 'Helium', '' ;... 61 | 0.43221, 5.340e-001, 'Li', 'Lithium', '' ;... 62 | 0.44384, 1.848e+000, 'Be', 'Beryllium', '' ;... 63 | 0.46245, 2.370e+000, 'B', 'Boron', '' ;... 64 | 0.49954, 1.700e+000, 'C', 'Carbon', '' ;... 65 | 0.49976, 1.165e-003, 'N', 'Nitrogen', '' ;... 66 | 0.50002, 1.332e-003, 'O', 'Oxygen', '' ;... 67 | 0.47372, 1.580e-003, 'F', 'Fluorine', '' ;... 68 | 0.49555, 8.385e-004, 'Ne', 'Neon', '' ;... 69 | 0.47847, 9.710e-001, 'Na', 'Sodium', '' ;... 70 | 0.49373, 1.740e+000, 'Mg', 'Magnesium', '' ;... 71 | 0.48181, 2.699e+000, 'Al', 'Aluminum', '' ;... 72 | 0.49848, 2.330e+000, 'Si', 'Silicon', '' ;... 73 | 0.48428, 2.200e+000, 'P', 'Phosphorus', '' ;... 74 | 0.49897, 2.000e+000, 'S', 'Sulfur', '' ;... 75 | 0.47951, 2.995e-003, 'Cl', 'Chlorine', '' ;... 76 | 0.45059, 1.662e-003, 'Ar', 'Argon', '' ;... 77 | 0.48595, 8.620e-001, 'K', 'Potassium', '' ;... 78 | 0.49903, 1.550e+000, 'Ca', 'Calcium', '' ;... 79 | 0.46712, 2.989e+000, 'Sc', 'Scandium', '' ;... 80 | 0.45948, 4.540e+000, 'Ti', 'Titanium', '' ;... 81 | 0.45150, 6.110e+000, 'V', 'Vanadium', '' ;... 82 | 0.46157, 7.180e+000, 'Cr', 'Chromium', '' ;... 83 | 0.45506, 7.440e+000, 'Mn', 'Manganese', '' ;... 84 | 0.46556, 7.874e+000, 'Fe', 'Iron', '' ;... 85 | 0.45815, 8.900e+000, 'Co', 'Cobalt', '' ;... 86 | 0.47708, 8.902e+000, 'Ni', 'Nickel', '' ;... 87 | 0.45636, 8.960e+000, 'Cu', 'Copper', '' ;... 88 | 0.45879, 7.133e+000, 'Zn', 'Zinc', '' ;... 89 | 0.44462, 5.904e+000, 'Ga', 'Gallium', '' ;... 90 | 0.44071, 5.323e+000, 'Ge', 'Germanium', '' ;... 91 | 0.44046, 5.730e+000, 'As', 'Arsenic', '' ;... 92 | 0.43060, 4.500e+000, 'Se', 'Selenium', '' ;... 93 | 0.43803, 7.072e-003, 'Br', 'Bromine', '' ;... 94 | 0.42959, 3.478e-003, 'Kr', 'Krypton', '' ;... 95 | 0.43291, 1.532e+000, 'Rb', 'Rubidium', '' ;... 96 | 0.43369, 2.540e+000, 'Sr', 'Strontium', '' ;... 97 | 0.43867, 4.469e+000, 'Y', 'Yttrium', '' ;... 98 | 0.43848, 6.506e+000, 'Zr', 'Zirconium', '' ;... 99 | 0.44130, 8.570e+000, 'Nb', 'Niobium', '' ;... 100 | 0.43777, 1.022e+001, 'Mo', 'Molybdenum', '' ;... 101 | 0.43919, 1.150e+001, 'Tc', 'Technetium', '' ;... 102 | 0.43534, 1.241e+001, 'Ru', 'Ruthenium', '' ;... 103 | 0.43729, 1.241e+001, 'Rh', 'Rhodium', '' ;... 104 | 0.43225, 1.202e+001, 'Pd', 'Palladium', '' ;... 105 | 0.43572, 1.050e+001, 'Ag', 'Silver', '' ;... 106 | 0.42700, 8.650e+000, 'Cd', 'Cadmium', '' ;... 107 | 0.42676, 7.310e+000, 'In', 'Indium', '' ;... 108 | 0.42120, 7.310e+000, 'Sn', 'Tin', '' ;... 109 | 0.41889, 6.691e+000, 'Sb', 'Antimony', '' ;... 110 | 0.40752, 6.240e+000, 'Te', 'Tellurium', '' ;... 111 | 0.41764, 4.930e+000, 'I', 'Iodine', '' ;... 112 | 0.41130, 5.485e-003, 'Xe', 'Xenon', '' ;... 113 | 0.41383, 1.873e+000, 'Cs', 'Cesium', '' ;... 114 | 0.40779, 3.500e+000, 'Ba', 'Barium', '' ;... 115 | 0.41035, 6.154e+000, 'La', 'Lanthanum', '' ;... 116 | 0.41395, 6.657e+000, 'Ce', 'Cerium', '' ;... 117 | 0.41871, 6.710e+000, 'Pr', 'Praseodymium', '' ;... 118 | 0.41597, 6.900e+000, 'Nd', 'Neodymium', '' ;... 119 | 0.42094, 7.220e+000, 'Pm', 'Promethium', '' ;... 120 | 0.41234, 7.460e+000, 'Sm', 'Samarium', '' ;... 121 | 0.41457, 5.243e+000, 'Eu', 'Europium', '' ;... 122 | 0.40699, 7.900e+000, 'Gd', 'Gadolinium', '' ;... 123 | 0.40900, 8.229e+000, 'Tb', 'Terbium', '' ;... 124 | 0.40615, 8.550e+000, 'Dy', 'Dysprosium', '' ;... 125 | 0.40623, 8.795e+000, 'Ho', 'Holmium', '' ;... 126 | 0.40655, 9.066e+000, 'Er', 'Erbium', '' ;... 127 | 0.40844, 9.321e+000, 'Tm', 'Thulium', '' ;... 128 | 0.40453, 6.730e+000, 'Yb', 'Ytterbium', '' ;... 129 | 0.40579, 9.840e+000, 'Lu', 'Lutetium', '' ;... 130 | 0.40338, 1.331e+001, 'Hf', 'Hafnium', '' ;... 131 | 0.40343, 1.665e+001, 'Ta', 'Tantalum', '' ;... 132 | 0.40250, 1.930e+001, 'W', 'Tungsten', '' ;... 133 | 0.40278, 2.102e+001, 'Re', 'Rhenium', '' ;... 134 | 0.39958, 2.257e+001, 'Os', 'Osmium', '' ;... 135 | 0.40058, 2.242e+001, 'Ir', 'Iridium', '' ;... 136 | 0.39984, 2.145e+001, 'Pt', 'Platinum', '' ;... 137 | 0.40108, 1.932e+001, 'Au', 'Gold', '' ;... 138 | 0.39882, 1.355e+001, 'Hg', 'Mercury', '' ;... 139 | 0.39631, 1.172e+001, 'Tl', 'Thallium', '' ;... 140 | 0.39575, 1.135e+001, 'Pb', 'Lead', '' ;... 141 | 0.39717, 9.747e+000, 'Bi', 'Bismuth', '' ;... 142 | 0.40195, 9.320e+000, 'Po', 'Polonium', '' ;... 143 | 0.40479, 1.000e+001, 'At', 'Astatine', '' ;... 144 | 0.38736, 9.066e-003, 'Rn', 'Radon', '' ;... 145 | 0.39010, 1.000e+001, 'Fr', 'Francium', '' ;... 146 | 0.38934, 5.000e+000, 'Ra', 'Radium', '' ;... 147 | 0.39202, 1.007e+001, 'Ac', 'Actinium', '' ;... 148 | 0.38787, 1.172e+001, 'Th', 'Thorium', '' ;... 149 | 0.39388, 1.537e+001, 'Pa', 'Protactinium', '' ;... 150 | 0.38651, 1.895e+001, 'U', 'Uranium', '' ;... 151 | 0.39233, 2.030e+001, 'Np', 'Neptunium', '' ;... 152 | 0.38514, 1.984e+001, 'Pu', 'Plutonium', '' ;... 153 | 0.39085, 1.370e+001, 'Am', 'Americium', '' ;... 154 | 0.38855, 1.350e+001, 'Cm', 'Curium', '' ;... 155 | 0.39260, 1.400e+001, 'Bk', 'Berkelium', '' ;... 156 | 0.39031, 1.000e+001, 'Cf', 'Californium', '' ;... 157 | 0.39273, 8.840e+000, 'Es', 'Einsteinium', '' ;... 158 | 0.38896, NaN , 'Fm', 'Fermium', '' ;... % last element 159 | 0.48181, 2.699e+000, 'Al', 'Aluminium', 'Al' ;... % Alternative spelling 160 | 0.49897, 2.000e+000, 'S', 'Sulphur' , 'S' ;... % Alternative spelling 161 | 0.41383, 1.873e+000, 'Cs', 'Caesium' , 'Cs' ;... % Alternative spelling 162 | 0.49954, 1.700e+000, 'C', 'Graphite' , 'C' ;... % Alternative form 163 | 0.49954, 3.513e+000, 'C', 'Diamond' , 'C' ;... % Alternative form 164 | 0.49954, 2.000e+001, 'C', 'Carbon, Amorphous', 'C' ;... % Alternative form 165 | 0.54903, 1.127e+000, 'A-150', 'A-150 TISSUE-EQUIVALENT PLASTIC', 'H(0.101327)C(0.775501)N(0.035057)O(0.052316)F(0.017422)Ca(0.018378)' ;... 166 | 0.55097, 7.899e-001, '', 'ACETONE', 'C3H6O' ;... 167 | 0.53768, 1.097e-003, '', 'ACETYLENE', 'C2H2' ;... 168 | 0.51803, 1.350e+000, '', 'ADENINE', 'C5H5N5' ;... 169 | 0.55847, 9.200e-001, 'ADIPOSE TISSUE', 'ADIPOSE TISSUE (ICRP)', 'H(0.119477)C(0.637240)N(0.007970)O(0.232333)Na(0.000500)Mg(0.000020)P(0.000160)S(0.000730)Cl(0.001190)K(0.000320)Ca(0.000020)Fe(0.000020)Zn(0.000020)' ;... 170 | 0.49919, 1.205e-003, 'Air', 'AIR, DRY (NEAR SEA LEVEL)', 'C(0.000124)N(0.755267)O(0.231781)Ar(0.012827)' ;... 171 | 0.53876, 1.420e+000, '', 'ALANINE', 'C3H7NO2' ;... 172 | 0.49038, 3.970e+000, '', 'ALUMINUM OXIDE', 'Al2O3' ;... 173 | 0.55178, 1.100e+000, '', 'AMBER', 'C10H16O' ;... 174 | 0.51129, 8.260e-004, '', 'AMMONIA', 'NH3' ;... 175 | 0.53690, 1.024e+000, '', 'ANILINE', 'C6H7N' ;... 176 | 0.52740, 1.283e+000, '', 'ANTHRACENE', 'C14H10' ;... 177 | 0.52740, 1.450e+000, 'B-100', 'B-100 BONE-EQUIVALENT PLASTIC', 'H(0.065471)C(0.536945)N(0.021500)O(0.032085)F(0.167411)Ca(0.176589)' ;... 178 | 0.52792, 1.250e+000, '', 'BAKELITE', 'H(0.057441)C(0.774591)O(0.167968)' ;... 179 | 0.42207, 4.890e+000, '', 'BARIUM FLUORIDE', 'BaF2' ;... 180 | 0.44561, 4.500e+000, '', 'BARIUM SULFATE', 'BaSO4' ;... 181 | 0.53768, 8.787e-001, '', 'BENZENE', 'C6H6' ;... 182 | 0.47978, 3.010e+000, '', 'BERYLLIUM OXIDE', 'BeO' ;... 183 | 0.40961, 7.130e+000, 'BGO', 'BISMUTH GERMANIUM OXIDE', 'Bi12GeO20' ;... 184 | 0.54995, 1.060e+000, 'Blood', 'BLOOD (ICRP)', 'H(0.101866)C(0.100020)N(0.029640)O(0.759414)Na(0.001850)Mg(0.000040)Si(0.000030)P(0.000350)S(0.001850)Cl(0.002780)K(0.001630)Ca(0.000060)Fe(0.000460)Zn(0.000010)' ;... 185 | 0.53010, 1.850e+000, 'COMPACT BONE', 'BONE, COMPACT (ICRU)', 'H(0.063984)C(0.278000)N(0.027000)O(0.410016)Mg(0.002000)P(0.070000)S(0.002000)Ca(0.147000)' ;... 186 | 0.52130, 1.850e+000, 'CORTICAL BONE', 'BONE, CORTICAL (ICRP)', 'H(0.047234)C(0.144330)N(0.041990)O(0.446096)Mg(0.002200)P(0.104970)S(0.003150)Ca(0.209930)Zn(0.000100)' ;... 187 | 0.47058, 2.520e+000, '', 'BORON CARBIDE', 'B4C' ;... 188 | 0.48838, 1.812e+000, '', 'BORON OXIDE', 'B2O3' ;... 189 | 0.55423, 1.030e+000, 'Brain', 'BRAIN (ICRP)', 'H(0.110667)C(0.125420)N(0.013280)O(0.737723)Na(0.001840)Mg(0.000150)P(0.003540)S(0.001770)Cl(0.002360)K(0.003100)Ca(0.000090)Fe(0.000050)Zn(0.000010)' ;... 190 | 0.55196, 1.020e+000, 'Breast', 'Breast Tissue (ICRU)', 'H(0.106)C(0.332)N(0.03)O(0.527)Na(0.001)P(0.001)S(0.002)Cl(0.001)' ;... 191 | 0.58497, 2.493e-003, '', 'BUTANE', 'C4H10' ;... 192 | 0.56663, 8.098e-001, 'n-BUTANOL', 'N-BUTYL ALCOHOL', 'C4H10O' ;... 193 | 0.49969, 1.760e+000, 'C-552', 'C-552 AIR-EQUIVALENT PLASTIC', 'H(0.024680)C(0.501610)O(0.004527)F(0.465209)Si(0.003973)' ;... 194 | 0.41665, 6.200e+000, '', 'CADMIUM TELLURIDE', 'CdTe' ;... 195 | 0.40749, 7.900e+000, 'CWO', 'CADMIUM TUNGSTATE', 'CdWO4' ;... 196 | 0.49955, 2.800e+000, '', 'CALCIUM CARBONATE', 'CaCO3' ;... 197 | 0.48670, 3.180e+000, '', 'CALCIUM FLUORIDE', 'CaF2' ;... 198 | 0.49929, 3.300e+000, '', 'CALCIUM OXIDE', 'O(0.285299)Ca(0.714701)' ;... 199 | 0.49950, 2.960e+000, '', 'CALCIUM SULFATE', 'CaSO4' ;... 200 | 0.40936, 6.062e+000, '', 'CALCIUM TUNGSTATE', 'CaWO4' ;... 201 | 0.49989, 1.842e-003, '', 'CARBON DIOXIDE', 'CO2' ;... 202 | 0.48107, 1.594e+000, '', 'CARBON TETRACHLORIDE', 'CCl4' ;... 203 | 0.53040, 1.420e+000, 'CELLOPHANE', 'CELLULOSE ACETATE, CELLOPHANE', 'C6H10O5' ;... 204 | 0.53279, 1.200e+000, 'CAB', 'CELLULOSE ACETATE BUTYRATE', 'C15H22O8' ;... 205 | 0.51424, 1.490e+000, 'Nitrocellulose', 'CELLULOSE NITRATE', 'C6H8N2O9' ;... 206 | 0.55278, 1.030e+000, '', 'CERIC SULFATE DOSIMETER SOLUTION', 'H(0.107596)N(0.000800)O(0.874976)S(0.014627)Ce(0.002001)' ;... 207 | 0.42132, 4.115e+000, '', 'CESIUM FLUORIDE', 'CsF' ;... 208 | 0.41569, 4.510e+000, '', 'CESIUM IODIDE', 'CsI' ;... 209 | 0.48734, 1.106e+000, '', 'CHLOROBENZENE', 'C6H5Cl' ;... 210 | 0.51498, 1.483e+000, '', 'CHLOROFORM', 'CHCl3' ;... 211 | 0.50274, 2.300e+000, 'Portland Concrete', 'CONCRETE, PORTLAND', 'H(0.010000)C(0.001000)O(0.529107)Na(0.016000)Mg(0.002000)Al(0.033872)Si(0.337021)K(0.013000)Ca(0.044000)Fe(0.014000)' ;... 212 | 0.50932, 2.300e+000, 'Concrete', 'Concrete, Ordinary', 'H(0.0221)C(0.002484)O(0.57493)Na(0.015208)Mg(0.001266)Al(0.019953)Si(0.304627)K(0.010045)Ca(0.042951)Fe(0.006435)' ;... 213 | 0.45714, 3.350e+000, 'Barite Concrete', 'Concrete, Barite', 'H(0.003585)O(0.311622)Mg(0.001195)Al(0.004183)Si(0.010457)S(0.107858)Ca(0.050194)Fe(0.047505)Ba(0.4634)' ;... 214 | 0.57034, 7.790e-001, '', 'CYCLOHEXANE', 'C6H12' ;... 215 | 0.49098, 1.305e+000, 'ortho-dichlorobenzene', '1, 2-DICHLOROBENZENE', 'C6H4Cl2' ;... 216 | 0.48616, 1.220e+000, 'DCDE', 'DICHLORODIETHYL ETHER', 'C4H8Cl2O' ;... 217 | 0.48853, 1.235e+000, 'EDC', '1, 2-DICHLOROETHANE', 'C2H4Cl2' ;... 218 | 0.56663, 7.138e-001, '', 'DIETHYL ETHER', 'C4H10O' ;... 219 | 0.54724, 9.487e-001, '', 'N,N-DIMETHYL FORMAMIDE', 'C3H7NO' ;... 220 | 0.53757, 1.101e+000, 'DMSO', 'DIMETHYL SULFOXIDE', 'C2H6OS' ;... 221 | 0.59862, 1.253e-003, '', 'ETHANE', 'C2H6' ;... 222 | 0.56437, 7.893e-001, 'Ethanol', 'ETHYL ALCOHOL', 'C2H6O' ;... 223 | 0.54405, 1.130e+000, '', 'ETHYL CELLULOSE', 'C12H22O5' ;... 224 | 0.57034, 1.175e-003, '', 'ETHYLENE', 'C2H4' ;... 225 | 0.54877, 1.100e+000, 'EYE LENS', 'EYE LENS (ICRP)', 'H(0.099269)C(0.193710)N(0.053270)O(0.653751)' ;... 226 | 0.47592, 5.200e+000, 'Iron(III) oxide', 'FERRIC OXIDE', 'Fe2O3' ;... 227 | 0.46507, 7.150e+000, '', 'FERROBORIDE', 'FeB' ;... 228 | 0.47323, 5.700e+000, 'Iron(II) oxide', 'FERROUS OXIDE', 'FeO' ;... 229 | 0.55328, 1.024e+000, '', 'FERROUS SULFATE DOSIMETER SOLUTION', 'H(0.108259)N(0.000027)O(0.878636)Na(0.000022)S(0.012968)Cl(0.000034)Fe(0.000054)' ;... 230 | 0.47968, 1.120e+000, 'Dichlorodifluoromethane', 'FREON-12', 'CCl2F2' ;... 231 | 0.44801, 1.800e+000, 'Dibromodifluoromethane', 'FREON-12B2', 'CBr2F2' ;... 232 | 0.47866, 9.500e-001, '', 'FREON-13', 'CClF3' ;... 233 | 0.45665, 1.500e+000, '', 'FREON-13B1', 'CBrF3' ;... 234 | 0.42262, 1.800e+000, '', 'FREON-13I1', 'CIF3' ;... 235 | 0.42266, 7.440e+000, '', 'GADOLINIUM OXYSULFIDE', 'Gd2O2S' ;... 236 | 0.44247, 5.310e+000, '', 'GALLIUM ARSENIDE', 'GaAs' ;... 237 | 0.53973, 1.291e+000, '', 'GEL IN PHOTOGRAPHIC EMULSION', 'H(0.081180)C(0.416060)N(0.111240)O(0.380640)S(0.010880)' ;... 238 | 0.49707, 2.230e+000, 'Pyrex Glass', 'Glass, Borosilicate', 'B(0.040064)O(0.539562)Na(0.028191)Al(0.011644)Si(0.377220)K(0.003321)' ;... 239 | 0.42101, 6.220e+000, 'Lead Glass', 'GLASS, LEAD', 'O(0.156453)Si(0.080866)Ti(0.008092)As(0.002651)Pb(0.751938)' ;... 240 | 0.49731, 2.400e+000, 'Plate Glass', 'GLASS, PLATE', 'O(0.459800)Na(0.096441)Si(0.336553)Ca(0.107205)' ;... 241 | 0.53489, 1.540e+000, 'GLc', 'GLUCOSE', 'C6H14O7' ;... 242 | 0.53371, 1.460e+000, '', 'GLUTAMINE', 'C5H10N2O3' ;... 243 | 0.54292, 1.261e+000, 'Glycerin', 'GLYCEROL', 'C3H8O3' ;... 244 | 0.51612, 1.580e+000, '', 'GUANINE', 'C5H5N5O' ;... 245 | 0.50039, 2.320e+000, 'GYPSUM', 'GYPSUM, PLASTER OF PARIS', 'H4CaSO6' ;... 246 | 0.57882, 6.838e-001, 'HEPTANE', 'N-HEPTANE', 'C7H16' ;... 247 | 0.58020, 6.603e-001, 'HEXANE', 'N-HEXANE', 'C6H14' ;... 248 | 0.51264, 1.420e+000, '', 'KAPTON POLYIMIDE FILM', 'C22H10N2O5' ;... 249 | 0.42588, 6.280e+000, '', 'LANTHANUM OXYBROMIDE', 'LaOBr' ;... 250 | 0.42706, 5.860e+000, '', 'LANTHANUM OXYSULFIDE', 'La2OS' ;... 251 | 0.40323, 9.530e+000, '', 'LEAD OXIDE', 'PbO' ;... 252 | 0.50052, 1.178e+000, '', 'LITHIUM AMIDE', 'LiNH2' ;... 253 | 0.48720, 2.110e+000, '', 'LITHIUM CARBONATE', 'Li2CO3' ;... 254 | 0.46262, 2.635e+000, '', 'LITHIUM FLUORIDE', 'LiF' ;... 255 | 0.50321, 8.200e-001, '', 'LITHIUM HYDRIDE', 'LiH' ;... 256 | 0.41839, 3.494e+000, '', 'LITHIUM IODIDE', 'LiI' ;... 257 | 0.46852, 2.013e+000, '', 'LITHIUM OXIDE', 'Li2O' ;... 258 | 0.48487, 2.440e+000, '', 'LITHIUM TETRABORATE', 'Li2B4O7' ;... 259 | 0.54965, 1.050e+000, 'Lung', 'LUNG (ICRP)', 'H(0.101278)C(0.102310)N(0.028650)O(0.757072)Na(0.001840)Mg(0.000730)P(0.000800)S(0.002250)Cl(0.002660)K(0.001940)Ca(0.000090)Fe(0.000370)Zn(0.000010)' ;... 260 | 0.55512, 1.050e+000, '', 'M3 WAX', 'H(0.114318)C(0.655823)O(0.092183)Mg(0.134792)Ca(0.002883)' ;... 261 | 0.49814, 2.958e+000, '', 'MAGNESIUM CARBONATE', 'MgCO3' ;... 262 | 0.48153, 3.000e+000, '', 'MAGNESIUM FLUORIDE', 'MgF2' ;... 263 | 0.49622, 3.580e+000, '', 'MAGNESIUM OXIDE', 'MgO' ;... 264 | 0.49014, 2.530e+000, '', 'MAGNESIUM TETRABORATE', 'MgB4O7' ;... 265 | 0.40933, 6.360e+000, '', 'MERCURIC IODIDE', 'HgI2' ;... 266 | 0.62334, 6.672e-004, '', 'METHANE', 'CH4' ;... 267 | 0.56176, 7.914e-001, '', 'METHANOL', 'CH4O' ;... 268 | 0.56479, 9.900e-001, '', 'MIX D WAX', 'H(0.134040)C(0.777960)O(0.035020)Mg(0.038594)Ti(0.014386)' ;... 269 | 0.53886, 1.000e+000, '', 'MS20 TISSUE SUBSTITUTE', 'H(0.081192)C(0.583442)N(0.017798)O(0.186381)Mg(0.130287)Cl(0.000900)' ;... 270 | 0.54938, 1.040e+000, 'SKELETAL MUSCLE', 'MUSCLE, SKELETAL (ICRP)', 'H(0.100637)C(0.107830)N(0.027680)O(0.754773)Na(0.000750)Mg(0.000190)P(0.001800)S(0.002410)Cl(0.000790)K(0.003020)Ca(0.000030)Fe(0.000040)Zn(0.000050)' ;... 271 | 0.55005, 1.040e+000, 'STRIATED MUSCLE', 'MUSCLE, STRIATED (ICRU)', 'H(0.101997)C(0.123000)N(0.035000)O(0.729003)Na(0.000800)Mg(0.000200)P(0.002000)S(0.005000)K(0.003000)' ;... 272 | 0.54828, 1.110e+000, '', 'MUSCLE-EQUIVALENT LIQUID, WITH SUCROSE', 'H(0.098234)C(0.156214)N(0.035451)O(0.710100)' ;... 273 | 0.55014, 1.070e+000, '', 'MUSCLE-EQUIVALENT LIQUID, WITHOUT SUCROSE', 'H(0.101969)C(0.120058)N(0.035451)O(0.742522)' ;... 274 | 0.53053, 1.145e+000, '', 'NAPHTHALENE', 'C10H8' ;... 275 | 0.51986, 1.199e+000, '', 'NITROBENZENE', 'C6H5NO2' ;... 276 | 0.49985, 1.831e-003, '', 'NITROUS OXIDE', 'N2O' ;... 277 | 0.55063, 1.080e+000, '', 'NYLON, DU PONT ELVAMIDE 8062', 'H(0.103509)C(0.648415)N(0.099536)O(0.148539)' ;... 278 | 0.54790, 1.140e+000, '', 'NYLON, TYPE 6 AND TYPE 6/6', 'C12H22O2N2' ;... 279 | 0.55236, 1.140e+000, '', 'NYLON, TYPE 6/10', 'C8H15ON' ;... 280 | 0.55649, 1.425e+000, '', 'NYLON, TYPE 11 (RILSAN)', 'C11H21ON' ;... 281 | 0.57778, 7.026e-001, 'Liquid Octane', 'OCTANE, LIQUID', 'C8H18' ;... 282 | 0.55149, 2.200e+000, '', 'Ovary', 'H(0.105)C(0.093)N(0.024)O(0.768)Na(0.002)P(0.002)S(0.002)Cl(0.002)K(0.002)' ;... 283 | 0.57275, 9.300e-001, 'PARAFFIN', 'PARAFFIN WAX', 'C25H52' ;... 284 | 0.58212, 6.262e-001, 'PENTANE', 'N-PENTANE', 'C5H12' ;... 285 | 0.48176, 3.820e+000, 'Kodak Photo Emulsion', 'Photographic Emulsion (Kodak Type AA)', 'H(0.0305)C(0.2107)N(0.0721)O(0.1632)Br(0.2228)Ag(0.3007)' ;... 286 | 0.45453, 1.030e+000, 'Nuclear Photo Emulsion', 'Photographic Emulsion (Standard Nuclear)', 'H(0.0141)C(0.072261)N(0.01932)O(0.066101)S(0.00189)Br(0.349104)Ag(0.474105)I(0.00312)' ;... 287 | 0.45453, 3.815e+000, '', 'PHOTOGRAPHIC EMULSION', 'H(0.0141)C(0.072261)N(0.01932)O(0.066101)S(0.00189)Br(0.349103)Ag(0.474105)I(0.00312)' ;... 288 | 0.54141, 1.032e+000, 'VINYLTOLUENE', 'PLASTIC SCINTILLATOR (VINYLTOLUENE BASED)', 'C9H10' ;... 289 | 0.38879, 1.146e+001, '', 'PLUTONIUM DIOXIDE', 'PuO2' ;... 290 | 0.52767, 1.170e+000, 'PAN', 'POLYACRYLONITRILE', 'C3H3N' ;... 291 | 0.52697, 1.200e+000, 'MAKROLON', 'POLYCARBONATE (MAKROLON, LEXAN)', 'C16H14O3' ;... 292 | 0.48558, 1.300e+000, '', 'POLYCHLOROSTYRENE', 'C17H18Cl2' ;... 293 | 0.57034, 9.400e-001, '', 'POLYETHYLENE', 'C2H4' ;... 294 | 0.52037, 1.400e+000, '', 'POLYETHYLENE TEREPHTHALATE (MYLAR)', 'C10H8O4' ;... 295 | 0.53937, 1.190e+000, 'PLEXIGLASS', 'POLYMETHYL METHACRALATE (LUCITE, PERSPEX, PLEXIGLASS)', 'C5H8O2' ;... 296 | 0.51183, 1.425e+000, '', 'POLYOXYMETHYLENE', 'H2CO' ;... 297 | 0.57034, 9.000e-001, '', 'POLYPROPYLENE', 'C3H6' ;... 298 | 0.53768, 1.060e+000, '', 'POLYSTYRENE', 'CH' ;... 299 | 0.47992, 2.200e+000, 'Teflon', 'POLYTETRAFLUOROETHYLENE (TEFLON)', 'C2F4' ;... 300 | 0.48081, 2.100e+000, '', 'POLYTRIFLUOROCHLOROETHYLENE', 'C2F3Cl' ;... 301 | 0.53432, 1.190e+000, 'PVA', 'POLYVINYL ACETATE', 'C4H6O2' ;... 302 | 0.54480, 1.300e+000, 'PVOH', 'POLYVINYL ALCOHOL', 'C2H4O' ;... 303 | 0.54537, 1.120e+000, 'PVB', 'POLYVINYL BUTYRAL', 'C8H13O2' ;... 304 | 0.48710, 1.300e+000, 'PVC', 'POLYVINYL CHLORIDE', 'C2H3Cl' ;... 305 | 0.49513, 1.700e+000, 'SARAN', 'POLYVINYLIDENE CHLORIDE', 'CHCl' ;... 306 | 0.49973, 1.760e+000, 'Kynar', 'POLYVINYLIDENE FLUORIDE', 'C2H2F2' ;... 307 | 0.53984, 1.250e+000, 'PVP', 'POLYVINYL PYRROLIDONE', 'C6H9NO' ;... 308 | 0.43373, 3.130e+000, '', 'POTASSIUM IODIDE', 'KI' ;... 309 | 0.48834, 2.320e+000, '', 'POTASSIUM OXIDE', 'K2O' ;... 310 | 0.58962, 1.879e-003, '', 'PROPANE', 'C3H8' ;... 311 | 0.58962, 4.300e-001, 'LIQUID PROPANE', 'PROPANE, LIQUID', 'C3H8' ;... 312 | 0.56576, 8.035e-001, '1-Propanol', 'N-PROPYL ALCOHOL', 'C3H8O' ;... 313 | 0.53097, 9.819e-001, 'Azine', 'PYRIDINE', 'C5H5N' ;... 314 | 0.57034, 9.200e-001, 'BUTYL', 'RUBBER, BUTYL', 'C4H8' ;... 315 | 0.55785, 9.200e-001, 'Latex', 'RUBBER, NATURAL', 'C5H8' ;... 316 | 0.48605, 1.230e+000, 'NEOPRENE', 'RUBBER, NEOPRENE', 'C4H5Cl' ;... 317 | 0.49930, 2.320e+000, '', 'SILICON DIOXIDE', 'SiO2' ;... 318 | 0.43670, 6.473e+000, '', 'SILVER BROMIDE', 'AgBr' ;... 319 | 0.44655, 5.560e+000, '', 'SILVER CHLORIDE', 'AgCl' ;... 320 | 0.43663, 6.470e+000, '', 'SILVER HALIDES IN PHOTOGRAPHIC EMULSION', 'Br(0.422895)Ag(0.573748)I(0.003357)' ;... 321 | 0.42594, 6.010e+000, '', 'SILVER IODIDE', 'AgI' ;... 322 | 0.54932, 1.100e+000, 'Skin', 'SKIN (ICRP)', 'H(0.100588)C(0.228250)N(0.046420)O(0.619002)Na(0.000070)Mg(0.000060)P(0.000330)S(0.001590)Cl(0.002670)K(0.000850)Ca(0.000150)Fe(0.000010)Zn(0.000010)' ;... 323 | 0.49062, 2.532e+000, 'Washing soda', 'SODIUM CARBONATE', 'Na2CO3' ;... 324 | 0.42697, 3.667e+000, '', 'SODIUM IODIDE', 'NaI' ;... 325 | 0.48403, 2.270e+000, '', 'SODIUM MONOXIDE', 'Na2O' ;... 326 | 0.49415, 2.261e+000, '', 'SODIUM NITRATE', 'NaNO3' ;... 327 | 0.53260, 9.707e-001, 'trans-1, 2-diphenylethylene', 'STILBENE', 'C14H12' ;... 328 | 0.53170, 1.581e+000, 'Sugar', 'SUCROSE', 'C12H22O11' ;... 329 | 0.52148, 1.234e+000, 'p-Terphenyl', 'TERPHENYL', 'C18H10' ;... 330 | 0.55108, 1.040e+000, 'TESTES', 'TESTES (ICRP)', 'H(0.104166)C(0.092270)N(0.019940)O(0.773884)Na(0.002260)Mg(0.000110)P(0.001250)S(0.001460)Cl(0.002440)K(0.002080)Ca(0.000100)Fe(0.000020)Zn(0.000020)' ;... 331 | 0.48241, 1.625e+000, 'PCE', 'TETRACHLOROETHYLENE', 'C2Cl4' ;... 332 | 0.40861, 7.004e+000, '', 'THALLIUM CHLORIDE', 'TlCl' ;... 333 | 0.55121, 1.000e+000, 'Soft Tissue', 'TISSUE, SOFT (ICRP)', 'H(0.104472)C(0.232190)N(0.024880)O(0.630238)Na(0.001130)Mg(0.000130)P(0.001330)S(0.001990)Cl(0.001340)K(0.001990)Ca(0.000230)Fe(0.000050)Zn(0.000030)' ;... 334 | 0.54975, 1.000e+000, '4 component soft tissue', 'TISSUE, SOFT (ICRP four components)', 'H(0.101172)C(0.111000)N(0.026000)O(0.761828)' ;... 335 | 0.54993, 1.064e-003, '', 'TISSUE-EQUIVALENT GAS (METHANE BASED)', 'H(0.101869)C(0.456179)N(0.035172)O(0.406780)' ;... 336 | 0.55027, 1.826e-003, '', 'TISSUE-EQUIVALENT GAS (PROPANE BASED)', 'H(0.102672)C(0.568940)N(0.035022)O(0.293366)' ;... 337 | 0.46528, 4.260e+000, '', 'TITANIUM DIOXIDE', 'TiO2' ;... 338 | 0.54265, 8.669e-001, 'methylbenzene', 'TOLUENE', 'C7H8' ;... 339 | 0.48710, 1.460e+000, 'TCE', 'TRICHLOROETHYLENE', 'Cl3C2H' ;... 340 | 0.52404, 1.070e+000, 'phosphoric acid', 'TRIETHYL PHOSPHATE', 'C6H15PO4' ;... 341 | 0.40371, 2.400e+000, 'Tungsten(VI) fluoride', 'TUNGSTEN HEXAFLUORIDE', 'WF6' ;... 342 | 0.39687, 1.128e+001, '', 'URANIUM DICARBIDE', 'UC2' ;... 343 | 0.39194, 1.363e+001, 'Uranium carbide', 'URANIUM MONOCARBIDE', 'UC' ;... 344 | 0.39996, 1.096e+001, 'Uranium dioxide', 'URANIUM OXIDE', 'UO2' ;... 345 | 0.53284, 1.323e+000, 'Diaminomethanal', 'UREA', 'N2H4CO' ;... 346 | 0.54632, 1.230e+000, 'Val', 'VALINE', 'C5H11NO2' ;... 347 | 0.52772, 1.800e+000, 'Viton', 'VITON FLUOROELASTOMER', 'C5H2F8' ;... 348 | 0.55509, 1.000e+000, 'Water', 'WATER, LIQUID', 'H2O' ;... 349 | 0.55509, 7.562e-004, 'Steam', 'WATER VAPOR', 'H2O' ;... 350 | 0.55509, 0.897e+000, 'Ice' , 'WATER, ICE', 'H2O' ;... 351 | 0.54631, 8.700e-001, '', 'XYLENE', 'C8H10' ;... 352 | 0.38930, 2.055 , '', 'Yellowcake', 'U3O8';... % source www.cdc.gov/niosh/ocas/pdfs/abrwh/drreview/scadrr01.pdf 353 | 0.55493, 0.93 , 'BPE' ,'Borated Polyethylene, 5%', 'B(5)H(11.6)C(61.2)O(22.2)' ;... 354 | 0.55012, 1.03 , 'BPE-10','Borated Polyethylene, 10%', 'B(10)H(11)C(58)O(21)' ;... 355 | 0.46556, 7.86 , 'Steel', 'Steel, ASTM A 366', 'C(8.5E-4)P(1.5E-4)S(1.75E-4)Mn(0.003)Fe(0.996)';... 356 | NaN, NaN, '', '', '';... 357 | }; 358 | 359 | %% Special cases: if Name is empty than just show aviable names 360 | nElem = 100; 361 | if (strcmp(Name, 'Compound Names')) 362 | P = Props(nElem+1:end, 3:5); 363 | return; 364 | end 365 | if (strcmp(Name, 'Element Data')) 366 | P = Props(1:nElem,[3, 1]); 367 | return; 368 | end 369 | if (strcmp(Name, 'All Data')) 370 | P = Props(:,[1 2 5 4 3]); 371 | idx = find(cellfun('isempty',P(:, 3))); 372 | P(idx, 3) = P(idx, 5); 373 | return; 374 | end 375 | 376 | %% Process Material Input Parameter 377 | if (ischar (Name)), Name = {Name}; end 378 | if (isnumeric(Name)), Name = num2cell(Name); end 379 | 380 | %% Initialize variables 381 | nName = length(Name); 382 | nData = length(Props); 383 | P = cell(nName,size(Props, 2)); 384 | 385 | %% Main Loop 386 | for i = 1:nName 387 | name = Name{i}; 388 | if (ischar(name)) 389 | k = find(strcmpi( name, Props(:, 3:4)), 1);% which benchmark? 390 | if (isempty(k)) 391 | k = find(strcmp( name, Props(:, 5)), 1);% which benchmark? 392 | end; 393 | name = nData; 394 | if (~isempty(k)), name=k; end; 395 | if (name>nData), name = name-nData; end 396 | end 397 | P(i,:) = Props(name,:); 398 | if (~isempty(P{i, 5})), P(i, 3) = P(i, 5); end 399 | end 400 | P(:, 5) =[]; --------------------------------------------------------------------------------