introduction to image processing using the...

32
Introduction to Medical Image Processing using Matlab Nov. 28. 2013 HanbeanYoun [email protected]

Upload: ngonguyet

Post on 22-May-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Introduction to Medical Image Processing using Matlab

Nov. 28. 2013

HanbeanYoun

[email protected]

Page 2: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Matlab

• For: for - end is a repetition statement providing a loop for automatic iteration over a range of numbers or objects.

• Usage

• Example: calculate 𝑖=110 𝑖

for i=1:1:N

Operation(i);

end

Sum = 0;

for i=1:1:10

Sum = Sum+i;

end

Page 3: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• for-if combination

Sum = 0;

for i=1:1:10

if mod(i,2)==1

Sum = Sum+i;

end

end

Page 4: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Questions?

• Type F1!!!

• or

[email protected]

051)510-3921

010-4567-9371

기계관 3301호

Page 5: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• Image processing toolbox

• Useful functions: imshow, imread, imwrite, imfilter …

• Image I/O

• Raw images

• “jpg”, “png”, “tif” … : “imread” built-in function

• Dicom images (.dcm): “dicomread” built-in function

• Open “ImgIO.m”

[fid]=fopen(FileName,'r',Endian);

Image=fread(fid,ImageSize,DataType);

fclose(fid);

clear fid;

Page 6: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Histogram

• Open “Histogram.m”

Histogram = zeros(max(max(Img)),1);

for i=1:size(Img,1)

for j=1:size(Img,2)

Histogram(Img(i,j)) = Histogram(Img(i,j))+1;

end

end

Page 7: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• Image display in Matlab

figure,imshow(Img, []) figure,imshow(Img, [0 500]) figure,imshow(Img, [500 1000])

Page 8: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Pixel base operations

• Gray level transformations (gamma transformation)

where A is a normalizing constant

• Implementation

• gamma = 0.5 % 1.0 2.0

• g = f.^gamma

• Open “GammaTran.m”

inAfg

𝛾 = 0.5 𝛾 = 1.0 𝛾 = 2.0

Page 9: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Pixel base operations

• Built-in function for pixel based image transforms

g=imadjust(f,[low_in high_in], [low_out high_out], gamma);

Page 10: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Pixel base operations

• Threshoding

• Open “ImgThreshold.m”

g = h>Threshold; g = h<Threshold;

Page 11: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Pixel base operations

• Multi-image operations (dual energy imaging)

• Open “DESub.m”

𝐷𝐸 = log 𝐼𝐻𝐸 −𝑤 log 𝐼𝐿𝐸

𝑤 = 0.47 𝑤 = 0.79

Page 12: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Pixel base operations

• 2d transformations: imtransform

• B = imtransform(A,tform)

• B = imtransform(A,tform,interp)

• imrotate, imresize

I = imread('cameraman.tif');

tform = maketform('affine',[1 0 0; .5 1 0; 0 0 1]);

J = imtransform(I,tform);

imshow(I), figure, imshow(J)

Page 13: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Transform Type Description

'affine' Affine transformation in 2-D or N-D

'projective' Projective transformation in 2-D or N-D

'custom' User-defined transformation that can be N-D to M-D

'box'Independent affine transformation (scale and shift) in each dimensio

n

'composite' Composition of an arbitrary number of more basic transformations

Page 14: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Image filtering

• Convolution filters

• “imfilter”: N-D filtering of multidimensional images

• Usage: B = imfilter(A,h), where A and h denote input image and convolution filter

• Example: averaging filtering

• Open “ImgConv.m”

1/9 1/9 1/9

1/9 1/9 1/9

1/9 1/9 1/9

Filter = ones(3,3)/9;

B = imfilter(A,Filter);

Page 15: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• Example: Sharpen filter

-0.167 -0.667 -0.167

-0.667 4.333 -0.667

-0.167 -0.667 -0.167

Adjust size of blurring filter

Page 16: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Non-linear filter

• Median filtering (open “ImgMedf.m”)

G = medfilt2(DE,[Size Size])

Page 17: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• Comparison

• Median filtering is very suitable for “salt and pepper” noise

• Compare with average filter

Noisy image Average filtering Median filtering

Page 18: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• Unsharp masking

• To enhance edge by emphasizing the high-frequency part and assigning it a higher weight

• Open “ImgUnsharp.m”

Unsharp masking applied to lower part of image

Page 19: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• Implementation

Alpha = 0.5;

Filter = ones(3,3)/9;

