52
Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006

Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Embed Size (px)

Citation preview

Page 1: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Biomedical Image Enhancement and Visualization

A N N A H O L M S T R Ö M

Master of Science Thesis Stockholm, Sweden 2006

Page 2: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Biomedical Image Enhancement and Visualization

A N N A H O L M S T R Ö M

Master’s Thesis in Biomedical Engineering (20 credits) at the School of Chemical Engineering Royal Institute of Technology year 2006 Supervisor at CSC was Erik Fransén Examiner was Anders Lansner TRITA-CSC-E 2006:157 ISRN-KTH/CSC/E--06/157--SE ISSN-1653-5715 Royal Institute of Technology School of Computer Science and Communication KTH CSC SE-100 44 Stockholm, Sweden URL: www.csc.kth.se

Page 3: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

To my family, and Pavel, you are the best.

Page 4: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Abstract

The diploma thesis presented deals with the study of general mathematical methodsof image-enhancement, visualization and their verification.

To describe the principle of processing real MR images artificial images are used. Thefiltering method which is applied to de-noice the images is based on fouriertransform,also other filtering methods and image-enhancement methods are described. Themethods which is used for segmentation and classification of images is achievedthrough application of neural networks. The result of processing the image-data isa segmentation of the image in different segments and classification of these.

In a larger perspective the goal is to find special classes for individual diseases. Thiscan be achieved by building a large data base and then compare the data and thusfind patterns that can indicate for example tumour or other malfunction which canbe diagnosed using MR images.

Page 5: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Biomedicinsk bildforbattring

och visualisering

Sammanfattning

I detta examensarbete studeras och bevisas metoder for forbattring och visualiseringav bilder. Allmanna bildbehandligsmetoder tillampas pa artificiella bilder.

For att beskriva principen av metoderna anvands artificiella bilder. Filteringmetodensom anvands for avbrusning av bilder bygger pa fouriertransform men aven andrafilteringsmetoder och bildforstarkningssmetoder beskrivs. Den metod som anvandsfor bildsegmentering och klassificering av bilderna bygger pa anvandning av neuralanatverk. Resultatet av bearbetningen och analysen av bilddata ar en uppdelning avbilden i olika segment och klassificering av dessa.

I ett vidare perspektiv ar malet att finna klasser som pekar pa enskilda sjukdomar,speciellt cancersvulster. Detta kan astadkommas genom att bygga upp en databasmed tusentals bilder och sedan forsoka finna aterkommande monster som tex skullekunna tyda pa en tumor, i detta arbete skulle metoder for att segmentera ochklassificera dessa bilder vara ovarderligt.

Page 6: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Declaration

This diploma thesis was elaborated at the Department of Computing and ControlEngineering of the Institute of Chemical Technology, Prague, in the period betweenSeptember, 2004 to December, 2004. Here I declare that the thesis presented hasbeen elaborated by the author exclusively, and only those information resources havebeen used which are provided in the list of the cited literature.

Anna Holmstrom

Acknowledgements

I would like to thank to the colleagues and co-students at the Department of Com-puting and Control Engineering for their support and understanding.

Keywords

Image Analysis, Image Decomposition and Reconstruction, Two-Dimensional ImageFiltering, Image Enhancement, Image De-Noising, Biomedical Images

Page 7: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Contents

1 Introduction 1

1.1 Biomedical Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Project Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Principles of Image Acquisition using Magnetic Resonance 3

2.1 Physical Principle of Magnetic Resonance Imaging . . . . . . . . . . . 42.2 Data Acquisition and Preprocessing . . . . . . . . . . . . . . . . . . . 52.3 Mathematical methods in image processing . . . . . . . . . . . . . . . 6

2.3.1 Time-Frequency and Time-Scale Signal and Image Analysis . . 62.3.2 Methods of Image Enhancement . . . . . . . . . . . . . . . . . 9

3 Results 13

3.1 Linear and Non-Linear Methods of Image Filtering . . . . . . . . . . 133.1.1 Neural Networks and Image Classification . . . . . . . . . . . 18

3.2 Statistical MR Image Processing and Enhancement . . . . . . . . . . 263.2.1 MR Image Enhancement . . . . . . . . . . . . . . . . . . . . . 263.2.2 Three-dimensional Image Modeling . . . . . . . . . . . . . . . 273.2.3 Image coding . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

3.3 Summary of results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303.3.1 MR Image Feature Extraction . . . . . . . . . . . . . . . . . . 303.3.2 MR Image Feature Classification . . . . . . . . . . . . . . . . 30

4 Conclusions 31

Bibliography 33

Appendices 33

.1 Selected Algorithms in MATLAB . . . . . . . . . . . . . . . . . . . . 35

.2 Image Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

Page 8: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

List of Figures

1.1 A MR image of the brain. . . . . . . . . . . . . . . . . . . . . . . . . 1

2.1 DFT of a sample signal . . . . . . . . . . . . . . . . . . . . . . . . . 72.2 2 dim Fourier transform of a sample signal. . . . . . . . . . . . . . . 92.3 Prewitt edge detector . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.4 Wavelet decomposition followed by enhancement. . . . . . . . . . . . 11

3.1 DFT of a sample signal. . . . . . . . . . . . . . . . . . . . . . . . . . 153.2 Filtering of signal in two dimensions . . . . . . . . . . . . . . . . . . 183.3 An image with and one without noise . . . . . . . . . . . . . . . . . . 203.4 Watershed ridges of the two images. . . . . . . . . . . . . . . . . . . . 203.5 The image and its watershed segmentation. . . . . . . . . . . . . . . . 223.6 Plot of the different classes and which segment belongs to which class. 253.7 The watershed image showing the classes and labels of the regions. . 263.8 Cross sections from the brain. . . . . . . . . . . . . . . . . . . . . . . 273.9 Volume section cut from the brain. . . . . . . . . . . . . . . . . . . . 283.10 Volume section ear . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

Page 9: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

1

Introduction

1.1 Biomedical Images

Biomedical images are of big interest because they can be a useful tool when diag-nosing and analyzing functions and diseases of the brain, also other body parts canof course be examined for example the kidneys. So how is it that the body can beanalysed by magnetic resonance? Well, the biological tissue contains a lot of hydro-gen atoms which are possible to detect. Nuclear magnetic resonance is a techniquein which a electromagnetic field is applied to the sample,in this case the brain.Thenuclei of the hydrogen atoms in the biological tissue align themselves to the mag-netic field, after this a radiomagnetic pulse will raise their energy level further, whenthe pulse ends they will relax and during the relaxation this energy will be transmit-ted from the atoms.The transmitted signal will be detected by the equipment andprocessed further into the pixels that make up the biomedical image. This thesis ismore focused on MR images of the brain, but in fact the methods described herecan be applied to any kind of image.

20 40 60 80 100 120

20

40

60

80

100

120

FIGURE 1.1. A MR image of the brain.

1

Page 10: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

1.2 Project Goals

Basic goals of the project is in

• Image de-noising using selected filtering methods

• Enhancement of image components

• Study of image segmentation

• Feature extraction of image components and classification

• Three-dimensional visualization

2

Page 11: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

2

Principles of Image Acquisition usingMagnetic Resonance

