+ All Categories
Home > Documents > MicroCT system software update and implementation of a...

MicroCT system software update and implementation of a...

Date post: 04-Feb-2021
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
74
IN DEGREE PROJECT ENGINEERING PHYSICS, SECOND CYCLE, 30 CREDITS , STOCKHOLM SWEDEN 2016 MicroCT system software update and implementation of a beam hardening correction method PHILIP SUNDQVIST KTH ROYAL INSTITUTE OF TECHNOLOGY SCHOOL OF TECHNOLOGY AND HEALTH
Transcript
  • IN DEGREE PROJECT ENGINEERING PHYSICS,SECOND CYCLE, 30 CREDITS

    , STOCKHOLM SWEDEN 2016

    MicroCT system software update and implementation of a beam hardening correction method

    PHILIP SUNDQVIST

    KTH ROYAL INSTITUTE OF TECHNOLOGYSCHOOL OF TECHNOLOGY AND HEALTH

  • Abstract

    The School of Technology and Health, STH, has been developing a micro-CTscanner for pre-clinical imaging. The scanner consists of an X-ray tube and aflat panel sensor fixated on a gantry rotating around the object to be imaged. Acomputer located on the gantry runs an acquisition software for communicationbetween the devices on the gantry as well as for controlling them. For this thesisthe acquisition software has been significantly improved in terms of functionality,performance, usability and user-adaptivity.

    Projection images acquired by the microCT are created by measuring theX-ray beam attenuation as a function of spatial location. Using all projectionimages, a 3-dimensional image can be reconstructed giving a map of the attenu-ation inside the object, thus providing information about its internal structure.A common artifact for CT-scanner images is the cupping�artifact, in which theattenuation in the middle of an object is underestimated due to beam hardening.For the second part of this thesis, a method for correcting for this artifact hasbeen implemented and tested. The cupping artifact was successfully removedin most cases, although it was shown that for some situation it is not applicable

  • Sammanfattning

    Skolan för teknik och hälsa, STH, har utvecklat ett mikro-CT system för av-bildning av små objekt. Systemet best̊ar av ett röntgenrör och en paneldetektormonterade p̊a ett gantry som roterar runt föremålet som ska avbildas. En datormonterat p̊a detta gantry har mjukvara för kontroll av och kommunikation mel-lan de olika delarna. Under detta examensarbete har mjukvaran f̊att förbättradfunktionalitet, prestanda, användbarhet och användarvänlighet.

    Projektionsavbildningar skapas av mikro-CT systemet genom att mätaröntgenstr̊alens attenuering som funktion av systemets spatiala orientering. Ge-nom att använda alla projektionsavbildningar kan en 3-dimensionell bild avföremålets attenuering rekonstrueras, vilket ger information om dess internastruktur. En vanlig artefakt i CT-bilder kallas cupping och innebär att attenue-ringen i mitten av föremålet underestimeras p̊a grund av beamhardening. Underden andra delen av detta examensarbete har en korrektion för denna artefaktimplementerats och testats. Korrigeringen av artefakten var lyckad i de flestafall, men det visade sig att den inte var applicerbar i vissa situationer.

  • Acknowledgements

    I would like to thank my supervisors, Prof. Massimiliano Colarieti-Tosti andM.Sc. David Larsson for their guidance and support during my masters thesisat STH, and for letting me be part of the development of their microCT system.I would also like to thank Dr. Ivan Valastyan and M.Sc Luca Gugliermetti fortheir help with the image acquisition software, and my fellow master studentGustaf Lönn for valuable input to the thesis.

    1

  • Contents

    1 Introduction 4

    1.0.1 Purpose of study . . . . . . . . . . . . . . . . . . . . . . . 4

    2 Background 5

    2.1 CT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.1.1 Photons in CT . . . . . . . . . . . . . . . . . . . . . . . . 52.1.2 X-ray production . . . . . . . . . . . . . . . . . . . . . . . 52.1.3 X-ray attenuation . . . . . . . . . . . . . . . . . . . . . . 62.1.4 Image acquisition and reconstruction . . . . . . . . . . . . 82.1.5 MicroCT . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    2.2 The STH microCT . . . . . . . . . . . . . . . . . . . . . . . . . . 102.2.1 System setup . . . . . . . . . . . . . . . . . . . . . . . . . 102.2.2 The acquisition software . . . . . . . . . . . . . . . . . . . 10

    2.3 Desired features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.3.1 Acquisition software update . . . . . . . . . . . . . . . . . 132.3.2 Dual energy microCT . . . . . . . . . . . . . . . . . . . . 132.3.3 Beam hardening correction . . . . . . . . . . . . . . . . . 13

    2.4 Programming details . . . . . . . . . . . . . . . . . . . . . . . . . 142.4.1 Qt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.4.2 The statemachine framework . . . . . . . . . . . . . . . . 15

    3 Updating the image acquisition software 16

    3.1 Solving the major disconnection issue . . . . . . . . . . . . . . . 163.2 Solving the socket issues . . . . . . . . . . . . . . . . . . . . . . . 193.3 Results from the software changes . . . . . . . . . . . . . . . . . 20

    3.3.1 Implementing dual energy scans . . . . . . . . . . . . . . 213.3.2 Protocol creator . . . . . . . . . . . . . . . . . . . . . . . 223.3.3 Updating the GUI . . . . . . . . . . . . . . . . . . . . . . 25

    4 Implementing a beam hardening correction 27

    4.1 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.1.1 Empirical Cupping Correction . . . . . . . . . . . . . . . 274.1.2 Measuring the attenuation of water . . . . . . . . . . . . . 294.1.3 Correction for geometric deviation from the ideal case . . 31

    2

  • 4.1.4 Acquisitions . . . . . . . . . . . . . . . . . . . . . . . . . . 314.1.5 Performing the cupping correction . . . . . . . . . . . . . 33

    4.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.2.1 Measuring the attenuation of water . . . . . . . . . . . . . 354.2.2 Basis images . . . . . . . . . . . . . . . . . . . . . . . . . 354.2.3 Correction using the large water bottle . . . . . . . . . . . 354.2.4 Correction using the small water bottle . . . . . . . . . . 464.2.5 Correction using the homogeneous plastic phantom . . . . 51

    5 Discussion 57

    5.1 The CTGantry software update . . . . . . . . . . . . . . . . . . . 575.2 The cupping correction . . . . . . . . . . . . . . . . . . . . . . . . 58

    6 Conclusion 60

    Appendices 61

    A Code for sustaining a symbolic link for the gantry 62

    B Cupping correction MATLAB software 65

    B.1 getImagesFromNii.m . . . . . . . . . . . . . . . . . . . . . . . . . 65B.2 calcCoe↵.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65B.3 correctImage.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

    3

  • Chapter 1

    Introduction

    Computed Tomography (CT) is an important imaging modality in clinical health-care and research that is widely used around the world today. The first im-plementation of an X-ray CT imaging system was engineered by Hounsfield in1972 [1], following the mathematical framework of the Radon transform. Radonproved that it was possible to reconstruct an image of an object using cross-sectional scans at di↵erent angles[1].

    Using a beam of X-ray radiation one can measure its attenuation as it tra-verses an object at many di↵erent angles. From these projections, a cross-sectional image of the attenuation can be constructed to provide a view of theinternal structure. The School of Technology and Health at KTH has con-structed such a system for performing microCT, in which small objects can beimaged at high resolutions. The system consists of an X-ray source and flatpanel detector, fixed on a gantry rotating around the object to be imaged.

    Prior to this project, there was already software implemented for control-ling the various parts of the imaging system. There were also several methodsimplemented for correcting image artifacts, such as geometrical misalignment,detector inhomogeneity and detector lag e↵ects [10].

    1.0.1 Purpose of study

    The imaging software would unfortunately stop frequently during acquisition,forcing the operator to restart it. Another problem with the software was thatthe user interface was too impractical and complex to use. Therefore, the firstaim of this project was to investigate any software or hardware related issuescausing the acquisition halting, and changing the user interface to allow easieruse. Additional functionality such as dual energy scans and customization ofacquisition protocols was also to be implemented.

    The second part of the project was to implement software to correct foranother image artifact called cupping. It appears as an underestimation of theattenuation values deep inside an object and is caused by a shift in the energyspectrum of the X-ray beam as it traverses the measured object.

    4

  • Chapter 2

    Background

    2.1 CT

    2.1.1 Photons in CT

    The photons used for measuring the attenuation of an object in a CT-scan arecalled X-rays, and are produced by accelerating electrons towards an anodeinside an X-ray tube [3]. The X-rays of interest in CT are typically in the rangeof 100 pm�10 pm, corresponding to energies of 12 keV�120 keV approximately.Photons with higher energies are called hard X-rays and attenuate too little toprovide contrast for clinical purposes. Photons with lower energies on the otherhand, attenuate too much, causing them to quickly be absorbed upon enteringan object.

    2.1.2 X-ray production

    X-rays are produced in X-rays tubes, consisting of an anode and a cathode insidea vacuum filled container [3]. By heating the cathode with a current, electronsbegin to emit from its surface. Because of the potential di↵erence betweenthe cathode and anode, the electrons are accelerated toward the anode. Uponreaching the anode, two di↵erent kinds of X-rays are produced:

    • Bremsstrahlung X-rays.

    • Characteristic X-rays.

    Bremsstrahlung X-rays are created due to the deacceleration and deflectionof the electrons by the potential field of the target nuclei. The energy of anemitted X-ray depend on the kinetic energy of the electron and the direction ofmotion relative to the nucleus it interacts with. Hence, there will be continuousspectrum of X-ray energies ranging up to the potential di↵erence between thecathode and anode, which is the maximum amount of energy an electron candeposit.

    5

  • Characteristic X-rays are produced if the electron transmit enough energyto the nuclei, causing an inner shell electron to be ejected. Then, an electronfrom a higher shell will fill its vacancy, producing an X-ray with energy equalto the energy di↵erence of the two shells.

    In a CT-scan, the adjustable parameters in the X-ray tube is:

    • The voltage between the anode and cathode

    • The cathode current

    • The emission time

    By increasing and decreasing the voltage, the entire energy spectrum is shiftedtowards higher and lower energies respectively, with a peak energy of between1/3-1/2 of the maximum energy. Increasing the voltage also increases the num-ber of emitted X-rays, but in a nontrivial fashion. Increasing the cathode currentor emission time both increases the number of emitted electrons and thereforethe amount of emitted X-rays linearly. Therefore, one can choose between al-tering the tube current or emission time to achieve a certain beam intensity.

    2.1.3 X-ray attenuation

    The entire concept of CT revolves around the fact that di↵erent materials at-tenuate photons di↵erently. The interior of an object is imaged by calculatinga map of the attenuation coe�cient inside it. Below follows a mathematicaldescription of attenuation as found in [2].

    In the simplest case, a homogeneous object is imaged with a monochromaticX-ray beam. The number of X-ray interactions is proportional to the num-ber of X-rays, with a proportionality constant µ called the linear attenuationcoe�cient. This gives the following relation:

    dN = �µNdx (2.1)

    where µ is the linear attenuation coe�cient and depends both on the objectmaterial and the X-ray energy. X is the distance traveled inside the attenuatingobject. Solving this di↵erential equation yields:

    N = N0e�µx (2.2)

    where N0 is the number of X-rays entering the object. A more often usedquantity is the beam intensity I. This is defined as the total energy of allphotons passing through a cross section perpendicular to the beam directionper unit time and area. In other words, I = E�, where � is the photon fluencerate, � = N

    At

    , where N is the number of photons, A is the cross-sectional area ofthe beam and t is the time. Using this definition, eq (2.2) can be rewritten as:

    I = I0e�µx (2.3)

    However, for polyenergetic beams, eq(2.2) and eq(2.3) are no longer valid.Instead, define the line spectrum S(E) as the number of photons with energy E

    6

  • passing through the beam cross section per unit time. Then, the photon fluenceand beam intensity can be written as:

    � =

    Z 1

    0S(E0)dE0 (2.4)

    and

    I =

    Z 1

    0E

    0S(E0)dE0 (2.5)

    Moreover, for a non-homogeneous object the attenuation coe�cient will de-pends on the position in the object. Eq (2.1) then changes to:

    dN = �µ(x)Ndx (2.6)

    Solving this di↵erential equation yields the number of photons at position x:

    N(x) = N0e�

    R 10 µ(x

    0)dx0 (2.7)

    Since the attenuation coe�cient also depends on the energy, one gets a similarexpression for the line spectrum. Now, the attenuation coe�cient also dependson the energy.

    S(x;E) = S0(E)e�

    R 10 µ(x

    0;E)dx0 (2.8)

    Finally, to get the intensity of the beam one multiplies eq (2.8) with the currentenergy, and integrates over all energies.

    I(x) =

    Z 1

    0S0(E

    0)E0e�R 10 µ(x

    0;E0)dx0dE0 (2.9)

    Unfortunately, eq (2.9) is not very useful in practice due to its mathematicalcomplexity and since most microCT systems are energy integrating, i.e. theymeasure the total intensity instead of individual hits. Instead, a common tech-nique is to define an e↵ective energy such that the a monochromatic beam withe↵ective energy Ē would have the same intensity as a polychromatic beam withthe same number of photons. Since I = E�, then E = I

    , or using equation

    (2.4) and (2.5):

    E =

    R10 E

    0S(E0)dE0

    R10 S(E

    0)dE0(2.10)

    The assumption that a polychromatic beam can be viewed as a monochromaticbeam with e↵ective energy Ē is a useful tool in CT, since now each point insidethe object can be assigned a single attenuation µ(x), simplifying equation 2.9to:

    I(x) = S0(Ē)Ēe�

    R 10 µ(x

    0;Ē) = I0e�

    R 10 µ(x

    0;Ē)dx0 (2.11)

    which can be used for image reconstruction.The linear attenuation varies proportionally with the density of a material.

    Therefore, it is common to normalize the attenuation with respect to the density,yielding the mass attenuation coe�cient µ/⇢ in units cm2 g�1. The massattenuation coe�cient is constant for a material in di↵erent states.’

    7

  • 2.1.4 Image acquisition and reconstruction

    A CT acquisition is performed by shooting an X-ray beam through the objecttowards a detector at di↵erent angles with respect to the object being imaged.There are several variations of this, but a simple method is a step-and-shootacquisition, in which the object is alternately illuminated and translated per-pendicularly with respect to the beam direction [2]. This is repeated for allangles. CT detectors are typically energy integrating, meaning that the valueobtained is the total energy deposited, which is related to the beam intensity I.However, in equation 2.11 the intensity before entering the object, I0 is neededas well. I0 is often determined by performing a so called lightfield acquisition,in which no object is present such that all X-rays hit the detector.

    The value read out by that the detector is increased by electronic noise in thedetector, which depends on both the temperature and which pixel is read out.Therefore, both the image acquisition and the lightfield has to be subtractedwith the dark current for each pixel.

    The CT acquisition geometry is depicted in figure 2.1. For CT, the functionf(x, y) may represent the attenuation µ(x, y), while the projection of f(x, y)onto the l-axis called g(l, ✓) is the integral of µ(x, y) through the object. Thisintegral is the same as the integral of equation 2.11. g(l, ✓) can therefore berepresented by � ln( N

    N0).

    Figure 2.1: The geometry of a parallel beam step-and-shoot acquisition.

    8

  • An important theorem for image reconstruction is the Fourier slice theorem,which states that the 1D fourier transform of a single projection at an angle✓ is equal to a slice, i.e. a line passing through the origin, of the 2D fouriertransform of the entire function. The proof begins with g(l, ✓), given by theintegral of f(x, y) along a line s.

    g(l, ✓) =

    Z 1

    �1f(x(s), y(s))ds (2.12)

    with the chosen coordinate system, x(s) and y(s) are given by:

    x(s) = l · cos(✓)� s · sin(✓) (2.13)

    y(s) = l · sin(✓) + s · cos(✓) (2.14)

    hence, g can be rewritten as:

    g(l, ✓) =

    Z 1

    �1

    Z 1

    �1f(x, y)�(x · cos(✓) + y · sin(✓)� l)dxdy (2.15)

    For a fixed ✓, this is the projection of the object. By taking the 1D fouriertransform of the projection one obtains:

    G(⇢, ✓) =

    Z 1

    �1

    Z 1

    �1

    Z 1

    �1f(x, y)�(x · cos(✓) + y · sin(✓)� l)e�j2⇡⇢ldxdydl =

    (2.16)

    G(⇢, ✓) =

    Z 1

    �1

    Z 1

    �1f(x, y) · e�j2⇡(x·cos(✓)+y·sin(✓))dxdy (2.17)

    Now, taking the 2D fourier transform of f(x, y):

    F (u, v) =

    Z 1

    �1

    Z 1

    �1f(x, y)e�j2⇡(xu,yv)dxdy (2.18)

    For u = ⇢ · cos(✓), v = ⇢ · sin(✓) eq 9 is equal to eq 8, i.e. G(⇢, ✓) = F (⇢ ·cos(✓), ⇢ · sin(✓)), which proves the fourier slice theorem [2].

    The theorem above can be used to perform a simple image reconstruction.By applying the 1D fourier transform on each projection g(l, ✓) and then apply-ing the inverse 2D fourier transform on the obtained dataset G(⇢, ✓), the imagef(x, y) is readily obtained.

    f(x, y) = F�1G(⇢, ✓) (2.19)

    Recall that f(x, y) is the attenuation coe�cient µ(x, y) and g(l, ✓) is the logattenuation � ln( N

    N0).

    9

  • 2.1.5 MicroCT

    MicroCT is designed to achieve resolution on a micrometer scale, which is muchhigher than ordinary CT that typically operates on the millimeter scale. This isuseful for high resolution images of small objects, either for industrial purposesor small animal imaging. When imaging animals, it is worth noting that all elseleft unchanged, the dose delivered is inversely proportional to the length of theimage voxel raised to the fourth power [1]. Hence, doubling the resolution willcause 16 times the delivered dose. Therefore, careful consideration has to betaken for in-vivo imaging to achieve as low dose as possible.

    2.2 The STH microCT

    2.2.1 System setup

    The School of Technology and Health has developed a system for performingmicroCT. The system consists of a microfocus X-ray source and a flat paneldetector mounted with a fixed distance on a rotating gantry. They can betranslated with respect to the rotational center to achieve a desired magnifi-cation factor. On the gantry there is also a frame grabber for image readoutand a computer for user control and image storage. During an acquisition, thewhole gantry is step wise rotated, with an image taken at each step. This isdone using a stepper motor, connected to the computer through a slip-ring.

    The system specifications are:

    • X-ray source: Hamamatsu microfocus X-ray source, product L10951-04.

    • Detector: Hamamatsu CMOS flat panel sensor, product C7942CA-22.

    • Gantry: Mekanex Stainless steel ring and Stepping motor-gearhead-driverAR98MC-H100-3 controlled by SCX11 universal controller from Oriental-motor.

    • Slip ring: Penlink, product PL025-56-4P-36S.

    • Frame grabber: Epix Pixci board, product D2X-C7942, controlled withXCAP libraries.

    • Computer: PCM-9562N-S6A1E from Advantech

    The system is depicted in figure 2.2

    2.2.2 The acquisition software

    At the beginning of this project, there was already software implemented forbasic control the microCT system, called CTGantry, written by Ivan Valastyan.A graphical user interface was implemented, as well as code for the controllingfor di↵erent parts of the system and the communication between them. The code

    10

  • Figure 2.2: The STH microCT imaging system

    was written in Qt, which is a C++ based framework for developing platformindependent application software.

    The graphical user interface of CTGantry was used to enter settings for theacquisition to be performed. The available options were:

    • Starting and ending angle

    • Angular step size

    • Tube voltage, current and pulse width

    • Number of images before, during and after illumination with the X-raytube

    • Pixel binning

    • Frame time

    • Rotation speed

    When the user starts the acquisition, all options are saved to a protocol classwhich is sent to the CTDaq class that handles the acquisition. CTDaq thencreates steps according to the protocol and connects them in a loop as visualizedby figure 2.3. The first step is an initialization step in which the X-ray tube,GPIO, frame grabber and gantry settings are sent to the respective device, and

    11

  • Figure 2.3: Schematic view of a microCT-scan using the STH microCT system.

    the frame grabber begins capturing frames continuously. The program thenenters the acquisition loop.

    During the ”snap image” step the main program sends a signal to the framegrabber, telling it that it is ready to acquire an image. The main program thenenters the ”time delay” step, in which it waits to ensure that it stays stationaryuntil the image is done. Meanwhile, the frame grabber waits until it reaches thebeginning of a frame and sends a trigger through the GPIO to the X-ray tubesuch that it emits X-rays during the frame. As the frame ends, its content iswritten to a file.

    After the ”time delay” step, the program enters the ”rotate” step, in whicha signal is sent to the gantry telling it to rotate to the next angular position.After the rotation is done, a signal is returned to the main program such thatit again enters the ”snap image” step, see figure 2.3. It then alternates betweenthese three steps until an entire acquisition is done.

    12

  • Following an acquisition, there were also a reconstruction program imple-mented by Sebastian Andersson [11], and programs for correction of some com-mon imaging artifacts such as geometric misalignment and detector lag, writtenby Lorenzo Di Sopra [10]. Geometric misalignment is an artifact caused by in-su�cient positional accuracy and detector lag is an artifact caused by residualsignal left in the detector after readout.

    2.3 Desired features

    2.3.1 Acquisition software update

    For the STH microCT system, there was a desire for more flexibility in thesystem. Specifically, the user should be able to run di↵erent imaging protocolsthan the one already implemented. For example, step sizes or tube settingsshould be able to vary during an acquisition to better suit the task at hand.

    Another change to be made was to make the program more user-friendly byaltering the GUI, as well as fixing some bugs causing the program to halt duringacquisition.

    2.3.2 Dual energy microCT

    A feature specifically wanted on the STH microCT was the ability to performdual energy scans, i.e using two di↵erent energy spectra during a single scan.This is useful since since the attenuation coe�cient depends not only on thematerial, but also the energy. An example of an application is base materialdecomposition, in which one can get material selective images, density maps orattenuation maps by making superpositions of either the raw projection data orthe reconstructed images. [8].

    There are di↵erent methods for performing a dual energy scan. In a stepand shoot scanner, two scans can be performed subsequently with di↵erent tubevoltages and therefore di↵erent energy spectra. Another option is to acquiretwo images at each angle, rapidly switching the voltage between them. A thirdoption is to have two sets of X-ray tubes and detectors operating simultaneously,o↵set by 90 degrees.

    2.3.3 Beam hardening correction

    A common artifact in CT-imaging is the cupping artifact, which appears as anunderestimation of the attenuation in the middle an imaged object. The artifactarises as a result of beam hardening, which is a gradual hardening, i.e. shifttoward higher energies, of an X-ray beam as it traverses the object.

    The reason for this hardening is that X-ray interaction probability is highlydependent on photon energy, causing low energy X-rays to more quickly beabsorbed or scattered out of the beam. Hence, the mean energy of the remainingbeam is raised, allowing it to more easily penetrate the rest of the object.

    13

  • When reconstructing an image from the projections, the projections goingthrough a lot of material will correspond to a harder X-ray beam. Thus, themean attenuation of that particular projection is lower compared to a beamgoing through less material. This poses a problem when reconstructing theimage, since the attenuation in the middle of the object is underestimated. Forthe STH microCT system it was desired to have a method of correcting thisunderestimation.

    There already exists several di↵erent strategies for removing beam hardeningartifacts from CT images. These strategies include: Iterative corrections [4],dual energy scanning [5], filtering [6] and linearization [7]. The strategy used inthis thesis for the STH microCT is a linearization technique known as empiricalcupping correction as described by Kachelrieß, Sourbelle and Kalender [7].

    2.4 Programming details

    2.4.1 Qt

    As mentioned earlier, the STH image acquisition was written in Qt, which isbased on C++ but with some additional features. The most important onesare:

    • The Qt signals and slots system, which allows for easy communicationbetween objects.

    • Introspection, which allows for examining objects during runtime, to ob-tain information such as the object type.

    • The Qt parenting system, which allows for easier GUI programming andhandling of pointers.

    All these features are utilized by using certain functions or keywords in the writ-ten code. The Qt ”Meta Object Compiler” (MOC) then generates additionalC++ code providing the desired feature.

    For the signals and slots system, the keywords are:

    • signal X. This is written in the C++ header file to declare a signal X

    • slot Y. This is written in the C++ header file to declare a slot Y. The slotis also a function, and is defined in the C++ source file.

    • connect(object1,SIGNAL(X),object2,SLOT(Y)). This connects the signalX of object1 to the slot Y of object 2.

    • emit(X). This emits signal X to each slot connected to it through theconnect keyword, causing the slot function to be called.

    It is possible to connect the same signal to several slots, or several signals tothe same slot.

    14

  • The introspection feature is implemented di↵erently depending on what typeof information is wanted. For example, the object type can be found by writingqobject cast < class1⇤ > (object1), which returns NULL if object1 is not partof class1.

    The parenting system is utilized by assign a parent when an object is created,resulting in tree structures. Then, as soon as an object is deleted, all its childrenare as well. Hence, memory leaks can easily be avoided.

    2.4.2 The statemachine framework

    The states in figure 2.3 were implemented as part of a framework in Qt called thestatemachine framework, which is an e↵ective tool in managing di↵erent statesand transitions between them. The statemachine framework mainly consists oftwo classes:

    • QAbstractState: This class is inherited by state classes created by theuser. The functionality of the state is defined in its ”run” function, whichis called as the state is entered.

    • QStateMachine: This is a class to which all states are added, and handlesstarting the statemachine and transitions between states.

    A statemachine is created by first implementing a custom State class inher-iting the QAbstractState. By overloading its ”run” function, the functionalityof the state is defined. Then, states are connected by the QAbstractState func-tion ”addTransition”, in which information about which state should come nextis provided. When all states are created and connected properly, they can beadded to the state machine through its ”addState” function and started.

    15

  • Chapter 3

    Updating the imageacquisition software

    3.1 Solving the major disconnection issue

    One of the major issues with the STH imaging software at the beginning of thisproject was that the program would occasionally crash during acquisition, eitherprinting ”Timeout” in the output window or producing a large error messagedepicted in figure 3.1.

    The origin of the timeout message was found to be in the controlling of theCTGantry parts. The communication with the parts was structured such thatthere were four classes in the main program, handling input and output to theGUI and statemachine.

    • EpixD2X - frame grabber

    • OrientalX11 - gantry rotation

    • XRayTube

    • GPIO

    These classes all had a corresponding classes that were run in separate pro-grams, responsible only for the direct communication with the physical gantrydevices:

    • EpixD2X2Net

    • Serial2Net - gantry rotation and X-ray tube

    • GPIO2Net

    The communication betwen the main program classes and the 2Net classeswere performed using TCP sockets. The reason for this division was that the

    16

  • Figure 3.1: Error message upon program crash

    17

  • 2net classes should be able to be run on a computer attached to the gantry,while the main program could be run on an external computer connected to thegantry through a network. However, in the current setup everything was runon the same computer, connected to each other through the loopback ip adress127.0.0.1.

    The origin of the error message was the CommandBu↵er class, which wasresponsible for storing commands from the CTGantry and the user and to sendthem one at a time to the corresponding 2Net class. Each of the device classeson the main program side had their own CommandBu↵er to which they wouldadd their commands. The CommandBu↵er would then store the commands inan array until it gets an opportunity to send them through the correspondingsocket. Then the CommandBu↵er would await an answer from the 2net class,and if an answer would not be received, the timeout message would be printed.

    To attempt to find the reason for this error, several program prints wereadded to trace the command from start to finish. The command flow is illus-trated in figure 3.2.

    Figure 3.2: Command flow of the acquisition software.

    The error was found to be originating in the Serial2Net class being respon-sible for the rotation of the gantry. More specifically it was the function thatsends the command to the actual device. It does so utilizing an external librarycalled ”Qextserialport” which provides an interface between the Qt libraries andserial ports. When using the Qextserialport function to write to the device, itreturns an integer equal to the number of bytes successfully written. Whenthe error occurred, it was found that the function simply returned -1, whichaccording to the manual meant that there was a writing error.

    To explore the reason for the writing error, the settings of the Qextserial-port were investigated. The port was connected via a USB called TTYUSB0inside the /dev folder. However, when running the program it was found thatsometimes the TTYUSB0 would disappear and return renamed TTYUSB1. Aprobable reason for this is a connection issue between the gantry and computer.As the connection was lost the TTYUSB0 disappeared, but when the connec-tion was reestablished, the TTYUSB0 was still occupied since the program stillwas connected to it. Instead the next port, TTYUSB1, was selected. But sincethe program still was writing to TTYUSB0, the command was lost.

    Since the origin of the connection issue could not be found, the solution was

    18

  • to add a rule in the form of an additional file in the folder /etc/udev/rules.d, toautomatically maintain a symbolic link called /dev/gantry that would alwayspoint to the appropriate TTYUSB. This was performed using the vendor ID,product ID and serial ID of the gantry. However, additional code had to beadded to the program to disconnect and reconnect the Qextserialport to get thenew TTYUSB from the /dev/gantry link and to send the message again, seeappendix A. To guarantee that no messages were lost neither from the gantrynor any other device, a ”while” loop was added to the commandbu↵er suchthat messages that did not receive an answer were resent instead of displayingthe timeout message. This solution reduced the number of software crashesdramatically.

    3.2 Solving the socket issues

    Despite the e↵orts in the previous section, the system would still stop occa-sionally, either producing no input at all, printing ”QSocketNotifier: Invalidsocket XX and type ’Read’, disabling” or giving the large error message shownin figure 3.1. Despite great e↵orts to analyze them, the cause of the last twoerrors remain unknown. At this time, another problem was discovered whichwould randomly cause the rest of the projections to be made without usage ofthe X-ray tube. How and when this problem appeared is unknown.

    While debugging, the cause of the first problem mentioned above was foundto also be caused by the sockets. The sending of messages from the mainprogram device classes malfunctioned, causing the commandbu↵er to try tosend the same message repeatedly without receiving an answer while a largestack of messages was piling up behind it. Debugging the 2net classes showedthat indeed the messages were not being received, indicating that the socketswere unable to transmit messages.

    The cause of the socket malfunction was not found. Instead, the decisionwas made to remove the usage of sockets and incorporate the 2net classes intothe main program. This was a simple solution to the socket problems sincethe computer running the main program was already mounted on the gantry,removing the need of communicating through a network. The main file code foreach 2net class was moved into the respective initialization function, which wascalled by the main program after creating an instance of the class. The socketswere then replaced by ordinary QByteArrays.

    To mimic the functionality of the sockets, both the client side and serverside classes had to be altered. To notify that there was data to be read, theprogram had initially relied upon the ”readyRead” signal of the socket class,which is called when there is data to be read. The signal was connected to the”socketDataAvailable” slot. Now, a new signal was implemented for each classand connected to the ”socketDataAvailable” slot. The signal was then fired asdata was written to the QByteArray.

    The solution presented above solved the remaining problems regarding soft-ware crashes when performing acquisitions.

    19

  • 3.3 Results from the software changes

    The solution presented in section 3.1 reduced the number of crashes dramat-ically. However, as stated in section 3.2, some issues regarding sockets stillremained. The change from sockets to having the 2net classes incorporated intothe main program solved these issues completely. This change had the addi-tional benefit of saving the operator of the system from having to start all four2net class programs.

    The problem regarding images being acquired without using the X-ray tubewas partially solved as well when removing the sockets. Some images would stillbe made with much fewer X-rays than they were supposed to, but the followingimages would still be correct. It was found that there was a bug regardingthe timing of the X-ray pulses. During an acquisition, it is possible to selectthe number of ”before”, ”during” and ”after” images. The ”before” images aretaken before the X-ray tube is turned on. The ”during” images are taken duringthe X-ray pulse. Finally, the ”after” images are acquired immediately after theX-ray pulse ends.

    This allows for the lag correction described by Lorenzo Di Sopra [10]. How-ever, it was found that depending on the frame time selected the X-ray tubewould be turned on for both the ”during” and ”after” images. Moreover, forthe images missing X-ray radiation, the ”after” images would also be partiallyirradiated.

    Images of a water bottle are depicted in figure 3.3. The first three area normal acquisition, although with the bug causing the ”after” image to beirradiated. The final three are of an acquisition with only partial radiation onboth the ”before” and ”after” image.

    Unfortunately there was not enough time to correct this error, and it is anissue that will have to be investigated in the future, since reconstructing animage with faulty projections may cause severe artifacts.

    20

  • (a) (b) (c)

    (d) (e) (f)

    Figure 3.3: Projection images of a water bottle. (a), (b) and (c) are the ”before”,”during” and ”after” images at the 75:th projection. (d), (e) and (f) are the”before”, ”during” and ”after” images at the 76:th projection.

    3.3.1 Implementing dual energy scans

    As seen in section 2.3.2, dual energy was a desired feature on the STH microCTsystem. To implement this, the statechart in fig 2.3 was altered by adding asecond snap state and time delay state in the loop between the first ones andthe rotation state.

    To be able to control the voltage and current, additional code was added tothe GUI to allow the user to select either normal CT or CT with dual energyand to enter values for the second image. The protocol class was altered to allowstorage of multiple values of current and voltage and the snap state was changedto take the current and voltage as input parameters and update the X-ray tubeaccordingly in its ”run” function. Then, at the creation of the statemachine,one snap states would be made with the first set of voltage and current, andthe other snap state would be made with the other set. The states would thenbe linked according to fig 3.4 and added to the statemachine.

    21

  • Figure 3.4: Schematic view of the statemachine for a dual energy CT-scan

    3.3.2 Protocol creator

    To give the user even more options in defining the scan, a tool for making andusing custom protocols was created. The tool is depicted in figure 3.5.

    As can be seen, it is possible to define each projection by setting its angle,current and voltage. When added, the projections are listed in order in thewindow to the left. Projections can also be selected and removed from the list.The tool also allows the user to save and load protocols as text files. The listeditems are created as instances of the Qt class QVariant, which is a containerthat allows variables of di↵erent types to be stored together. Therefore, the toolcan easily be extended to allow even more customization if desired by simplyadding more variables to the QVariant and having appropriate input windowsin the GUI.

    The rest of the program was also altered to allow the usage of the customprotocols created by the protocol creation tool. A button on the main GUI wasadded to let the user choose to use a custom protocol. The CTDaq class wasalso changed to use another method than the simple circular linking shown infigures 2.3 and 3.4. For custom protcols, the CTDaq would instead create a long

    22

  • Figure 3.5: The protocol creator GUI.

    chain of states as depicted in figure 3.6, put together using a for-loop. Insidethe loop, four steps handled the creation, linking and adding of the states:

    • Create a new set of states according to the protocol

    • Add a transition from the old states to the new states. Also add connec-tions between the new states.

    • Add the old states to the statemachine

    • Rename the new states to old states

    Of course, the same initialization states as before were created before the loopand a first set of acquisition states were created to fill the roles of the old states

    23

  • in the first iteration of the loop. After the loop, a transition was added fromthe last state in the chain to the ”Finished” state.

    Figure 3.6: Schematic view of the statemachine for a custom protocol microCTscan

    24

  • 3.3.3 Updating the GUI

    Many unnecessary input fields and buttons were removed to simplify the usageof the CTGantry program. Options rarely changed were moved to menus foradvanced control. An option to rotate the gantry in between acquisitons to moreeasily perform single projections was also implemented, as well as an option tomake the gantry rotate to its original position. Buttons to access all theseoptions as well as opening the protocol creator were all added. Furthermore, arotating picture of the gantry was added, allowing a user to see the rotation ofthe gantry in real-time during a scan. The LCD-numbers displaying the angleof the gantry was changed to only display angles between 0 and 360 degrees.

    For the STH micro-CT system, the frame time of the detector has to be atleast 500 µs longer than the pulse width of the X-ray tube to ensure that theentire pulse fits within the frame. Therefore, the window controlling the frametime was changed to automatically update according to the set pulse width,thus reducing the amount of necessary user inputs. Finally, the status label waschanged to update more frequently, as well as showing whether the gantry iscurrently rotating or acquiring an image instead of simply stating if the systemis running or finished. The old GUI and the updated GUI are shown in figure3.7 and 3.8 respectively.

    Figure 3.7: The old GUI.

    25

  • Figure 3.8: The updated GUI.

    26

  • Chapter 4

    Implementing a beamhardening correction

    4.1 Method

    4.1.1 Empirical Cupping Correction

    The core of the empirical cupping correction method by Kachelrieß, Sourbelleand Kalender [7] is the assumption that each image f(r) can be decomposed toa set of basis images f

    n

    (r). These corrected image is ideally reconstructed fromthe corrected projection data p(r), which is created from the raw projectiondata q(r). Let P be a correction function, such that

    p(r) = P (q(r)) (4.1)

    Here, P is defined to raise q(r) to the power of 0,1,2... and sum the obtainedbasis data with correction coe�cients c, such that

    p(r) =X

    n

    c

    n

    q

    n

    (r) (4.2)

    where qn

    (r) = q(r)n. The image f(r) can be reconstructed from the correctedprojection data p(r) through some reconstruction method such as the inverseradon transform,

    f(r) = R�1p(r) (4.3)

    Similarly, a set of basis images can be reconstructed by using the basis dataq

    n

    (r)f

    n

    (r) = R�1qn

    (r) (4.4)

    Using the linear properties of the radon transform, equation (12) can be rewrit-ten as

    f(r) = R�1X

    n

    c

    n

    q

    n

    (r) =X

    n

    c

    n

    R

    �1q

    n

    (r) =X

    n

    c

    n

    f

    n

    (r) (4.5)

    27

  • Now, the goal is to calculate cn

    such that the image f(r) as closely as possiblerepresent the real object. This can be performed by reconstructing the imageof a phantom of the same material one wishes to correct for. In this study, awater phantom is used. Then, a template image t(r) is defined such that

    t(r) =

    8><

    >:

    µ

    water

    when r is inside the phantom

    µ

    table

    when r is inside the table

    µ

    air

    = 0 when r is outside of the phantom

    (4.6)

    A weight image is also defined with the purpose of extracting the part of theimage to correct for, i.e. the phantom as well as part of the air surrounding it.

    w(r) =

    (1 when r is inside the phantom

    0 when r is outside of the phantom(4.7)

    Then, the coe�cients cn

    can be calculated through minimizing least square errorbetween the corrected image f(r) and the template image t(r).

    E

    2 =

    Zdr w(r)(f(r)� t(r))2 =

    Zdr w(r)(

    X

    n

    c

    n

    f

    n

    (r)� t(r))2 (4.8)

    Switching to Einstein notation and deriving with respect to the coe�cients cn

    yields:

    @

    i

    E

    2 = @i

    Zdr w(r)(c

    j

    f

    j

    (r)� t(r))(ck

    f

    k

    (r)� t(r)) (4.9)

    @

    i

    E

    2 =

    Zdr w(r) (

    @c

    j

    @c

    i

    f

    j

    (r)(ck

    f

    k

    (r)� t(r)) + (cj

    f

    j

    (r)� t(r))@ck@c

    i

    f

    k

    (r)) (4.10)

    @

    i

    E

    2 =

    Zdr w(r) (�

    ij

    f

    j

    (r)(ck

    f

    k

    � t(r)) + �ik

    f

    k

    (r)(cj

    f

    j

    (r)� t(r))) (4.11)

    @

    i

    E

    2 =

    Zdr w(r) (f

    i

    (r)(ck

    f

    k

    � t(r)) + fi

    (r)(cj

    f

    j

    (r)� t(r))) (4.12)

    @

    i

    E

    2 = 2

    Zdr w(r) f

    i

    (r)(cj

    f

    j

    (r)� t(r)) = 0 (4.13)

    This yields Zdr w(r)f

    i

    (r)t(r) =

    Zdr w(r)f

    i

    (r)cj

    f

    j

    (r) (4.14)

    Eq 4.14 tells us the way in which the coe�cients will be calculated. Not onlyshould the corrected image match the template image, but when summing overall pixels, the projection of the corrected image onto each basis image shouldbe equal to the projection of the template image onto the same basis image.

    Since c does not depend on the position r, one can write ai

    =Rdr w(r)f

    i

    (r)t(r),B

    ij

    =Rdr w(r)f

    i

    (r)fj

    (r), such that:

    a

    i

    = Bij

    c

    j

    (4.15)

    28

  • From the raw projection data, ai

    and Bij

    can be calculated. Then the correctioncoe�cients can be calculated from the system of linear equations in eq 4.15. Thecoe�cients can be used to correct other images through:

    f(r) = R�1p(r) = R�1X

    n

    c

    n

    q

    n

    (r) = R�1X

    n

    c

    n

    q

    n(r) (4.16)

    For optimal correction, the coe�cients should be calculated for each objectthickness and type of material one wishes to correct for. [7]

    In equation 4.6, the attenuation coe�cient of water have to be estimated toprovide the ideal image to which one tries to correct for. However, the tableis of less importance, but still has to be dealt with. As described in [7] thereare two solutions to this problem. The first is to ignore the table by setting theweight image to be zero inside the table, thus ignoring any contribution fromit. Another is to redefine the template image in the following way:

    t(r) = t0(r) + t00(r)µtable

    (4.17)

    Here, t0(r) is the new template without the table and t00(r) is a template whichis 1 inside the table and 0 outside the table. The right hand side of equation4.8 can then be reordered as:

    E

    2 =

    Zdr w(r)(

    X

    n

    c

    n

    f

    n

    (r)�t(r))2 =Z

    dr w(r)(X

    n

    c

    n

    f

    n

    (r)�t0(r)�t00(r)µtable

    )2

    (4.18)

    E

    2 =

    Zdr w(r)(

    X

    n+1

    c

    n

    f

    n

    (r)� t(r))2 (4.19)

    The template of the table has been incorporated as cn+1fn+1 by defining cn+1 =

    µ

    bed

    and fn+1 = �t00(r). The problem can then be solved as previously, and

    µ

    table

    is obtained as the last correction coe�cient. Note that the water templateis defined to have the value µ

    water

    inside the water phantom, while the bedtemplate is defined to have the value 1 inside the bed.

    4.1.2 Measuring the attenuation of water

    To perform the cupping correction, the attenuation of water to be used forthe template (4.6) had to be found. However, since the attenuation is energydependent and the beam is polychromatic, it has no single value and had to beestimated. The estimation was done by freezing a 1.02 cm thick slab of water andacquiring images of it using a pinhole, without rotating the gantry. A picture ofthe experimental setup can be seen in figure 4.1. The same acquisition settingsas the ones to be used for the correction were used in order to receive theapproximate attenuation for the relevant X-ray spectrum. The settings were:

    29

  • Figure 4.1: The experimental setup for measuring the attenuation of water.

    • Voltage: 40 kVp

    • Current: 600 µA

    • Pulse width: 1500 ms

    • Frame time: 2000 ms

    30

  • The voltage was chosen to give good contrast for the material and dimensionsof the objects to be scanned during the correction. If the voltage is too low, theX-ray beam will quickly be attenuated due to the low energy and a low contrastwill be achieved. If the voltage is too high, the X-ray beam will barely attenuateat all and the resulting contrast will again be too low. The rest of the settingswere chosen to give enough counts while avoiding oversaturating the detector.

    100 images were taken in sequence, followed by 100 images of the lightfieldand 100 images of the dark current. The attenuation was calculated usingequation 4.20.

    µ = � 1x

    ln(N

    measured

    �Ndarkcurrent

    N0,measured �Ndarkcurrent) (4.20)

    Here, the attenuation is assumed to be constant throughout the slab.

    4.1.3 Correction for geometric deviation from the idealcase

    Before the acquisition of the phantom could begin, the source to object distancehad to be adjusted such that the entire phantom could fit inside the field ofview. Then a calibration had to be performed to correct for any positionaland rotational misalignment. The calibration was done using a phantom withseveral metallic spheres embedded in a line, shown in figure 4.2. When thegantry is rotated around the phantom, the spheres form elliptical trajectorieswith respect to the gantry. These trajectories are calculated and used by amisalignment correction program written by Lorenzo Di Sopra [10] to calculatethe following misalignment parameters:

    • The positional displacement in the x- and y-axis.

    • The skew around the rotational axis.

    • The source to detector distance.

    • The source to center of rotation distance.

    • The magnification factor.

    The misalignment parameters were then entered into the reconstruction soft-ware implemented by Sebastian Andersson [11] to be used when reconstructingthe images for the cupping correction.

    4.1.4 Acquisitions

    All acquisitions were performed using the same system settings. The voltagewas set to 40 kVp with 600 µA current, 1500 ms pulse width and 2000 ms frametime. For each acquisition, 360 projection images were taken with an angularstep size of 1 degree. After this, a lightfield acquisition was performed with the

    31

  • Figure 4.2: The phantom used for the geometrical misalignment correction.

    same settings but no object, followed by a dark current acquisition with the X-ray tube switched o↵. The images were then reconstructed using the Feldkampoption of Sebastian Andersson’s program. To obtain the basis images for thecupping correction, the code was altered slightly to also create images where theinput log-attenuation to the Feldkamp algorithm was raised to di↵erent powers.

    The following objects were imaged:

    • A large water-filled bottle with a diameter of 6.25 cm.

    • A small water-filled bottle with a diameter of 2.86 cm.

    • A homogeneous plastic phantom with a diameter of 5.04 cm.

    • A QRM MicroCT Low Contrast Phantom V1.

    All imaged objects are depicted in figure 4.3The QRM phantom is a cylindrical phantom with a diameter of 3.20 cm.

    The base material is resin and it has four cylindrical inserts with a di↵erence inHounsfield units of 4% and 8%, corresponding to -40HU and -80HU with respectto the base material. There are two inserts of each sort, one with a diameter of1.0 mm and one with a diameter of 2.5 mm.

    32

  • (a) (b)

    (c) (d)

    Figure 4.3: All objects imaged when performing the cupping correction: (a) isthe large water bottle, (b) is the small water bottle, (c) is the homogeneousplastic phantom and (d) is the QRM phantom.

    4.1.5 Performing the cupping correction

    The output of the reconstruction program was data saved in a file format callednifti files, which are common for medical imaging. MATLAB function were

    33

  • implemented to obtain the reconstructed images from them, select a slice inthe rotational plane, calculate the coe�cients for the correction and performthe correction. The functions are available in appendix B. Since the noise wasfound to be too high using a single slice, an average of 250 slices were usedinstead. The template and weight images were produced by selecting regions ofinterest using the MATLAB ”roipoly” function on the non-corrected image.

    Several tests of the cupping correction were made to investigate the behaviorof it when applying coe�cients calculated on one object to another object ofdi↵erent size and material. The following tests were performed:

    • The large water bottle was used to calculate correction coe�cients. Thecoe�cients were then applied to:

    – The large water bottle itself

    – The small water bottle

    – The QRM phantom

    – The plastic phantom

    • The small water bottle was used to calculate correction coe�cients. Thecoe�cients were then applied to:

    – The large water bottle

    – The small water bottle itself

    – The QRM phantom

    – The plastic phantom

    • The plastic phantom was used to calculate correction coe�cients. Thecoe�cients were then applied to:

    – The large water bottle

    – The small water bottle

    – The QRM phantom

    – The plastic phantom itself

    The water template, weight and table template used for the large waterbottle, small water bottle and plastic phantom are shown in figures 4.5, 4.4 and4.6 respectively. µ

    water

    was set to the value obtained from the measurementin section 4.1.2 for the first two measurements. For the plastic phantom theattenuation had not been measured, and it was therefore estimated by averagingover the attenuation in the uncorrected image.

    For all three sets of coe�cients, the contrast to noise ratio was calculated forthe uncorrected and corrected images of the QRM phantom. The contrast tonoise ratio was calculated by selecting a region inside each insert as target anda region outside as background, while excluding the border in between where itis uncertain if the pixel belongs to the insert or not.

    34

  • (a) (b)

    (c)

    Figure 4.4: Binary images used for the cupping correction using a small waterbottle. (a) is the phantom template, (b) is the weight image and (c) is the tabletemplate

    4.2 Results

    4.2.1 Measuring the attenuation of water

    The attenuation was measured toN

    N0= 0.5698, giving the attenuation coef-

    ficient from eq 2.2, µice

    = � log 0.56981.02cm

    = 0.5514 cm�1. The attenuation for

    liquid water is then µwater

    =⇢

    water

    ice

    µ

    ice

    =1 g cm�3

    0.9167 g cm�3⇥ 0.5514 cm�1 =

    0.6015 cm�1.

    4.2.2 Basis images

    4.2.3 Correction using the large water bottle

    Table 4.1 presents the coe�cients calculated using eq 4.15 when using the largewater bottle as template. µ

    table

    = c9 was found to be 0.526 cm2/ g. Figures4.11, 4.12 and 4.13 display the result of applying this correction to the largewater bottle itself, the small water bottle and the QRM phantom respectively.

    35

  • (a) (b)

    (c)

    Figure 4.5: Binary images used for the cupping correction using a large waterbottle. (a) is the phantom template, (b) is the weight image and (c) is the tabletemplate

    Basis image 0 1 2 3 4 5 6 7 8 9Coe�cient value -0.038 0.763 0.282 -0.190 0.107 -0.054 0.016 0.001 -0.001 0.526

    Table 4.1: Coe�cient values corresponding to each basis image for the correctionusing the large water bottle as template. Note that the last coe�cient is definedas the attenuation coe�cient of the table.

    36

  • (a) (b)

    (c)

    Figure 4.6: Binary images used for the cupping correction using a homogeneousplastic phantom. (a) is the phantom template, (b) is the weight image and (c)is the table template

    37

  • (a) (b) (c)

    (d) (e) (f)

    (g) (h) (i)

    Figure 4.7: Basis images f0 to f8 of the large water bottle.

    38

  • (a) (b) (c)

    (d) (e) (f)

    (g) (h) (i)

    Figure 4.8: Basis images f0 to f8 of the small water bottle.

    39

  • (a) (b) (c)

    (d) (e) (f)

    (g) (h) (i)

    Figure 4.9: Basis images f0 to f8 of the QRM phantom.

    40

  • (a) (b) (c)

    (d) (e) (f)

    (g) (h) (i)

    Figure 4.10: Basis images f0 to f8 of the plastic phantom.

    41

  • (a) (b)

    (c) (d)

    Figure 4.11: Correction of the large water bottle using the coe�cients calculatedfrom itself. (a) is the uncorrected image, (b) is the corrected image, (c) and (d)are plots of the attenuation for the line through the bottle from left to right atpixel 350 of the y-axis for the two images. The windowing in (a) and (b) is setto the mean-value ± two standard deviations of the attenuation values insidethe bottle.

    42

  • (a) (b)

    (c) (d)

    Figure 4.12: Correction of the small water bottle using the coe�cients calculatedfrom the large water bottle. (a) is the uncorrected image, (b) is the correctedimage, (c) and (d) are plots of the attenuation for the line through the bottlefrom left to right at pixel 350 of the y-axis for the two images. The windowing in(a) and (b) is set to the mean-value ± two standard deviations of the attenuationvalues inside the bottle

    43

  • (a) (b)

    (c) (d)

    Figure 4.13: Correction of the QRM phantom using the coe�cients calculatedfrom the large water bottle. (a) is the uncorrected image, (b) is the correctedimage, (c) and (d) are plots of the attenuation for the line through the bottlefrom left to right at pixel 350 of the y-axis for the two images. The windowing in(a) and (b) is set to the mean-value ± two standard deviations of the attenuationvalues inside the phantom

    44

  • (a) (b)

    (c) (d)

    Figure 4.14: Correction of the homogeneous plastic phantom using the coe�-cients calculated from the large water bottle. (a) is the uncorrected image, (b) isthe corrected image, (c) and (d) are plots of the attenuation for the line throughthe bottle from left to right at pixel 350 of the y-axis for the two images. Thewindowing in (a) and (b) is set to the mean-value ± two standard deviations ofthe attenuation values inside the phantom

    45

  • Before correction After correctionSmall insert 5.63 5.89Large insert 5.90 6.79

    Table 4.2: Contrast to noise ratios for the high-contrast inserts for the QRMphantom when using the large water bottle for correction.

    Before correction After correctionSmall insert 3.10 3.07Large insert 3.32 3.06

    Table 4.3: Contrast to noise ratios for the low-contrast inserts for the QRMphantom when using the large water bottle for correction.

    4.2.4 Correction using the small water bottle

    Table 4.4 presents the coe�cients calculated using eq 4.15 when using the largewater bottle as template. µ

    table

    = c9 was found to be 0.509 cm2/ g. Figures4.16, 4.15 and 4.17 display the result of applying this correction to the largewater bottle, the small water bottle itself and the QRM phantom respectively.

    Basis image 0 1 2 3 4 5 6 7 8 9Coe�cient value -0.054 0.830 -0.008 0.041 0.103 -0.107 -0.050 0.095 -0.030 0.509

    Table 4.4: Coe�cient values corresponding to each basis image for the correctionusing the large water bottle as template. Note that the last coe�cient is definedas the attenuation coe�cient of the table.

    46

  • (a) (b)

    (c) (d)

    Figure 4.15: Correction of the small water bottle using the coe�cients calculatedfrom itself. (a) is the uncorrected image, (b) is the corrected image, (c) and (d)are plots of the attenuation for the line through the bottle from left to right atpixel 350 of the y-axis for the two images. The windowing in (a) and (b) is setto the mean-value ± two standard deviations of the attenuation values insidethe bottle.

    47

  • (a) (b)

    (c) (d)

    Figure 4.16: Correction of the large water bottle using the coe�cients calculatedfrom the small water bottle. (a) is the uncorrected image, (b) is the correctedimage, (c) and (d) are plots of the attenuation for the line through the bottlefrom left to right at pixel 350 of the y-axis for the two images. The windowing in(a) and (b) is set to the mean-value ± two standard deviations of the attenuationvalues inside the bottle .

    48

  • (a) (b)

    (c) (d)

    Figure 4.17: Correction of the QRM phantom using the coe�cients calculatedfrom the small water bottle. (a) is the uncorrected image, (b) is the correctedimage, (c) and (d) are plots of the attenuation for the line through the bottlefrom left to right at pixel 350 of the y-axis for the two images. The windowing in(a) and (b) is set to the mean-value ± two standard deviations of the attenuationvalues inside the bottle.

    49

  • (a) (b)

    (c) (d)

    Figure 4.18: Correction of the homogeneous plastic phantom using the coef-ficients calculated from the small water bottle. (a) is the uncorrected image,(b) is the corrected image, (c) and (d) are plots of the attenuation for the linethrough the bottle from left to right at pixel 350 of the y-axis for the two im-ages. The windowing in (a) and (b) is set to the mean-value ± two standarddeviations of the attenuation values inside the bottle.

    50

  • Before correction After correctionSmall insert 5.63 5.89Large insert 5.90 6.75

    Table 4.5: Contrast to noise ratios for the high-contrast inserts for the QRMphantom when using the small water bottle for correction.

    Before correction After correctionSmall insert 3.10 3.08Large insert 3.32 3.07

    Table 4.6: Contrast to noise ratios for the low-contrast inserts for the QRMphantom when using the small water bottle for correction.

    4.2.5 Correction using the homogeneous plastic phantom

    Table 4.7 presents the coe�cients calculated using eq 4.15 when using the plasticphantom as template. µ

    table

    = c9 was found to be 0.542 cm2/ g. Figures 4.16,4.15 and 4.17 display the result of applying this correction to the large waterbottle, the small water bottle itself and the QRM phantom respectively.

    Basis image 0 1 2 3 4 5 6 7 8 9Coe�cient value -0.058 0.840 0.155 -0.111 0.091 -0.062 0.022 -0.001 -0.001 0.542

    Table 4.7: Coe�cient values corresponding to each basis image for the correctionusing the plastic phantom as template. Note that the last coe�cient is definedas the attenuation coe�cient of the table.

    51

  • (a) (b)

    (c) (d)

    Figure 4.19: Correction of the homogeneous plastic phantom using the coe�-cients calculated from itself. (a) is the uncorrected image, (b) is the correctedimage, (c) and (d) are plots of the attenuation for the line through the bottlefrom left to right at pixel 350 of the y-axis for the two images. The window-ing in (a) and (b) is set to the mean-value ± two standard deviations of theattenuation values inside the bottle.

    52

  • (a) (b)

    (c) (d)

    Figure 4.20: Correction of the large water bottle using the coe�cients calculatedfrom the homogeneous plastic phantom. (a) is the uncorrected image, (b) is thecorrected image, (c) and (d) are plots of the attenuation for the line throughthe bottle from left to right at pixel 350 of the y-axis for the two images. Thewindowing in (a) and (b) is set to the mean-value ± two standard deviations ofthe attenuation values inside the bottle .

    53

  • (a) (b)

    (c) (d)

    Figure 4.21: Correction of the small water bottle using the coe�cients calculatedfrom the homogeneous plastic phantom. (a) is the uncorrected image, (b) is thecorrected image, (c) and (d) are plots of the attenuation for the line throughthe bottle from left to right at pixel 350 of the y-axis for the two images. Thewindowing in (a) and (b) is set to the mean-value ± two standard deviations ofthe attenuation values inside the bottle.

    54

  • (a) (b)

    (c) (d)

    Figure 4.22: Correction of the QRM phantom using the coe�cients calculatedfrom the homogeneous plastic phantom. (a) is the uncorrected image, (b) is thecorrected image, (c) and (d) are plots of the attenuation for the line throughthe bottle from left to right at pixel 350 of the y-axis for the two images. Thewindowing in (a) and (b) is set to the mean-value ± two standard deviations ofthe attenuation values inside the bottle.

    55

  • Before correction After correctionSmall insert 5.63 5.89Large insert 5.90 6.75

    Table 4.8: Contrast to noise ratios for the high-contrast inserts for the QRMphantom when using the homogeneous plastic phantom for correction.

    Before correction After correctionSmall insert 3.10 3.08Large insert 3.32 3.07

    Table 4.9: Contrast to noise ratios for the low-contrast inserts for the QRMphantom when using the homogeneous plastic phantom for correction.

    56

  • Chapter 5

    Discussion

    The CTGantry software updates improved the performance of the experimentalsetup significantly, although not all issues were solved. The cupping correctionimplementation showed promising results, yielding reduced cupping in mostcases. However, some constraints in the applicability of the method were found.

    5.1 The CTGantry software update

    As found in chapter 3, the changes to the CTGantry code solved many of theproblems it had in its previous state. The updated version was considerablyeasier to use and had many additional features added. Moreover, the issueregarding the disconnection of the gantry as well as the socket errors were solve,allowing long acquisitions to be performed without interruptions.

    However, the problem with the partially irradiated images remained. Ascan be seen in figure 3.3, there is a gradient in the number of counts in thex-direction. A probable reason for this error is an error in the timing of turningon and o↵ the X-ray tube. The detector pixels are read from left to right bycollecting the collected charge in each pixel of a column. Thus, if the X-ray tubedis turned on during the collection, the pixels on the right side of the image willhave more collected charge than the left side at the point of collection, givingthe gradient seen in figure 3.3 (e). After the charge is collected, the remainingX-ray radiation will cause charge to be stored for the next frame. The nextframe will therefore look like figure 3.3 (f), with more charge collected on theleft side.

    Additional work will have to put into fixing the timing error, as well asexploring why the ”after” images are irradiated at all. A good start would beto simultaneously measure the output of the X-ray trigger cable and the X-raytube when trying to send X-ray triggers with a constant interval. One couldthen find out whether there is hardware problem in the cable or X-ray tube, orif it is the software malfunctioning. A final target for improvement is findingout whether its possible to reduce the waiting time between images to increase

    57

  • the speed of the scan, possibly by shortening the delay step in the statemachine.

    5.2 The cupping correction

    As can be seen in the images of section 4.2, the cupping e↵ect is completelyremoved from the small water bottle, the large water bottle and the plasticphantom when the correction is applied to themselves. This is expected sincethe coe�cients are calculated to make this specific correction to be as close tothe template as possible.

    One note on the self-corrected images is that there seems to be a gradient inattenuation in the left to right direction, i.e. the attenuation closer to the tableis slightly lower than farther away. This can be seen in the uncorrected imagesas well, and it would seem that the cupping correction is not able to correctthis error. This highlights the limitations of the empirical cupping correction.Although the cupping coe�cients are fit to provide a homogeneous image, thefinal image is still limited by the basis images.

    A possible explanation for this gradient is that there is beam hardeningcaused by the table, causing the gradient to appear in all the basis images.If the e↵ect looks similar in all basis images, then there could possibly be nocombination that can erase it from the final image. This could be tested byperforming the correction on images with the table removed. The phantomswould then have to be hold in place with some other method. Ideally, a correc-tion should be implemented also for the beam hardening caused by the table.Another option that perhaps could solve this problem is to use filtering, i.e. let-ting the X-ray beam pass through some material upon exiting the X-ray tube.Thus, a large portion of low energy X-rays would be absorbed, and the beamhardening e↵ect reduced.

    Applying the coe�cients calculated from one object onto another to performthe correction yielded mixed results. Comparing figure 4.12 with figure 4.15 andfigure 4.21 the resulting corrected images are almost identical. The same is truewhen comparing figure 4.13 with figure 4.17 and figure 4.22. However, there is ashift in the Hounsfield values when comparing images corrected with coe�cientscalculated from di↵erent objects. This is to be expected due to the nature of thebeam hardening e↵ect. An object that hardens the beam more will yield a highere↵ective energy and therefore a lower average attenuation. So a problem ariseswhen one tries to correct objects with di↵erent beam hardening characteristicsto the ”true” value, because the ”true” value varies. In this case, the attenuationvalue used was for a beam traveling through 1.02 cm ice. Correcting the valuesof both the small and large water bottle to that attenuation value yields di↵erentcoe�cients, not only because of the smoothing of the cupping, but also becauseof the adjustment of the overall attenuation to fit the e↵ective energy of a beampenetrating a 1.02 cm thick layer of ice.

    From figures 4.14, 4.16, and 4.18 it is evident that sometimes the correction isnot successful. A possible explanation for this phenomenon lies within the basisimages. For a highly attenuating object, the projection data raised to a high

    58

  • power will have much larger values than for an object attenuating less. Hence,the reconstructed basis images will as well, which leads to very small coe�cients.This works when a highly attenuating object is used to correct a less attenuatingobject, because the lower coe�cients is often enough to provide an accuratecorrection. However, using the large coe�cients for a highly attenuating objectwill cause unpredictable results. Therefore, the correction should only be appliedon objects that are less attenuating than the phantom used.

    Examining the contrast to noise ratio (CNR) on the inserts in the QRMphantom when performing the cupping correction, one can see that the di↵er-ence is rather small. For high contrast inserts, the CNR was somewhat increased,while it was slightly decreased for the low contrast inserts. A possible explana-tion for the di↵erence is simply the position of the inserts on the phantom. Thegradient in the attenuation in the corrected image of the QRM phantom meansthat there is an overestimation of the attenuation surrounding the high contrastinserts (to the right) and an underestimation of the attenuation surroundingthe low contrast inserts (to the left). Thus, the relative di↵erence between theattenuation in the insert and surrounding material is higher for the right insertsthan the left inserts.

    59

  • Chapter 6

    Conclusion

    The STH microCT imaging system software has been improved both in perfor-mance and functionality. It can now perform long acquisitions without interrup-tions, and many additional features such as dual energy scans and customizedprotocols has been implemented.

    Beam hardening correction software has been implemented and tested usingimages from the current microCT system, yielding promising results. The cup-ping artifact was significantly reduced, although it was shown that the correctionmethod could not be applied for objects more attenuating than the phantomused for calculating the correction coe�cients. Moreover, it was found that thecorrection only could remove beam hardening caused by the object being im-aged. Another beam hardening e↵ect presumably caused by the table, was stillpresent in the corrected images.

    60

  • Appendices

    61

  • Appendix A

    Code for sustaining asymbolic link for the gantry

    As explained in section 3.1, the gantry was connected to either ttyUSB0 orttysUSB1. To create a link, the vendor id, product id and serial number wasneeded. All usb devices connected were listed through the command lsusb,producing the output of figure A.1. The only connected device listed apart

    Figure A.1: Output for lsusb

    from the Logitech mouse is the first on the list, with product ID 0403.To confirm that this was indeed the gantry, the command ”udevadm info –

    name=/dev/ttyUSB0 –attribute-walk” was entered, producing the output shownin figure A.2

    Here, the product ID was indeed shown to be 0403, with product ID 6001and serial ID A6039XZL.

    To create the link, a file was created in the /etc/udev/rules.d/ folder, con-taining the following piece of code:SUBSYSTEM=”tty”, ATTRSidVendor=”0403”, ATTRSidProduct=”6001, AT-TRSserial=”A6039XZL” , SYMLINK+=”gantry”

    As confirmation that the new link was working, the output of the command”ls -l /dev” was examined. As can be seen in figure A.3, /dev/gantry is indeeda link to /dev/ttyUSB0.

    62

  • Figure A.2: Output for udevadm info –name=/dev/ttyUSB0 –attribute-walk

    Figure A.3: Output for ls -l /dev

    To reconnect using the new link, the code in figure A.4 was added to se-rial2net.cpp, which occasionally produces output such as the one depicted infigure A.5. However, instead of stopping the program would now continue withthe acquisition unhindered.

    63

  • Figure A.4: New code in Serial2Net.cpp. The original code consisted of the twolines: ”m serialDevice.write(data); ” and ”m serialDevice.f lush; ”

    Figure A.5: Output in testserial.txt.

    64

  • Appendix B

    Cupping correctionMATLAB software

    B.1 getImagesFromNii.m

    The getImagesFromNii function (figure B.1) loads all nifti files in the currentfolder, scales it with the voxel size used in Sebastian Andersson’s code, calculatesthe average of a set number of slices in the direction of the rotational axis andsaves all images in an array in the current folder.

    The imAvg function used on line 9 of the getImagesFromNii function calcu-lates the image averaged over several slices. See figure ??

    B.2 calcCoe↵.m

    The calcCoe↵.m (figure B.3 function takes as input the path to the folder con-taining the imagearray produced by the getImagesFromNii function. The func-tion also assumes that the template, weight and bed weight as defined in section4.1.1 are saved in a mat file called ”templates.mat”. The output coe�cients aresaved in the input folder.

    B.3 correctImage.m

    The correctImage function (see figure B.4 takes as input both the path to thefolder containing the correction coe�cients to be used and the path to thefolder containing the images to correct. The output is both the uncorrected andcorrected images.

    65

  • Figure B.1: The getImagesFromNii function code.

    Figure B.2: The imAvg function code.

    66

  • Figure B.3: The calcCoe↵ function code.

    67

  • Figure B.4: The correctImage function code.

    68

  • Bibliography

    [1] Kalender W. (2011). Computed Tomography. Third edition. Erlangen. Pub-licis Publishing.

    [2] Prince J, Links J (2006). Medical Imaging, Signals and Systems. UpperSaddle River, New Jersey. Pearson Prentice Hall.

    [3] http://radiopaedia.org/articles/x-rays

    [4] G. Van Gompel et al. ”Iterative correction of beam hardening artifacts inCT” Med. Phys. 38, 36 (2011)

    [5] A J Coleman, M Sinclair ”A beam-hardening correction using dual-energycomputed tomography” Physics in Medicine and Biology, Volume 30, Number11

    [6] Je↵rey A. Meganck et al. ”Beam Hardening Artifacts in Micro-ComputedTomography Scanning can be Reduced by X-ray Beam Filtration and theResulting Images can be used to Accurately Measure BMD” Bone. 2009 Dec;45(6): 1104–1116.

    [7] Kachelrieß M, Sourbelle K, Kalender W. Empirical cupping correction: Afirst-order raw data precorrection for cone-beam computed tomography. Med.Phys. 33, 1269 (2006).

    [8] Maaß C, Baer M and Kachelrieß M. Image-based dual energy CT usingoptimized precorrection functions: A practical new approach of material de-composition in image domain. Med. Phys. 36, 3818 (2009)

    [9] Qt 4.8 Documentation. http://doc.qt.io/qt-4.8/

    [10] Di Sopra L.Geometric Misalignment Calibration and Detector Lag E↵ectArtifact Correction in a Cone-Beam Flat Panel micro-CT System for SmallAnimal Imaging. Master of Science Thesis, KTH Royal Institute of Technol-ogy, 2015.

    [11] Andersson Sebastian. Implementation of a reconstruction software and im-age quality assessment tool for a micro-CT system. Master of Science Thesis,KTH Royal Institute of Technology, 2016.

    69

    http://doc.qt.io/qt-4.8/

  • [12] Cunningham I.A , Shaw R Signal-to-noise optimization of medical imagingsystems. Journal of the Optical Society of America A, vol 16, issue 3 (1999).

    70

  • www.kth.se

    IntroductionPurpose of study

    BackgroundCTPhotons in CTX-ray productionX-ray attenuationImage acquisition and reconstructionMicroCT

    The STH microCTSystem setupThe acquisition software

    Desired featuresAcquisition software updateDual energy microCTBeam hardening correction

    Programming detailsQtThe statemachine framework

    Updating the image acquisition softwareSolving the major disconnection issueSolving the socket issuesResults from the software changesImplementing dual energy scansProtocol creatorUpdating the GUI

    Implementing a beam hardening correctionMethodEmpirical Cupping CorrectionMeasuring the attenuation of waterCorrection for geometric deviation from the ideal caseAcquisitionsPerforming the cupping correction

    ResultsMeasuring the attenuation of waterBasis imagesCorrection using the large water bottleCorrection using the small water bottleCorrection using the homogeneous plastic phantom

    DiscussionThe CTGantry software updateThe cupping correction

    ConclusionAppendicesCode for sustaining a symbolic link for the gantryCupping correction MATLAB softwaregetImagesFromNii.mcalcCoeff.mcorrectImage.m


Recommended