Unsharp = Img-imfilter(Img,Filter);

ImgFin = Img+Alpha*Unsharp;

Adjust 𝛼 and size of blurring filter

Page 20: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Frequency domain operations

• 2d Fourier transform in Matlab

• fft2 returns the two-dimensional discrete Fourier transform (DFT) of X.

• The DFT is computed with a fast Fourier transform (FFT) algorithm.

• Usage: Y = fft2(X), Y = fft2(X,m,n)

Page 21: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• Low pass filters

-1

-0.5

0

0.5

1

-1

-0.5

0

0.5

10

0.2

0.4

0.6

0.8

1

Fx

Fy

Magnitude

-1

-0.5

0

0.5

1

-1

-0.5

0

0.5

10.2

0.4

0.6

0.8

1

Fx

Fy

Magnitude

Page 22: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• High pass filters

-1

-0.5

0

0.5

1

-1

-0.5

0

0.5

10

2

4

6

8

Fx

Fy

Magnitude

-1

-0.5

0

0.5

1

-1

-0.5

0

0.5

10

1

2

3

4

5

6

Fx

Fy

Magnitude

Page 23: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

M = 128;

N = 128;

u = (0:(M-1));

v = (0:(N-1));

idx = find(u > M/2);

u(idx) = u(idx)-M;

idy = find(v > N/2);

v(idy) = v(idy)-N;

[V, U] = meshgrid(v, u);

D = hypot(U,V);

D0 = 2000;

H = 1-exp(-(D.^2)/(2*D0^2));

figure,surf(fftshift(H));

colormap jet; shading interp

-1

-0.5

0

0.5

1

-1

-0.5

0

0.5

10.2

0.4

0.6

0.8

1

Fx

Fy

Magnitude

Page 24: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

실습

• Oepn “ImgFilt.m”

Page 25: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

실습

• Filter의모양을바꾸어가면서필터링을해보자

Page 26: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

고주파강조필터링

• 고역통과필터는 dc항을 0으로제거하므로, 영상의평균값을 0으로만든다. 따라서에지검출마스크가된다.

• 이를보상하기위해사용되는한가지방법은고역통과필터에오프셋(offset)을더하는것이다.

• 오프셋이필터를 1보다큰상수로곱한것과결합될때, 이접근방식은고주파강조필터링으로불린다.

• 고주파강조필터들은다음의전달함수를갖는다.

• Open “ImgFilt_H.m”

𝐻𝐻𝐹𝐸 𝑢, 𝑣 = 𝑎 + 𝑏𝐻𝐻𝐹(𝑢, 𝑣)

Page 27: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

실습

f = ReadRaw('HeadandNeck.raw',[1024 768],'uint16','l');

F=fftshift(fft2(f));

M = 1024;

N = 768;

u = (0:(M-1));

v = (0:(N-1));

idx = find(u > M/2);

u(idx) = u(idx)-M;

idy = find(v > N/2);

v(idy) = v(idy)-N;

[V, U] = meshgrid(v, u);

DSQ = U.^2 + V.^2;

D = hypot(U,V);

D0 = 100;

H = 0.5+2*(1-exp(-(D.^2)/(2*D0^2)));

H = ifftshift(H);

G = F.*H;

g = abs(ifft2(G));

WriteRaw('Result.raw',[1024 768],'double','l');

Page 28: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov
Page 29: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

Gray level operations

• Histogram equalization

• Histogram equalization is a method in image processing of contrast adjustment using the image's histogram.

Original image

Calculate histogram

Cumulative sum and normalize

Gray level re-mapping

Enhanced image

Page 30: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• Implementation

• Histogram calculation

• Cumulative sum

• Normalization

Histogram = zeros(max(max(Img)),1);

for i=1:size(Img,1)

for j=1:size(Img,2)

Histogram(Img(i,j)) = Histogram(Img(i,j))+1;

end

end

for i=1:numel(Histogram);

CumSum(i) = sum(Histogram(1:i));

end

ni = CumSum/size(Img,1)/size(Img,2)*1024;

Page 31: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov

• Re-mapping

Img2 = zeros(size(Img));

for i=1:size(Img,1)

for j=1:size(Img,2)

Img2(i,j) = round(ni(Img(i,j)))+1;

end

end

Page 32: Introduction to Image processing using the Matlabbml.pusan.ac.kr/resources/Lecture/MedEng/ImgProcMat… ·  · 2013-11-27Introduction to Medical Image Processing using Matlab Nov