The magnetic resonance tomograph is build of different parts, to generate the mag-netic field a system of magnets is needed, a radiotransmittor that produces excitationpulses and detection devises and a unit that processes the image. There is a lot of dif-ferent ways how to acquire a magnetic resonance image. But what is always neededto obtain the image is the density of the protons and the two relaxation times. Togenerate images it’s necessary to bring about a force field in the measuring placeso that the Larmor frequency emitted by the sample is the same as the absorbedradio pulse frequency. The magnetic field is made inhomogeneous with the aid ofgradient spools in the x, y and z direction.This is done because the frequency mustbe different in places of the patient which are not to be measured.

MR images [1] can be obtained in different ways. Here I will explain the principlesof a few different methods. A simple way how to do it is to pick one tiny element atthe time and then build a resulting image from all the little elements. The elementsare picked by aligning the gradient fields so that only one little volume element hasthe correct field strength. The MRI system goes through the head, liver kidney orwhatever the area of interest point by point (sequential point method), building up a2-D or 3-D map of tissue types. The resulting image reflects the chemical structureof the tissue, including differences in the water content and in movements of thewater molecules.

The method above is very time consuming and is therefore not that much used inpractice.The most usual is the ”spin warp” method which is based on a phase codingof the precession movements. This takes place with a series of pulses of different sizein the gradient field in for example the y-direction. In the x-direction a frequencycoding is executed by choice of appropriate force on the gradient field in this directionand the position of the cut and the gradient field is decided in the same way in thez-direction. The image is obtained through a process which resembles an opticalhologram.

3

Page 12: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

2.1 Physical Principle of Magnetic Resonance Imaging

Hydrogen atoms occur in large numbers in biological tissue and are therefore usedin clinical imaging. Hydrogen atoms are most numerous in water and of course thebiological tissue consists mainly of water. So how is the presence of hydrogen atomsdetected? The body is exposed to a highly energetic magnetic field (induced by amagnet) that causes the electrons to arrange themselves in relation to the field.They spin around their own axis, the speed is given by the ”Larmor frequency” [4].”Precession” is another word for when something spinning around its own axis.

But why do they start to rotate when exposed to a magnetic field? Well nucleiwith odd number of neutrons have nuclear magnetism which means that in thepresence of a magnetic field they possess a magnetic dipole due to spin. Spin isa quantum mechanical property [5] and when talking about MRI it’s the nucleusand its magnetic dipole which is referred to. In one mm3 of water there is 6.7 ∗ 1019

protons, which is a large quantity, but the net magnetic moment is still small becausethe spins cancel each other out because of the spin up( +1/2) and spin down (-1/2)states. All of the spins doesn’t have the same relative phase, but they do have thesame relative frequency, the ”Larmor frequency”, due to the magnetic field and thisis given by the Larmor equation.

ω = γ·B (2.1)

The Larmor frequency ω,which is in fact the speed of the precession of the atoms,isgiven by the magnetic field, B, and also by the gyromagnetic constant γ,whichis typical for every nucleus. The difference in this constant makes it possible todistinguish between different nuclei.After the nuclei have been aligned along thefield they are exposed to a radio magnetic pulse. The energy from this pulse isabsorbed by the nuclei. The pulse is brought o perpendicular to the magnetic fieldcaused by the magnet. The spin vectors will now start to move in phase, the angleof precession will increase slightly. When the pulse ceases the absorbed energy willbe transmitted as radiation.

The nuclei will again become out of phase and their orientation resume the original.These two changes are characterised by two relaxation times, T1 and T2. T1 isa measurement of the time it takes for the nuclei to transmit their energy to thesurrounding and resume the equilibrium position. T2 is the time it takes for thenuclei to start moving out of phase again. This depends on the effect that themagnetic fields of neighbouring nuclei has. T2 is always shorter or the same as T1.In fluids both T1 and T2 are in seconds but in solid tissues , for example bone, T1 isin hours and T2 in microseconds. This is the reason why bone can’t be visualized. T2

is the most interesting time because it gives information about the characteristics of

4

Page 13: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

the sample. T2 is decided by the spin echo method [1].T2* is the de-phasing causedby local inhomogeneities in the applied magnetic field and this de-phasing is fasterfor the spins than the T2 relaxation time. A 90o pulse turns the spin vectors to thexy-plane. By flipping the direction of the spins 180o round the x-axis the fastestrotating spins will catch up with the slow ones then you will receive a spin echowith maximal amplitude when the spins are in the same phase. By turning the spinsa number of times with new 180o pulses it’s possible to measure how fast the echopeaks decline.The envelope on the curve allows calculation of T2.

2.2 Data Acquisition and Preprocessing

A grouping of radio frequency pulses, delays and data acquisition periods is referredto as a pulse sequence. The spin echo technique is a trick for removing the de-phasingcaused by local magnetic field inhomogeneities and other disturbances . In the spinecho pulse sequence the events are timed with respect to the initial radio frequencypulse. It could be possible to sample immediately after the rf pulse ends but it’shard to do it practically, instead a realigned echo is sampled.

If the spins spread out and their direction suddenly change they will come togetheragain after a known time interval. In MRI the time for reversal is carried out by a180 phase reversing radio frequency pulse [1]. The repositioning will occur at thesame time constant , T2* as when they change direction. T2* is the de-phasingcaused by local inhomogeneities in the applied magnetic field and this de-phasingis faster for the spins than the T2 relaxation time. This echo approach will onlycancel de-phasing caused by magnetic inhomogeneities not the variations due to thesample itself, which are those caused by the T2 relaxation. T2 is the decay fromwhen the atoms relax to their equilibrium position. And this is exactly what is ofinterest. Because the T2 pulse will give the information about the sample, the brainor the kidney.

The location of the pulse is given by the resonant frequency and the different relationtimes are used to achieve image contrast. After being detected by the receiver coilthe signal is processed in the transducer from one energy form to another. Thesignal may have to pass through a filter which removes noise from for example thesurrounding electromagnetic fields.

5

Page 14: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

2.3 Mathematical methods in image processing

2.3.1 Time-Frequency and Time-Scale Signal and Image Analysis

Definition of Discrete Fourier Transform

Discrete Fourier transform [6]is a way to calculate for example frequency contents ofa sampled signal, it can be a signal from any source with a periodical or suspectedperiodical behavior...

X(ωk) ≡N−1∑

n=0

x(tn)e−jωktn , k = 0, 1, 2.......N − 1 (2.2)

Description of symbols;

N−1∑

n=0

f(n) = f(0) + f(1) + .... + f(N − 1) (2.3)

• x(tn) The amplitude of the input samples at time tn

• tn = nT The nth sampling instant, n is an integer bigger than zero.

• T sampling interval

• X(ωk) Spectrum of X with complex value at frequency ωk.

• ωk = kΩ kth frequency sample

• Ω = 2πNT

radian frequency sampling interval

• fs = 1

Tsampling rate

• N number of time samples

Here is an example how to make the discrete Fourier transform in Matlab. Handlingimages, it’s more common to plot the Fourier transform with zero in the middle ofthe diagram and go from -0.5 to +0.5.

% 1D DFT

N=64; n=[0:N-1]’; f1=0.1; %N= number of samples

x=sin(2*pi*f1*n); X=fft(x); %definition of a sinusoid

subplot(2,1,1);

