Calculating size metrics from CT axial images
The size metrics
This section outlines the calculations performed by the calcSizeMetrics script, focusing on the extraction of patient size surrogates, specifically the anteroposterior (AP) and lateral (LAT) widths from CT axial scans It details the computation of effective diameter and ellipticity ratio, as well as the extraction of the mean Hounsfield Unit from a region of interest (ROI) in a CT scan, leading to the calculation of water-equivalent diameter (WED) Additionally, a method for table removal is included Example code and a comprehensive explanation of the methodology are provided in the subsequent subsections, with all relevant data for each slice, including complete DICOM metadata, organized within a structure named 'exam.'
Calculating AP and LAT dimensions
Figure 13.1: (a) The original CT axial image, (b) CT axial image with a threshold of −150 HU set to zero applied, (c) binary CT axial image with the remaining values over
The binary CT axial image in set 1, (d) illustrates the removal of the table, highlighting two rays used to measure lateral width One ray travels through the patient, represented by value 1, while the other passes through air alone, indicated by value 0.
Figure 13.1 illustrates the process of extracting anteroposterior (AP) and lateral (LAT) dimensions from a CT axial image Initially, the original CT image is presented in Figure 13.1a To focus on the patient’s shape, a threshold of -150 is applied in Figure 13.1b, effectively removing the background air The image is then binarized, converting all non-zero values to 1, as seen in Figure 13.1c To ensure accurate size estimation, any extraneous objects, such as the table and other equipment, must be excluded This is achieved using MATLAB’s bwareaopen function, which eliminates connected components with fewer than 5000 pixels, resulting in a clean binary image of the patient in Figure 13.1d.
In the analysis process, each row and column of the image undergoes a summation, assigning a binary value of 1 if a patient is present and 0 if absent (see Figure 13.1d) These binary values are stored in arrays, which are then summed to determine the LAT and AP widths in pixels To convert these pixel measurements to millimeters, the sums are multiplied by the pixel spacing values from the DICOM tag (0028,0030) found in the structuredcmInfo Figure 13.2 demonstrates the calculated LAT and AP widths for the ATCM phantom, as discussed in Chapter 11, with the true dimensions of the phantom sections (300 mm × 200 mm, 350 mm × 233 mm, and 250 mm × 167 mm) closely matching the reconstructed values.
The effective diameter can be calculated using two methods: the first method (diaEff1) involves taking the square root of the product of the lateral (LAT) and anteroposterior (AP) widths, while the second method (diaEff2) averages the LAT and AP widths by summing them and dividing by two Additionally, the ellipticity ratio (ellipRat) is determined by dividing the LAT width by the AP width.
Figure 13.2: Size metrics for an ATCM phantom using the code in this chapter.
% Set any padded values to CT-number of air dcmImage(dcmImage 0; widthLAT = sum(projLAT)*dcmInfo.PixelSpacing(2);
% Effective diameter is calculated using two formulas given in
% AAPM Report 204 diaEff1 = sqrt(widthLAT*widthAP); % Geometric mean diaEff2 = (widthLAT + widthAP)/2; % Arithmetic mean ellipRat = widthLAT/widthAP; % Ellipticity ratio
% Make a new binary image of patient including low densities inside patient if tableRemoval == 'y' % Option to remove background and table from image
% Fill in the low density regions inside patient, e.g lungs binImage = imfill(axialImageBinCR,'holes'); areaROI = sum(sum(binImage))*dcmInfo.PixelSpacing(1)* dcmInfo.PixelSpacing(2); elseif tableRemoval == 'n' % Option to keep background and table
This code snippet processes an image by iterating through its pixels to create a binary image representation It initializes a logical array, `binImage`, with the same dimensions as the input image, `dcmImage` For each pixel, the code checks if it lies within a circular region defined by the field of view (FOV), centered in the middle of the image If a pixel falls within this circular area, it is assigned a value of 1, indicating it is part of the FOV This method effectively isolates the relevant area of the image for further analysis.
% Area of the FOV areaROI = pi*(double(dcmInfo.Width)/2)^2* double(dcmInfo.PixelSpacing(1))*double(dcmInfo.PixelSpacing(2)); end
% Mean CT number in patient meanCTNum = mean2(dcmImage(binImage));
(code continues on next page)
% Water equivalent area and diameter calculation formula from AAPM Report 220 areaWaterEq = 0.001 * meanCTNum * areaROI + areaROI; diaWaterEq = 2 * (areaWaterEq/pi)^(1/2);
The data is organized within a structure named 'exam', where each entry, indexed by 'iExam', stores various parameters for each slice, denoted by 'iSlice' Specifically, the slice location is recorded as 'dcmInfo.SliceLocation', while the diameter of water equivalent is captured as 'diaWaterEq' Additionally, the ellipticity ratio is stored as 'ellipRat', and the effective diameter is noted as 'diaEff1' The lateral and anteroposterior widths are documented as 'widthLAT' and 'widthAP', respectively Finally, the computed tomography dose index volume is represented by 'dcmInfo.CTDIvol'.
% Store entire DICOM header as a cell exam(iExam).dicomHeaderAxial(1,iSlice) = {dcmInfo};
Table considerations and calculating Water Equivalent Diameter 169
The AAPM Report 220 emphasizes the importance of removing the table before calculating the Water Equivalent Dose (WED), as this method is preferred for SSDE calculations Despite this recommendation, current WED publications have consistently included the table Although its impact on overall WED may be minimal, removing the table is essential for achieving the most accurate NDC and SSDE estimates that are relevant to patient care.
When the variable removeTable is set to 'y', the bwareaopen function generates a binary image that excludes the table, ensuring it does not affect the AP and LAT extraction The imfill function is then applied to fill low-density cavities in this binary image, which serves as a mask for all pixels within the patient Conversely, if removeTable is 'n', the entire field-of-view, centered with a diameter of dcmInfo.Width, is utilized to create the binary image The MATLAB code extracts Hounsfield Units (HU) from a defined circular region of interest (ROI), created using a nested for loop, which, while not time-efficient, is straightforward to implement The WED formula from AAPM Report 220 incorporates both the mean CT number and the area of the ROI, although care must be taken when the reconstructed image center is not at isocenter, as this may affect the ROI's accuracy.
Padding values, such as -3024 HU, are commonly used by CT vendors, though these values may vary To address this issue, the first line of code in the calcSizeMetrics function resets all voxels with a value of -1024 HU to -1000 HU, simulating air It is crucial to correct these padding values prior to performing a WED calculation, as neglecting this step could lead to a significant reduction in WED values.
13.4 CALCULATING THE SIZE-SPECIFIC DOSE ESIMATE
The script calcSSDE is utilized to access and process information from the structure exam, allowing for data extraction that can be visualized in MATLAB or exported to an Excel spreadsheet By extracting the CTDIvol, users can apply it alongside the NDC to compute the SSDE The example code demonstrates how to estimate the average NDC within the central 20% of each examination using both the effective diameter (diaEff) and the water equivalent diameter (diaWaterEq), while also calculating the average CTDIvol in the same region to facilitate the conversion of NDC to SSDE.
Before these calculations, the data stored in exam for every examination is reordered so that the slice location is ordered with increasing value (using MATLAB’s sort function)
% Reorder the slices in each exam so we go from low to high z-position for iExam = 1:length(exam)
[~,b] = sort(exam(iExam).sliceLocation); % Array b holds the reordering
% Iterate through the fieldnames of the structure for fieldName = fieldnames(exam(iExam)) fieldValues = exam(iExam).(fieldName{1});
% Reorder only if the field has a value for each slice if numel(fieldValues) == numel(b) exam(iExam).(fieldName{1}) = fieldValues(b); end end end
% For each exam, average the size metric and CTDIvol over middle 20% of
The code iterates through each exam, calculating the number of slices and determining the middle index range It computes the average values for the diameter efficiency, water equivalent diameter, and CTDI volume for each exam using the specified index range These averages are stored in the respective arrays for further analysis.
% Fit coefficients from AAPM Report 204 (for CTDIvol 32cm) a = 3.704369; b = 0.03671937*0.1;
% Estimate the SSDE using effective diameter ssdeDiaEff = a*exp(-b*midDiaEff).*midCtdiVol; % mGy
% Estimate the SSDE using water equivalent diameter ssdeDiaWaterEq = a*exp(-b*midDiaWaterEq).*midCtdiVol; % mGy
Vendors must now display the Size-Specific Dose Estimate (SSDE) and Weighted Effective Dose (WED) in relation to CT scans, although their data collection methods remain undisclosed This chapter offers a comprehensive overview of coding techniques that can calculate patient size surrogates and SSDE for axial images, as well as provide an average SSDE estimate across specific scan regions.
MATLAB toolboxes used in this chapter:
Index of the in-built MATLAB functions used: bwareaopen dir mean clearvars double mean2 count exp numel dicominfo fullfile round dicomread imfill size sort sqrt strcmp sum uigetdir
Reconstructing the exposure geometry in x-ray angiography and interventional radiology
Medical Radiation Physics and Nuclear Medicine, Karolinska University Hospital, Stockholm, Sweden
Department of Oncology-Pathology, Karolinska Institutet, Stockholm, Sweden
14.3 Reconstructing the patient-beam alignment 174
14.4 Reconstructing the source-to-surface distance 176
14.5 Calculating the incident air kerma 180
Medical Physicists face the challenging responsibility of estimating the absorbed dose for patients who have undergone intricate image-guided interventions involving numerous distinct x-ray exposures This chapter presents a structured approach to tackle this complex task effectively.
Accurate patient dose estimation in angiography and interventional radiology is challenging due to the difficulty in obtaining detailed information about specific irradiation geometry and x-ray beam settings Given the high exposure levels associated with complex interventions, it is crucial to estimate absorbed organ doses accurately to assess the risk of radiation-induced tissue reactions, such as skin erythema and hair loss The International Atomic Energy Agency (IAEA) has established guidelines in its international code of practice to address these concerns.
The x-ray angiography system, as depicted in Figure 14.1, includes a patient table top and a c-arm that houses the x-ray tube and imaging detector The design allows for various movements and tilting of the table top, as well as multiple axes of rotation for the c-arm around the isocenter, facilitating optimal imaging during procedures.
TRS-457[110] suggests that dosimetry measurements in diagnostic radiology should aim for an accuracy of 7% with 95% confidence limits when tissue reactions are anticipated While this requirement pertains to the accuracy of directly measured dosimetry quantities, it sets a benchmark for patient dose estimation Achieving this level of accuracy can be challenging, particularly when using simplified approximations for specific examination settings, such as x-ray beam quality and irradiation geometry.
The U.S National Electrical Manufacturers Association (NEMA) has implemented diagnostic x-ray radiation dose structured reporting (RDSR) to ensure systematic and non-proprietary access to exam-specific exposure settings, as mandated by IEC 60601-2-43 for newly manufactured x-ray units While RDSR provides comprehensive data on various exposure settings, including patient table and x-ray beam geometry, it often omits crucial information about the patient's position on the table This absence of data hampers the accurate reconstruction of patient-beam alignment, potentially introducing significant uncertainty into radiation dose calculations.
This chapter presents a MATLAB implementation of a method for reconstructing exposure geometry using information from RDSR, as proposed in Ref [113] It emphasizes two main aspects: inferring the target region's position relative to the x-ray tube source (Section 14.3) and calculating the source-to-skin distance (Section 14.4) In the concluding section (14.5), the reconstructed exposure geometry is utilized to determine the incident air kerma, a crucial parameter for patient dose calculations To facilitate this process, we will first explore the implementation of translation, scaling, and rotation of position vectors in MATLAB, as a foundational understanding of elementary vector algebra is necessary.
A translation (or displacement)T(t x , t y , t z ) can be applied to the vectorr= (x, y, z) using vector addition, r 0 =T(t)r=r+t= (x+t x , y+t y , z+t z ) = (x 0 , y 0 , z 0 ) (14.1) This can be implemented as:
%% Vector translation r = [1,1,1]; t = [1,2,3]; % An arbitrary position vector and translation. rp = r+t; % r'= [2,3,4].
A scaling transformation S(s x , s y , s z ) can be applied to the vector r = (x, y, z) using element-wise multiplication (i.e., the Hadamard product), r 0 =S(s)r=s ∗r= (s x x, s y y, s z z) = (x 0 , y 0 , z 0 ) (14.2) This can be implemented as:
%% Vector scaling r = [2,2,2]; s = [1,2,3]; % An arbitrary position and scaling vector. rp = s.*r; % r'= [2,4,6].
A vector rotation in three-dimensional space involves a series of three fundamental rotations around the coordinate axes: an angle α around the x-axis, an angle β around the y-axis, and an angle γ around the z-axis Positive rotations are defined as counterclockwise when viewed from the rotation axis toward the origin, following the right-hand rule The position vector r = (x, y, z) can be transformed into a new position vector r' = (x', y', z') through the rotation matrix R(α, β, γ), expressed as r' = R(α, β, γ)r = Rz(γ)Ry(β)Rx(α)r This process can be efficiently executed in MATLAB using anonymous functions to represent the three basic rotations.
%% Anonymous functions for the basic rotations Rx(), Ry(), Rz() (rad):
Ry = @(bet) [ cos(bet), 0 , sin(bet) ;
Rz = @(gam) [ cos(gam), -sin(gam) , 0 ; sin(gam), cos(gam) , 0 ;
Figure 14.2: Rotation R( , , ) of a position vector r = (0, 0.6, 0) in the standard basis {e x , e y , e z }
The implementation of three-dimensional rotation is non-commutative, meaning that the sequence of rotations significantly affects the final outcome For example, the rotation demonstrated in Figure 14.2 follows a specific order to achieve the desired result.
%% Vector rotation r = [0;0.6;0]; % Position vector in fig 14.2. alph = pi/2; bet = pi/2; gam = pi/4; % Rotation angles in fig 14.2. rp = Rz(gam)*Ry(bet)*Rx(alph)*r; % r'= 0.6.*[cos(pi/4); sin(pi/4); 0].
Since R( , , ) is orthogonal, the inverse rotation is given by the transpose of the rotation matrix, meaning that a rotation can be reversed as, r = R T ( , , )r 0 = R x (− )R y (− )R z (− )r 0 = (x, y, z) (14.4)
14.3 RECONSTRUCTING THE PATIENT-BEAM ALIGNMENT
To estimate the absorbed dose to a patient, a Monte Carlo simulation can be utilized, incorporating a computational phantom model that accurately represents the patient's anatomy By aligning the orientation and position of the phantom model with that of the patient on the treatment table, the exposure geometry can be effectively reconstructed.
Conclusion
C hapter 14 Reconstructing the geometry of x-ray interventions 171
Elementary vector algebra
Translation
A translation (or displacement)T(t x , t y , t z ) can be applied to the vectorr= (x, y, z) using vector addition, r 0 =T(t)r=r+t= (x+t x , y+t y , z+t z ) = (x 0 , y 0 , z 0 ) (14.1) This can be implemented as:
%% Vector translation r = [1,1,1]; t = [1,2,3]; % An arbitrary position vector and translation. rp = r+t; % r'= [2,3,4].
Scaling
A scaling transformation S(s x , s y , s z ) can be applied to the vector r = (x, y, z) using element-wise multiplication (i.e., the Hadamard product), r 0 =S(s)r=s ∗r= (s x x, s y y, s z z) = (x 0 , y 0 , z 0 ) (14.2) This can be implemented as:
%% Vector scaling r = [2,2,2]; s = [1,2,3]; % An arbitrary position and scaling vector. rp = s.*r; % r'= [2,4,6].
Reconstructing the patient-beam alignment
C hapter 15 Mammography and breast tomosynthesis simulation us- ing Perlin noise 183
C hapter 16 xrTk: a MATLAB toolkit for x-ray physics calculations 197
TOMI F NANO AND IAN A CUNNINGHAM
C hapter 17 Automating daily QC for an MRI scanner 211
Reconstructing the source-to-surface distance
C hapter 15 Mammography and breast tomosynthesis simulation us- ing Perlin noise 183
C hapter 16 xrTk: a MATLAB toolkit for x-ray physics calculations 197
TOMI F NANO AND IAN A CUNNINGHAM
C hapter 17 Automating daily QC for an MRI scanner 211
Conclusion
C hapter 15 Mammography and breast tomosynthesis simulation us- ing Perlin noise 183
C hapter 16 xrTk: a MATLAB toolkit for x-ray physics calculations 197
TOMI F NANO AND IAN A CUNNINGHAM
C hapter 17 Automating daily QC for an MRI scanner 211
17.2 AUTOMATIC ANALYSIS OF QUALITY CONTROL IMAGES 212
C hapter 18 Image processing at scale by containerizing’ MATLAB 223
JAMES D’ARCY, SIMON J DORAN AND MATTHEW ORTON
18.2 IMPROVED DICOM SUPPORT BY MATLAB-JAVA INTEGRATION 224 18.3 RUNNING MATLAB IN A CONTAINER 230 18.4 EXAMPLE PROBLEM FOR CONTAINERIZATION 233 18.5 XNAT: ORCHESTRATING THE IMAGE ANALYSIS OF LARGE
C hapter 19 Estimation of arterial wall movements 239
MAGNUS CINTHIO, JOHN ALBINSSON, TOBIAS ERLệV, TOMAS JANSSON and ÅSA RYDÉN AHLGREN
19.1 THE LONGITUDINAL MOVEMENT OF THE ARTERIAL WALL 240
C hapter 20 Importation and visualization of ultrasound data 249
TOBIAS ERLệV, MAGNUS CINTHIO andTOMAS JANSSON
20.4 GENERATING AND VISUALIZING B-MODE IMAGES 253
"Diagnostic Radiology Physics with MATLAB®: A Problem-Solving Approach," authored by Johan Helmenkamp, Robert Bujila, and Gavin Poludniowski, is the second installment in the Series in Medical Physics and Biomedical Engineering This book focuses on the application of MATLAB® software for clinical medical physicists, providing valuable insights and problem-solving techniques in diagnostic radiology physics.
The rapid advancement of medical device technology has made it increasingly challenging for clinical medical physicists to fulfill their roles effectively While strong programming skills can significantly aid in this process, there is a scarcity of comprehensive resources for acquiring such expertise "Diagnostic Radiology Physics with MATLAB®: A Problem-Solving Approach" addresses this gap by providing structured teaching materials and real-world case studies This book serves as a valuable resource for university tutors, students, and practicing clinical medical physicists, offering practical advice on topics like DICOM data manipulation, software integration, and regulatory considerations in clinical settings.
I extend my heartfelt gratitude to experienced medical physicists Johan Helmenkamp, Robert Bujila, and Gavin Poludniowski for dedicating their valuable time to this educational initiative and sharing their expertise with our readers Additionally, I appreciate the outstanding team of contributors who have provided a diverse array of real-world applications Their efforts are truly commendable I wish all readers enjoyable programming experiences and remind them that programming is a powerful tool!
Professor and Head, Medical Physics Department, University of Malta
Past Chair, Education and Training Committee, European Federation of Organizations for Medical Physics
Past Associate Editor for Education and Training: Physica Medica—European Journal of Medical Physics
Past Member, Accreditation Committee: International Medical Physics Certification Board xiii
This book does not serve as a comprehensive introduction to MATLAB, nor does it focus on image processing techniques like the unsharp mask algorithm Additionally, despite the inclusion of "physics" in the title, it does not delve into the physical principles of clinical radiology For those topics, other resources are available.
The title is Diagnostic Radiology Physics with MATLAB ® : A Problem-Solving Approach
Diagnostic Radiology encompasses both diagnostic and interventional radiology, utilizing ionizing sources like x-rays and non-ionizing sources such as Ultrasound and Magnetic Resonance Imaging While Nuclear Medicine is not the focus of this book, some relevant material is included Aimed primarily at medical physicists and engineers, the content also appeals to technically-minded professionals in other healthcare fields Additionally, the book bridges clinical development and research, making it valuable for students and researchers in academic settings.
The book title begs a further question: what do we mean by a problem-solving approach?
This article emphasizes that instead of presenting a wide array of problems for readers to solve, it offers examples of how various individuals have tackled their challenges The first section features a variety of brief examples, while the second part includes eleven comprehensive case studies, primarily authored by medical physicists rather than software engineers Although the coding may not always adhere to optimal efficiency or industry standards, it effectively fulfills its intended purpose The article also highlights the importance of adopting good practices and acknowledges situations where software development must meet industry standards.
You may still be wondering why MATLAB? Well, MATLAB has been around for over
MATLAB is a mature and versatile product with over 30 years of development, offering a vast array of functionalities and toolboxes Its core programming language is user-friendly, powerful, and accessible for beginners The MATLAB desktop environment enhances the user experience, making it a popular choice among students and professionals alike While there is no specific reason to choose MATLAB, it remains a solid option for many users Additionally, the MATLAB code referenced in this book is readily available in a software repository.
The book is divided into two main sections: General Topics and Problem-Solving, featuring real-life examples The chapters in the first section are organized for a seamless reading experience but can also be explored individually In contrast, the second section consists of entirely independent chapters that can be read in any sequence We encourage you to find a topic that piques your interest and dive in, hoping you gain as much knowledge from the book as we did in creating it!
Johan Helmenkamp, Robert Bujila and Gavin Poludniowski, June 2020 xv
The successful editing and co-authoring of this book was made possible thanks to the unwavering support and understanding of our families, who have graciously coped with our absence during countless nights and weekends over the past three years We extend our heartfelt gratitude to them.
We extend our heartfelt gratitude to all contributors, as this book's quality and utility are a direct result of your dedicated efforts in creating its content Your expertise and extensive knowledge in your fields have truly impressed us, making it a privilege to collaborate with you on this project and a valuable learning experience.
We are immensely grateful for the exceptional support from the CRC Press team, including Kirsten Barr, Rebecca Davies, Francesca McGowan, and Georgia Harrison, who have consistently provided guidance throughout our journey A special acknowledgment goes to Prof Carmel J Caruana for proposing the book concept and encouraging us to take on this project Thank you all for your dedication, belief in our vision, and for entrusting us with the opportunity to bring this book to life.
We extend our heartfelt gratitude to Shashi Kumar for his invaluable assistance with L A TEX formatting and coding His expertise and skillful service have made a significant difference in our work, allowing us to overcome challenges that would have otherwise hindered our progress.
We would also like to thank Paul Ganney for generously giving up his time to review a chapter, and Antti Lửytynoja and MathWorks for their helpful support throughout the project
We would like to express our sincere appreciation to our colleagues at Karolinska University Hospital and our friends for their unwavering support and encouragement Special thanks to Robert Vorbau for his assistance in reviewing our materials and data sets.
Johan Helmenkamp, Robert Bujila and Gavin Poludniowski xvii
Lund University, Skồne University Hospital
Umeồ University, Dicom Port AB
Lund University, Skồne University Hospital
Karolinska University Hospital Stockholm, Sweden
Queensland University of Technology, Brisbane
Umeồ University, Dicom Port AB Umeồ, Sweden
Karolinska University Hospital, Karolinska Institutet
Karolinska University Hospital, Karolinska Institutet
Image Owl, Inc., Greenwich New York, USA
The role of programming in healthcare
Johan Helmenkamp and Robert Bujila
Medical Radiation Physics and Nuclear Medicine, Karolinska University Hospital, Stockholm, Sweden
Medical Radiation Physics and Nuclear Medicine, Karolinska University Hospital, Stockholm, Sweden
Department of Clinical Science, Intervention and Technology, Karolinska Institutet, Stock- holm, Sweden
Programming can significantly enhance your clinic by transforming routine tasks, streamlining operations, and improving efficiency It also fosters research and innovation, enabling clinics to stay at the forefront of medical advancements However, with the power of programming comes the responsibility to use it ethically and effectively In conclusion, embracing programming in your clinic can lead to substantial benefits, but it is crucial to approach it with care and consideration.
This chapter serves as an essential introduction to the book, akin to a "ReadMe" file for software While it may be tempting to skip ahead, we encourage you to read these pages to align your mindset for the content ahead The chapter delves into the significance of programming in your professional journey, particularly within the fields of Medical Physics and healthcare Additionally, it highlights recent initiatives by professional societies aimed at enhancing training programs in Medical Physics to incorporate vital programming skills.
1.1 WHAT PROGRAMMING CAN DO FOR YOU