plot(n/N,abs(X));

subplot(2,1,2);

plot(n/N-0.5,fftshift(abs(X)));

6

Page 15: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Results are in Fig. 2.1.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

5

10

15

20

25FFT of sample signal

ma

gn

itud

e

−0.5 −0.4 −0.3 −0.2 −0.1 0 0.1 0.2 0.3 0.4 0.50

5

10

15

20

25FFT of sample signal, after fftshift.

frequency

ma

gn

itud

e

Signal with added noise

FFT of sample signal, with box

FIGURE 2.1. DFT of a sample signal

Definition of Inverse Discrete Fourier Transform

In Matlab the command IFFT (Inverse Fourier Transform) will restore the origi-nal spectra after being transformed with FFT (Fast Fourier Transform).The IDFT,inverse discrete Fourier transform, is given by.

x(tn) =1

N

N−1∑

k=0

X(ωk)ejωktn n = 0, 1, 2.......N − 1 (2.4)

Mathematics of DFT

To make it easier to understand the mathematics of Fourier transform it’s commonto set T= 1 in the definition above.

X(k) =N−1∑

n=0

x(n)e−j2πnk

N , k = 0, 1, 2.......N − 1 (2.5)

and in the inverse case:

7

Page 16: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

x(n) =1

N

N−1∑

k=0

X(k)ej2πnk

N , n = 0, 1, 2.......N − 1 (2.6)

Two dimensional Fourier Transform

The difference between the base functions of the one and two dimensional Fouriertransform is that in the one dimensional case it’s a sinusoid and in the two dimen-sional case, they are sinusoidally varying wavefronts.

〈x(n,m)〉N−1,M−1

n=0,m=0 → X(h, l) =M−1∑

m=0

(N−1∑

n=0

x(n,m)e−jkn 2πN )e−jlm 2π

M , (2.7)

For h=0,1,2.......N -1 and l=0,1,2.......M -1

Here is an example on how to make two dimensional Fourier transform in Mat-lab.Note in the rightmost figure how easy it is to see the frequencies of the noisewhen plotting between -0.5 to +0.5.. The idea is to multiply the signals with eachother to achieve the three dimensional structure. To add the noise to the clean signalthey are simply added.

% 2D DFT

N=128; n=[0:N-1]’;%N = number of samples

f1=0.01; f2=0.01; %frequencies of sinusoids

x1=sin(2*pi*f1*n); x2=sin(2*pi*f2*n)’;

%definition of sinusoids

X=x1*x2;

%definition of sinusoidal wavefronts

fn1=0.3; fn2=0.3;

%noise frequencies

xn1=sin(2*pi*fn1*n); xn2=sin(2*pi*fn2*n)’;

%definition of noise sinusoids

XN=xn1*xn2;

%definition of sinusoidal noise

X=X+XN;

%addition of noise to sinusoid

8

Page 17: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

X=(X-min(X(:)))/(max(X(:))-min(X(:)));

figure(2);

subplot(1,2,1);

mesh(X);

XX=fft2(X-mean(X(:)));

subplot(1,2,2);

mesh(n/N-0.5,n/N-0.5,fftshift(abs(XX)));

FIGURE 2.2. 2 dim Fourier transform of a sample signal.

2.3.2 Methods of Image Enhancement

Image enhancement is about finding features [4] in the image such as points linesand edges. The most common method of finding characteristics in an image is edgedetection. In edge detection the gradient of the pixel values calculated.See definitionof a gradient below.

∇f = [Gx Gy]T = [

∂f

∂x

∂f

∂y]T

(2.8)

9

Page 18: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

The equation above can be simplified. The gradient can be approximated digitallyby a method called sliding neighborhood.This means that the differences of the pixelvalues in a small neighborhood is calculated for each pixel in the image. An exampleof this is the Prewitt mask which is illustrated in the figure below. The Prewitt edgedetector uses this mask to approximate the partial derivatives Gx and Gy. If thereis no difference in pixel values the result will be zero.There are other edge detectorsthat give results with less noise but this one is easy to use and is a illustrativeexample of this method. After the edge detection the pixels rarely resemble an edgethis is due to disturbances such as noise and other effects that are caused by theenviroment.There are methods that link the segments together,gathers them on aline, one of these is the Hough Transform.This method will not be described closerhere however.

FIGURE 2.3. Prewitt edge detector

MR Image De-Noising

Good algorithms for de-noising is of the essence when it comes to handling MRimages. This was earlier mentioned and explained in chapter two presenting thede-noising of an artificial image as illustration of the principle for the windowingmethod. The windowing method is a filter that uses one or two dimensional Fouriertransform to detect noise frequencies. Then a box or a cube function is achieved bymultiplying the wanted cutoff frequency with a window function to create a filter andlast uses the inverse Fourier transform to acquire the de-noised image. But there isa lot of other ways of de-noising an image with a filter and two of the most commonones are FIR filters and Wavelet transform decomposition.Other filters that can beused are adaptive filters that have a learning structure, a neural network.

10

Page 19: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Wavelet noise reduction and FIR filters

The wavelet transform can be described in three steps:

• In the first step the image is decomposed by a three function which dividesthe image into four subimages.

• Each subimage is analyzed for certain properties, an individual threshold limitis chosen for them and the coefficients are modified.

• The signal is reconstructed from the modified wavelet transform coefficients.

The result from wavelet noise reduction [2] depends on the proper choice of waveletfunctions and selection of threshold limits.Wavelet transform apply wide windowsfor low frequencies and short windows for high frequencies. In Fig. 3.7 you can sethe result of Wavelet noise reduction.The FIR filter is a linear class of filters thatcan be used for both one and two dimensional cases. It is often used when denoisingMR images. The two dimensional filter is a natural extension of the one dimensionalfilter.It is easy to use practically and to represent by matrices and coefficients.

FIGURE 2.4. Wavelet decomposition followed by enhancement.

11

Page 20: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

12

Page 21: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

3

Results

3.1 Linear and Non-Linear Methods of Image Filtering

This chapter contains application of basic methods (FFT, WT, FIR, Median Fil-tering) to MR image [3] de-noising, comparison of results and suggestion of an ownalgorithm.

Filtering in one dimension

To create a boxfunction is one way how to remove the unwanted frequencies froma signal or an image. The box function is a vector or matrix of the same size asthe signal or image vector/matrix but it consists of ones in the region with wantedfrequencies and zeros in the region with unwanted frequencies. The signal is elementby element multiplied with the box function and the unwanted frequency interval willbe zero. In the case of two dimensional filtering the box function is a cubefunction.

Here is an example from Matlab how to create a filter in one dimension using thebox function. Note that Matlab starts counting from one instead of zero, which hasto be taken in to account. First the sinusoidal waves are defined then transformed bythe Fourier transform and finally plotted.The window is created by a matrix of zerosand ones which is defined after finding the cutoff frequecy and the multiplying withN(number of samples). This matrix is then multiplied element by element with thefourier transformed matrix X. The element multiplied with zeroes are the elementscontaining the noise frequencies and they will this way be removed. The filteredsignal is then retransformed by using the command fftshift and the result is a cleanplot without any noise.

13

Page 22: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

% 1D Filtering

clear

N=64; n=[0:N-1]’; f1=0.05; f2=0.25

%N= number od samples

x1=sin(2*pi*f1*n);

x2=0.5*sin(2*pi*f2*n); x=x1+x2;

X=fft(x);

figure(1);

subplot(4,1,1);

plot(n,x); hold on; plot(n,x1,’r’); hold off

subplot(4,1,2);

plot(n/N,abs(X)/max(abs(X)));

fc=0.15; W=round(fc*N);

% Definition of cutoff frequency interval

w=[ones(1,W),zeros(1,N-2*W+1),ones(1,W-1)]’;

%Definition of box vector

%removes the unwanted frequency

%values by multiplying with zero.

hold on, plot(n/N,w,’r’); hold off

subplot(4,1,3);

plot(n/N-0.5,fftshift(abs(X))/max(abs(X)));

subplot(4,1,4);

Y=X.*w;

y=ifft(Y);

plot(n,real(y))

Filtering in two dimensions

As mentioned earlier it is also possible to create a similar function in two dimensions,this is called a cube function.The cube function is a matrix with zeros in the regionwith the unwanted frequencies and ones in the region with wanted frequencies. Whencreating the cube function it is as before important to take in to account that Matlabstarts counting from zero.

In the Matlab code below noise is added to a sinusoidal wave function, a syntheticsignal. Then a two dimensional Fourier transform is made on the signal with noise.From the FFT spectrum it is possible to determine the frequency of the noise. Thebox function is created:

H=zeros(N,N);

H(N/2-W+2:N/2+W,N/2-W+2:N/2+W)=1;

14

Page 23: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

0 10 20 30 40 50 60 70−2

0

2

time

magnitude

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.5

1

magnitude

−0.5 −0.4 −0.3 −0.2 −0.1 0 0.1 0.2 0.3 0.4 0.50

0.5

1

frequency

0 10 20 30 40 50 60 70−2

0

2

Signal with added noise

FFT of sample signal, with box

Signal after FFTshift

Signal without noise

FIGURE 3.1. DFT of a sample signal.

N is the number of samples and W is the cutoff frequency multiplied with numberof samples. This creates a matrix with ones in the middle surrounded by zeros. Thisis then multiplied element by element with the noise function. A box is thus created.What is left is the signal without noise and on this the inverse Fourier transform isdone. The result should resemble the signal without noise.In the figure below youcan see the result of the program just described.

In the Matlab code below the synthetic signal with noise is defined. First the sinu-soids are multiplied with each other to form the wave function and then added withthe noise wavefront which is obtained in the same way.

% 2D Filtering

clear clear figure

N=128; n=[0:N-1]’;

%N is the number of samples

%n is a vector with N values starting from zero

f1=0.01; f2=0.01;

x1=sin(2*pi*f1*n); x2=sin(2*pi*f2*n)’;

%Definition of sinusoids

15

Page 24: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

X1=x1*x2;

%Definition of sinusoidal wave functions

fn1=0.3; fn2=0.3;

%noise frequencies

xn1=sin(2*pi*fn1*n); xn2=sin(2*pi*fn2*n)’;

%Definition of noise sinusoids

XN=xn1*xn2;

%Definition of noise sinusoidal wave functions

X=X1+XN;%X is wavefunction with noise, has no imaginary part.

In the code below the fourier transformed matrix is normalized. By this operationthe peak will end up in the middle of the spectrum, for easier identification of thenoise frequency fc.

XX=fft2(X);

%Fourier transform of function with noise,XX has imaginary part

%because it’s a Fourier transform of a wavefunction.

Fs=fftshift((XX)/max(max(abs(XX))));

%Normalization of shifted Fourier transform,

%maxmax is maximum element of matrix.

%Fs is still a matrix with imaginary part preserved.

Now that the cutoff frequency fc is found the cube function can be defined. Theway the cube removes the noise is explained above. the operation ”ifftshift” returnsthe spectrum into its original shape, this is done in order to make it possible to use”ifft” and thus undo the fourier transform.

H=zeros(N,N);

fc=0.2697; W=round(fc*N);

% Definition of cutoff frequency interval

%If fc increases the cube will be smaller.

%H(N/2-W+3:N/2+W-1,N/2-W+3:N/2+W-1)=1;

H(N/2-W+2:N/2+W,N/2-W+2:N/2+W)=1;

%H is the cube matrix that will cut off unwanted

%frequencies

Z=H.*Fs;

%Element by element multiplication

%of Fs by H (the cube function)

16

Page 25: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

qq=ifftshift(Z);%Swaps the first with

%the third and the second with the fourth

%quadrant in the spectrum, is done to

%get it back into original shape.

Zi=ifft2(qq);%Inverse Fourier transform.

%After the inverse Fourier transform,Zi may still have

%imaginary part which has to be reversed to real.

Zq=max(max(abs(XX)))*real(Zi);

%That is why only the real part

%of Zi can be taken into account

%(real). In the definition of Fs

%the matrix XX was divided by its

%maximum value, that’s why Zi now

%has to be multiplied with the

%same value for it to resemble X1,

%the wave function without noise.

(...)

To find the optimal cutoff frequency this program was made. The first part of theprogram is identical to the one above and therefor omitted here. It runs frequenciesfrom 0.2 to 0.3 with an accuracy of 0.0001 and returns the frequency which cor-respond to the minimal value of the least square error between the original signalwithout noise and the filtered signal.

% 2D Filtering, calculation of optimal Fc

clear clear figure

(...)

E=[;];

ac=0.0001; %accuracy

for fc=[0.2:ac:0.3]

W=round(fc*N);

%cutoff frequency

H=zeros(N,N);

%Definition of cube vector

H(N/2-W+1:N/2+W-1,N/2-W+1:N/2+W-1)=1;

Z=H.*Fs;

qq=ifftshift(Z);

Zi=ifft2(qq);

17

Page 26: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Zq=max(max(abs(XX)))*real(Zi);

E=[E,mse(Zq-X1)];

end

[mmin,i]=min(E);%mmin is the minimum value in

%the vector E and i is the index of this value.

fcr=0.2+ac*i %fcr gives the corresponding fc value

%multiplied with the accuracy.

FIGURE 3.2. Filtering of signal in two dimensions

3.1.1 Neural Networks and Image Classification

When working with MRI images it’s very useful to be able to divide it into differentsegments that can be analyzed to find some distinguishing mathematical features.It is not easy to divide the image into segments but with the help of the watershedfunction in Matlab is a very powerful tool.

Something about the watershed function

It can be worth to explain something about how the [6] watershed function works.Mathematically, a gray scale image can be thought of as a topological surface, like

18

Page 27: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

a mountain terrain, where the light parts are lighter and the dark are the groves orholes. It is called ”watershed” as an analogy to the geological formation. A watershedis the ridge that divides different area s drained by a river system and a catchmentbasin is the drained reservoir, like an empty lake. The watershed function findsthe catchment basins and the ridges in the greyscale image. But for it to work theimage usually has to be slightly changed to another image where the ridges can beidentified.This means that on an image with noise the watershed function would notwork. Below is a small Matlab and two figures program that illustrates the problem.

First the images are defined, they are displayed with imshow.

%IMAGE DEFINITION OF X AND X1 %%%%%%%%%%%%%%%

f1=0.01; f2=0.01;

x1=sin(2*pi*f1*n); x2=sin(2*pi*f2*n)’;

%Definition of sinusoids

X1=x1*x2;

%Definition of sinusoidal wave functions

fn1=0.3; fn2=0.3;

%noise frequencies

xn1=sin(2*pi*fn1*n); xn2=sin(2*pi*fn2*n)’;

%Definition of noise sinusoids

XN=xn1*xn2;

%Definition of noise sinusoidal wave functions

X=X1+XN;

%X is a wave function with noise, has no imaginary part.

Now it’s time to use the watershed function on these two images. See code below.Comparing the watersheds for the images with and without noise it’s clear to seethat noise makes the segmentation completely useless. Therefor it’s as mentionedimportant to alter the image, one way to do this is to smooth the image so that onlythe important features are classified. X1 is the data from the image in matrix formthis is then analyzed with the watershed function in matlab.

LL = watershed(X1,18);

w=LL==0;

figure(2) hold on

subplot(1,2,1)

imshow(w,’n’), title(’Ridge lines for image without noise’);

LL1 = watershed(X,18);

w1=LL1==0;

subplot(1,2,2)

imshow(w1,’n’), title(’Ridge lines for image with noise’);

19

Page 28: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

hold off

Image without noise Image with noise

FIGURE 3.3. An image with and one without noise

Ridge lines for image without noise Ridge lines for image with noise

FIGURE 3.4. Watershed ridges of the two images.

Method of image classification

When analyzing images such as MRI images it is also of great value to be ableto classify the different segments of the image.That is; make a classification fromdifferent characteristics of the segments. The segments are classified by the helpof competitive learning process (neural network).The neural network is built up ofdifferent layers of neurons, the first layer is the input where the data to be analyzedis absorbed and the last layer is the output layer where the processed data again

20

Page 29: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

goes in to the input and so fourth, the aim of the learning network in this case is todivide the data into three classes, the network also decides the parameters of theseclasses.

Here is a Matlab [6] example how to classify segments: The image is first dividedinto segments by the watershed function that was previously described. The differentsegments are then labelled by bwlabel().The segments are labelled so they can belocated and analyzed mathematically as described above.

LL = watershed(im1,6);

%Divides the image into segments,

(...)

L=bwlabel(LL,4);

%All the segments are labelled.

Then the mean and standard deviation is calculated for each of the segments andput in a vector P consisting of two rows one row with mean value and the secondwith standard deviation.

stats=regionprops(L,’all’);

for i=1:length(stats)

L1=L==i;

%L1 counts the segments.

LL1=im1(L1);

%The corresponding area

%in the image is chosen

P(1,i)=mean(LL1);

%The mean value of areas

%in the image is calculated

P(2,i)=std(LL1);

%The standard deviation of

%areas in the image is calculated

end

The next step is to classify the segments in to a chosen number of classes by the aidof a network. The network is created by ”newc” which creates a competitive layer,the output vector w, that are closest to the inputs will be plotted in the graph. Theclass indicators (A,B,C) are plotted in different colors. See figure. The network isfirst initialized and then trained, the number of training epochs can be changed fordesired accuracy.

%initiation of neural network

net=newc(minmax(P),4,.1);

net=init(net);

21

Page 30: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

w=net.IW1;

%training of neural network

net.trainParam.epochs=350;

net.b1,1=zeros(3,1)+eps;

%Biases set to zero, done to eliminate errors.

net.biases1.learnParam.Ir=0; %%

net=train(net,P1);

w=net.IW1;

Below is a figure of and image and its watershed segmentation.The image has threedistinct regions that should belong to three different classes.This is done to clearlyvisualize the principle of the classification.

Image without noise Ridge lines for image without noise

FIGURE 3.5. The image and its watershed segmentation.

Now the classification will be visualized in a plot showing which segments belong towhich class. The code below is giving each of the classes its own color.The regionswill have the same color as the class they belong to.

The colours are defined by COLOUR and in the first for-sling the font size is set.Thevector a is resultant from the competitive network, indices of the true element inthis vector corresponds to the class of the point. The b vector receives the index ofthe true element, thus the class, for each point.The c vector collects the b values.

h=text(w(:,1),w(:,2),[’A’;’B’;’C’]);

COLOUR=[’g’;’b’;’r’];

for i=1:3;

set(h(i),’FontSize’,14,’color’,COLOUR(i));

end;

22

Page 31: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

c=[];

COLOUR=[’g’;’b’;’r’];

for i=1:length(P1) %The points

a=sim(net,P1(:,i));

%Takes the right class for the points in P

b=find(a==1);

%Finds class, corresponding to position of

%the true value in the "a" vector, for each point.

c=[c,[b]];

%Stores info about point

end

for i=1:length(P);

set(H(i),’FontSize’,12,’color’,COLOUR(c(i)));

%Changes the colors of the points from P

%indicated by the vector c

end

The result of this program can be seen in Fig. 3.4. Further more a program wasmade to show which classes the segments belongs to in the watershed image. Theprogram below simply chooses the right class for each segment visualized by thecolour red, green or blue.The program takes the label value for each pixel storedin L,which is the image after watershed function that actually just consists of thelabels from 1− 9 but still in the image format. Vector c has the class 1− 3 and thusdefine the color f each segment.

LLc=[];%Initialize new matrix

COLOUR=[’g’;’b’;’r’];

for i=1:size(L,1)

%i goes from one to the end the first dim in LL

for j=1:size(L,2)

%j goes from one to the end of the second dim in LL

ll=L(i,j);

%ll picks an element from L (the element is a integer

%between 1-9)

if ll~=0

%If ll is not equal to zero (doesn’t work if ll=0)..

LLc(i,j)=c(ll)*80;

%ll gives position in c and c has the classes 1 2 3

%This line can only be executed if the ll is different from

%zero.c(11) times 80 because the difference of the colors will

23

Page 32: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

%be bigger.

end

end

end

Further more, the label of each segment should be plotted on the colour imageshowing the different classes of the segments. This is simply done by using thefunction ginput which enables you to select points from the figure using the mousefor cursor positioning. The data is stored in a vector v after clicking on the segmentand then the number is printed on the segment

hold on

(...)

imshow(LLc,colormap(hsv(256)));% hsv

title(’Classification of segments’);

disp(’Click one time on each of the segments to see which label they

have’);

%I have to find out which segment has which label

[x,y]=ginput(length(P));

% Indices are taken from the image.

v=[x,y];

%Indices are stored.

vr=round(v);

%Indices are rounded off to nearest integer.

LLxy=[];

for i=1:length(P)

llxy=L(vr(i,2),vr(i,1));

%v indicates the corresponding label values in L.

LLxy=[LLxy,[llxy]];%

The label values are stored.

end

F=[];

for i=1:length(P)

F=[F;[’ ’,num2str(LLxy(i))]];

%In F the label values are transformed to strings.

end;

24

Page 33: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

h1=text(round(x(:)),round(y(:)),F);

%The label values are written on the image.

set(h1,’FontSize’,14,’color’,’k’);

hold off

break

FIGURE 3.6. Plot of the different classes and which segment belongs to which class.

The result of this program can be seen in Fig. 3.5

25

Page 34: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

FIGURE 3.7. The watershed image showing the classes and labels of the regions.

3.2 Statistical MR Image Processing and Enhancement

3.2.1 MR Image Enhancement

Image enhancement was earlier examined in chapter two where the basic principleswhere explained.As was mentioned edge detection is the most common enhancementapproach for image enhancement. And to do edge detection it’s possible to use thegradient method.In Matlab it looks like this.

I=nlfilter(ZD,[3 3],’det_gr1’); I1=mat2gray(I);

The nlfilter is a very useful function or MR images and it applies the gradientfunction detgr to each 3 by 3 area of the matrix of interest, in this case I.Thestructure of detgr is described in the Matlab program below.

function y=det_gr(B)

y=-B(1,1)+B(1,2)+B(1,3)-B(2,1)-2*B(2,2)+B(2,3)-B(3,1)+B(3,2)+B(3,3);

%The function performs a sliding neighborhood operation on B.

The result of this figure can be seen in the last image of Fig. 3.7.

26

Page 35: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

3.2.2 Three-dimensional Image Modeling

In Matlab there is several ways to display three dimensional images. It’s also possibleto display MR images in this way. Below is a little program that shows the possibilityof showing the MR images as slices of the brain in a three dimensional coordinatesystem. This is done with the command contour plot.

load Aim

colormap jet

ch=contourslice(Aim,[],[],[1,2,3],4); view(3); axis tight

%The first second and third image is chosen from the z axis.

set(ch,’LineWidth’,2)

See the result of this figure in the image below.

FIGURE 3.8. Cross sections from the brain.

Sometimes it can be interesting to see a three dimensional volume section from thebrain. This can be achieved by the program below.

[x,y,z,Aim] = subvolume(Aim,[50,200,150,350,nan,nan]);

%Here all of the images are chosen, the first coordinates

%are from the x axis the other from the y axis and so on.

p1 =patch(isosurface(x,y,z,Aim, 5),...

%Isosurface connects points that have a specified value

%in common, in this case five.

’FaceColor’,’red’,’EdgeColor’,’none’);

isonormals(x,y,z,Aim,p1); p2 = patch(isocaps(x,y,z,Aim, 5)

The result of this program can be seen in the figure below.In this image you cansee a part of the head and in the one following is the ear, a smaller section of theprevious one.

27

Page 36: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

FIGURE 3.9. Volume section cut from the brain.

FIGURE 3.10. Volume section ear .

3.2.3 Image coding

This chapter describes show the images are stored in Matlab and how it is possibleto manipulate them.

28

Page 37: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

How images are stored in Matlab

In Matlab the most common way to store information is in an array. An array is anordered set of real or complex values. In Matlab images are stored as two-dimensionalarrays, that is, matrices. A pixel in an image corresponds to an element in the matrix.One value in the matrix also says which color the pixel should have. Truecolor images,consisting of red, green and blue, needs a three-dimensional matrix, that is, threematrices where each matrix represents a color. In Matlab you can easily display asingle pixel or just a few pixels by matrix subscripting for example I(3,10). Thisgives the value at row 3 and column 10.

Intensity images

An intensity image [6]is really just a normal grey scale image.The values in the datamatrix representing the intensity image are in the case of single or double rangingbetween 0 and 1. Zero represents black and one white and the values in betweenrepresents different shades of gray. This is true in the when using the default greyscale map but it’s possible to use any colormap with Matlab.

Indexed images

An indexed image consists of an array of pixel values, which can be called X, anda color map matrix. The pixel value in X are pointing at the three correspondingcolor map values. The color map matrix is an m by 3 matrix, the values in the colormap range between [0,1]. The three rows in the color map represents red, green, andblue. A single pixel value in X indicates one value each from red, green and blue rowand together they represent the color of the pixel.

The image matrix can be of different classes, single, double, uint8, uint16 or logical,this effects the relationship with the color map. In the case of class single or doublethe first value is one and it points to the first row in the color matrix. In the caseclass logical, uint8 or uint16 the first value is zero and points on the first row of thecolor map the second value ,one, points at the second row in the color map and soon. This is important to keep in mind...

Binary black and white images

A binary image is made up of just black or white pixels. This means that the pixelshave discrete values 1 or 0 where one is white and zero is black, there are thus noshades of gray like in the intensity image. The binary image may also be called abilevel image.

29

Page 38: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

3.3 Summary of results

3.3.1 MR Image Feature Extraction

In the previous chapters different ways how to manipulate images was investigated.To extract features from MR images it is first necessary to eliminate noise from theimage, in some cases it’s also necessary to know something about the environmentwhere the image was produced. There might be some electromagnetic fields from theother equipment in the room that is disturbing the detection of the signal. Methodsdescribed in the thesis makes it possible to denoise the images, this can be donewith the method described in chapter one, the window method but there is a lot ofother ways how to do it, for example with the wavelet denoising or FIR filters, aclass of filters in Matlab.After the denoising has been done it’s time to enhance theimage. There is as usual a number of ways how to do this but the most common anduseful approach is the edge detection which is a way to find edges in the image thatcan make it easier to se interesting structures in the image . Edge detection can becarried out by the gradient method which is described other ways how to enhancethe image is through point and line detection. The programs given in chapter twomay not be sufficient to manage a real MR image as they are presented but theygive a good idea for the principles and may well be used with some further research.

3.3.2 MR Image Feature Classification

To classify and image it’s first necessary to divide it into segments and this can notbe done until the procedure described above has been done, that is, denoising andenhancement.If the image is not denoised it will be segmented too much and uselessto classify them.But when segmenting the image it may also be of use to smooththe image a bit, so that just the very most interesting areas will be classified. Thesegmentation can be done with for example the watershed function in Matlab, afunction that sees the image as a topological surface and that finds the ”mountainridges” in the image.After the segmentation the segments are labelled, given a num-ber and now they can be classified.The method of classification presented here isusing the competitive network to find which segments belong to which class, in thiscase three but there can of course be more of them. This is very interesting becauseimagine to find a special class that is significant for the early stages of a brain tumoror alzheimer’s disease.The program in the thesis uses an artificial image to show theprinciple of classification but can with some adjustments be used in practice.

30

Page 39: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

4

Conclusions

The thesis is devoted to the study of mathematical methods for analyzing im-ages.The aim was to find methods for analyzing, filtering and classifying images.Themethod described regarding de-noising was window filtering also mentioned areWavelet decomposition de-noising and FIR. It’s important to de-noise the imagebecause otherwise it can’t be segmented and if it’s not segmented it can not be clas-sified.The filters use different algorithms to exclude the noise frequencies. A commonway to find out which frequencies that should be omitted is Fourier transform in oneand two dimensions. Enhancement of the image is here briefly illustrated by edgedetection. Edge detection is more useful that for example line or dot detection.Edgedetection is done through the gradient method.

The watershed function in Matlab has been used in one of the programs here, it’s avery good function for dividing the image into segments. The only problem is thatthe image has to be completely free from noise before it can be used. Or at least ithas to be smoothed out somehow, which is quite complicated and requires a lot ofresearch if the result is to be of use. Therefor it has only been applied to an artificialimage in the thesis. There is one program written which besides using the watershedfunction and labels all the segments also classifies the segments into three classes.Areal MR image would probably have to be classified more and the program wouldhave to be modified to work for MR images. Maybe it could be possible to storedata from a lot of images from the brain and to try and find some special class forinstance defining tumours.

In Matlab there is a lot of ways how to display the MR data in three dimensions.With the command contour for example they can be displayed as slices. It’s possibleto just look at a small volume section from the brain.The images in the thesis aremade up from only three slices, which is really not sufficient to get a useful resultbut there are interpolating methods, for example spline that can fill the rest of thespace between the images.This is very good because if it would be viable to justfrom a few MR images say something about the sample the MRI could be cheaperand faster as a diagnostic method.

It’s clear that these are not the only methods and that this is an area where moreresearch can be done and is done. The methods and algorithms described here maynot be sufficient for the study of real MR images as they are presented in this thesisbut they give the basic principles and with some additions and further research theymay be very useful for this purpose.

31

Page 40: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

32

Page 41: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

Bibliography

[1] Bertil Jacobson. Medicin och Teknik. Studentlitteratur, Lund, Varnamo, Swe-den, 2004.

[2] A. Prochazka, J. Jech, and J. Smith. Wavelet transform use in signal processing.In 31st International Conference in Acoustics, pages 209–213. Czech TechnicalUniversity, 1994.

[3] R.E. Woods R.C. Gonzales and S.L. Eddins. Digital Image Processing UsingMATLAB. Prentice Hall, Englewood Cliffs, N.J., 2004.

[4] John L. Semmlow. Biosignal and Biomedical Image Processing. Marcel Dekker,Inc, New York, Basel, 2004.

[5] Robert J. Silbey. Physical chemistry. John Wiley & Sons, Inc., New york, 1995.

[6] Inc. The MathWorks. Matlab Image Processing Toolbox. The MathWorks, Inc.,Natick, Massachusetts 01760, May 1997.

33

Page 42: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

34

Page 43: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

APPENDICES

.1 Selected Algorithms in MATLAB

This section contains headers of the most important programs belonging to thethesis. As it is mentioned in the Conclusions (see Chapter 4), the thesis is availableon the www page http://dsp.vscht.cz.

% Simulated image

N=128; n=[0:N-1]’;

f1=0.03; f2=0.03;

x1=sin(2*pi*f1*n); x2=sin(2*pi*f2*n)’;

XS=x1*x2;

fn1=0.2; fn2=0.2; Am=0.5;

xn1=Am*sin(2*pi*fn1*n); xn2=Am*sin(2*pi*fn2*n)’;

XN=xn1*xn2;

X=XS+XN;

X=(X-min(X(:)))/(max(X(:))-min(X(:)));

figure(1);

subplot(1,2,1); mesh(X)

subplot(1,2,2); imshow(X)

%little program to explain the principle of denoicing

clear

N=128; n=[0:N-1]; f0=0.02; fn=0.1;

x=sin(2*pi*f0*n);

figure(1) subplot(2,1,1) plot(x); title(’Sinusoid without noice’)

xn=sin(2*pi*f0*n)+sin(2*pi*fn*n);

subplot(2,1,2) plot(xn); title(’Sinusoid with noice’)

35

Page 44: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

%Normally fn (frequency of noice) would be unknown, but we can use FFT

%(fast fourier transform) to find out the frequency

%and when we know it, it is easy to remove by subtraction of xn (noice sinusoid).

X=fft(xn);

Xs=abs(X);

figure(2) subplot(2,1,1) plot(n/N,Xs);grid on;

title(’Spectrum with noice, note the frequency of the noice’)

xlabel(’frequency’)

subplot(2,1,2) X1=ifft(X); Xc=abs(X1) plot(n/N,X1); title(’The

original signal with noice’)

%And then you can just remove the noice with fn through a simple subtraction.

%When the noice is of a more complex nature it’s possible to use NN to remove it.

.2 Image Analysis

Name:Label1

%This program classifies the different segments of an image.

%The segments are first labelled and then mean and standard deviation

%is calculated for all of them. These values are put in a vector with

%two rows and n columns. Then it’s possible to use a program for

%classification which is described below.

% IMAGE SEGMENTATION %%%%%%%%%%%%%%%%%%%

delete(get(0,’children’)); clear

N=128; n=[0:N-1]’;

[im2,col]=imread(’nybild4.bmp’);

im1=im2(:,:,1);

%% IMAGE VISUALIZATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

hf=figure(’Name’,’Object’,’Units’,’Normal’,...

’Position’,[0.0 1 0.25 0.25]);

imshow(im1,’n’);, title(’Image without noise’)

hold on

%% IMAGE WATERSHED TRANSFORM %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

LL = watershed(im1,6);%Divides the image into segments,

36

Page 45: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

% w=LL==0;

hf2=figure(’Name’,’Ridge’,’Units’,’Normal’,...

’Position’,[0.25 0.6 0.25 0.25]);

imshow(LL,’n’), title(’Ridge lines for image without noise’);

hold off

L=bwlabel(LL,4);%All the segments are labeled.

stats=regionprops(L,’all’);

L1=[];

for i=1:length(stats)

L1=L==i;

LL1=im1(L1);

P(1,i)=mean(LL1);

P(2,i)=std(LL1);

end

P1=P/244;

% Pattern Classification with a Competitive Layer

%% NEWC - Creates a competitive layer

%% TRAIN - Trains a neural network

%% SIM - Simulates a neural network

%% Neurons in a competitive layer learn to

%% represent different regions

%% of the input space where input vectors occur

G=[’ 1’];

for i=2:length(P)

G=[G;[’ ’,num2str(i)]];

end

for i=10:length(P1+0.1)

G=[G;num2str(i)];

end

%% Plot the weight vectors to see their initial

%% attempt at classification

net=newc(minmax(P1),3,.1);

net=init(net);

w=net.IW1;

figure(3)

H=text(P1(1,:),P1(2,:),G);

axis([min(P1(1,:))-0.1 max(P1(1,:))+0.1 min(P1(2,:))-0.1_

37

Page 46: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

_max(P1(2,:)+0.1)]);

title(’Input Vectors’); xlabel(’p(1)’); ylabel(’p(2)’);

set(H,’FontSize’,14,’color’,’r’)

text(w(:,1),w(:,2),[’A’;’B’;’C’]); hold off;

disp(’Press any key to continue’);pause;

%% Plot the updated layer weights on the same graph

net.trainParam.epochs=350;

net.b1,1=zeros(3,1)+eps;

%Biases set to zero, done to eliminate errors.

net.biases1.learnParam.Ir=0; %%

net=train(net,P1);

w=net.IW1;

hold on;

h=text(w(:,1),w(:,2),[’A’;’B’;’C’]);

COLOUR=[’g’;’b’;’r’];

for i=1:3;

set(h(i),’FontSize’,14,’color’,COLOUR(i));

end;

c=[];COLOUR=[’g’;’b’;’r’];

for i=1:length(P1) %The points

for j=1:3%The classes

a=sim(net,P1(:,i));

%Takes the right class for the points in P

b=find(a==j);

%Finds which points belongs to which class

c=[c,[b]];

%Stores info about point

r=i+1;

%counter

o=j+1;

end

end

for i=1:length(P);

set(H(i),’FontSize’,12,’color’,COLOUR(c(i)));

%Changes the colours of the points from P

%indicated by the vector c

end

hold off

%%%%%%%%%%%%%CHANGES

LLc=[];%Initialize new matrix

38

Page 47: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

COLOUR=[’g’;’b’;’r’];

for i=1:size(L,1)

%i goes from one to the end the first dim in LL

for j=1:size(L,2)

%j goes from one to the end of the second dim in LL

ll=L(i,j);

%ll picks an element from LL (the element is a integer between 1-9)

if ll~=0 %If ll is not equal to zero (doesn’t work if ll=0)..

LLc(i,j)=c(ll)*80;

%ll gives position in c and c has the classes 1 2 3

%This line can only be executed if the ll is different from

%zero.c(11) times 80 because the difference of the colors will

%be bigger.

end

end

end

hold on

hf3=figure(’Name’,’Ridge’,’Units’,’Normal’,...

’Position’,[0.25 0.6 0.25 0.25]);

imshow(LLc,colormap(hsv(256)));% hsv

title(’Classification of segments’);

disp(’Click one time on each of the segments to see which label

they have’);

%I have to find out which segment has which label

[x,y]=ginput(length(P));

% Indices are taken from the image.

v=[x,y];%Indices are stored.

vr=round(v);%Indices are rounded off to nearest integer.

LLxy=[];

for i=1:length(P)

llxy=L(vr(i,2),vr(i,1));

%v indicates the corresponding label values in L.

LLxy=[LLxy,[llxy]];

% The label values are stored.

end

F=[];

for i=1:length(P)

F=[F;[’ ’,num2str(LLxy(i))]];

%In F the label values are transformed to strings.

end;

h1=text(round(x(:)),round(y(:)),F);

%The label values are written on the image.

39

Page 48: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

set(h1,’FontSize’,14,’color’,’k’);

hold off

break

Name:Water1

%This program uses the watershed function to find

%edges in an image.

% IMAGE SEGMENTATION %%%%%%%%%%%%%%%%%%%

delete(get(0,’children’)); clear

N=128; n=[0:N-1]’;

%IMAGE DEFINITION OF X AND X1 %%%%%%%%%%%%%%%

f1=0.01; f2=0.01;

x1=sin(2*pi*f1*n); x2=sin(2*pi*f2*n)’;

%Definition of sinusoids

X1=x1*x2;

%Definition of sinusoidal wave functions

fn1=0.3; fn2=0.3;%noise frequencies

xn1=sin(2*pi*fn1*n); xn2=sin(2*pi*fn2*n)’;

%Definition of noise sinusoids

XN=xn1*xn2;

%Definition of noise sinusoidal wave functions

X=X1+XN;

%X is wave function with noise, has no imaginary part.

%% IMAGE VISUALIZATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

hf=figure(’Name’,’Object’,’Units’,’Normal’,...

’Position’,[0.0 0.6 0.25 0.25]);

imshow(X1,’n’), title(’Image without noise’)

hf1=figure(’Name’,’Object’,’Units’,’Normal’,...

’Position’,[0.0 0.6 0.25 0.25]);

imshow(X,’n’), title(’Image with noise’)

Name:Filt2Dslut

% 2D Filtering

clear clear figure

N=128; n=[0:N-1]’;

40

Page 49: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

%n is a vector with N values starting from zero

f1=0.01; f2=0.01;

x1=sin(2*pi*f1*n); x2=sin(2*pi*f2*n)’;

%Definition of sinusoids

X1=x1*x2;

%Definition of sinusoidal wave functions

fn1=0.3; fn2=0.3;%noise frequencies

xn1=sin(2*pi*fn1*n); xn2=sin(2*pi*fn2*n)’;

%Definition of noise sinusoids

XN=xn1*xn2;

%Definition of noise sinusoidal wave functions

X=X1+XN;

%X is wave function with noise, has no imaginary part.

figure(1);

subplot(1,2,1);

mesh(n/N-0.5,n/N-0.5,X1)

%plots wavefunction without noise.

%x and y coordinate system is

%created by n/N-0.5 instead of zero to one, -0.5 to +0.5.

subplot(1,2,2);

mesh(n/N-0.5,n/N-0.5,X)

XX=fft2(X);

%Fourier transform of function with noise,

XX has imaginary part because it’s a Fourier transform

%of a wave function.

Fs=fftshift((XX)/max(max(abs(XX))));

%Normalisation of shifted Fourier transform,

%maxmax is maximum element of matrix.

%Fs is still a matrix with imaginary part preserved.

figure(2);

subplot(2,2,1);

mesh(n/N-0.5, n/N-0.5,abs(Fs));

41

Page 50: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

axis([-0.5 0.5 -0.5 0.5 0 1]);

colormap(jet(64));

xlabel(’frequency’)

ylabel(’frequency’)

zlabel(’magnitude’)

subplot(2,2,2);

mesh(n/N-0.5, n/N-0.5,abs(Fs));

%Setup of mesh values

hold on

H=zeros(N,N);

fc=0.2697; W=round(fc*N);

% Definiton of cutoff frequency interval

%If fc increases the cube will be smaller.

%H(N/2-W+3:N/2+W-1,N/2-W+3:N/2+W-1)=1;

H(N/2-W+2:N/2+W,N/2-W+2:N/2+W)=1;

%H is the cube matrix that will cut off unwanted

%frequences

mesh(n/N-0.5, n/N-0.5, H); %Setting of axis

axis([-0.5 0.5 -0.5 0.5 0 1]);

colormap(jet(64));

hold off

xlabel(’frequency’)

ylabel(’frequency’)

zlabel(’magnitude’)

Z=H.*Fs;

%Element by element multiplication of Fs by H (the cube function)

subplot(2,2,3)

mesh(n/N-0.5, n/N-0.5,abs(Z));

axis([-0.5 0.5 -0.5 0.5 0 1]);

%Definition of axis

colormap(jet(64));

xlabel(’frequency’)

ylabel(’frequency’)

zlabel(’magnitude’)

subplot(2,2,4)

42

Page 51: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

hold on

axis([-0.5 0.5 -0.5 0.5 -1 1]);

%Control axis scaling and apperance

colormap(jet(64));

qq=ifftshift(Z);

%Swaps the first with the third and the second with the fourth

%quadrant in the spectrum,

%is done to get it back into origional shape.

Zi=ifft2(qq);

%Inverse fourier transform.

%After the inverse fouriertransform, Zi still has

%imaginary part which has to be reversed to real.

Zq=max(max(abs(XX)))*real(Zi); %That is why only the real part

%of Zi can be taken into account (real).

%Because in the definition of Fs

%the matrix XX was divided by its maximum value

%Zi now has to multiplied with the

%same value for it to resemble X1, the wavefunction without noise.

mesh(n/N-0.5,n/N-0.5,Zq); hold off

xlabel(’time’)

ylabel(’time’)

zlabel(’sample size’)

figure(3) mesh(n/N-0.5,n/N-0.5,Zq)

43

Page 52: Biomedical Image Enhancement and Visualization - … · Biomedical Image Enhancement and Visualization ANNA HOLMSTRÖM Master of Science Thesis Stockholm, Sweden 2006. Biomedical

TRITA-CSC-E 2006:157 ISRN-KTH/CSC/E--06/157--SE

ISSN-1653-5715

www.kth.se