Top Banner
DIGITAL IMAGE PROCESSING (01317172) Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL [email protected] [email protected] [email protected]
47

Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL [email protected] [email protected] [email protected].

Jan 04, 2016

Download

Documents

Franklin Hines
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

DIGITAL IMAGEPROCESSING

(01317172)Dr. Thurdsak LEAUHATONG

Dept. of electronics, Faculty of Engineering, KMITL

[email protected]@hotmail.com

[email protected]

Page 2: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

ScheduleDate Time Subject

Nov. 10 15:10 – 16:40 Introduction and Digital Image Fundamental #1

Nov. 17 15:10 – 16:40 Digital Image Fundamental #2

Nov. 24 15:10 – 16:40 Image Transform

Dec. 1 15:10 – 16:40 Image Enhancement #1

Dec. 8 15:10 – 16:40 Image Enhancement #2 & Assignment #1

Page 3: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Schedule (Continue)Date Time Subject

Dec. 15 15:10 – 16:40 Image Compression #1

Jan. 12 15:10 – 16:40 Image Compression #2

Jan. 19 15:10 – 16:40 Image Compression #3 & Assignment #2

Jan. 26 15:10 – 16:40 Image Segmentation #1

Feb. 2 15:10 – 16:40 Image Segmentation #2

Page 4: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Text Book

Digital Image Processing using MATLAB by Rafael C. Gonzalez, Richard E. Woods, and Steven L. Eddins

Page 5: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Text Book

Digital Image Processing

by Rafael C. Gonzalez, Richard E. Woods

Page 6: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

CxImage www.codeproject.com

Page 7: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.
Page 8: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Structure of Human EyeRetina :Light Sensitive Tissue

Cone Cell :Red cell, green cell, and blue cell. Detect Color. Locate at center of retina called fovea.

Rod Cell :One type. Detect Illumination.

Page 9: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Structure of Human Eye

Page 10: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Camera Structure

Charge-Coupled Device (CCD)

Page 11: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Psychophysical

Page 12: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Psychophysical

Page 13: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Gestalt Law Similarity

Human often perceive a group of similar objects as a single object or pattern

Page 14: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Gestalt Law

AnomallyWhen similarity occurs, an object can be

emphasised if it is dissimilar to the others. This is called anomally.

Page 15: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Getstalt Law

ContinuationContinuation occurs when the eye is compelled

to move through one object and continue to another object.

Page 16: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Getstalt Law

ClosureClosure occurs when an object is incomplete or a

space is not completely enclosed. If enough of the shape is indicated, people percieve the whole by filling in the missing infomation.

Page 17: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Getstalt Law

ProximityProximity occurs when elements are placed close

together. They tend to be perceived as a group.

Page 18: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Getstalt Law Figure and Ground

The eye differentiates an object from its surrounding area. A form, silhouette, or shape is naturally perceived as figure (object), while the surrounding area is perceived as ground (background).

Balancing figure and ground can make the perceived image more clear. Using unusual figure/ground relationships can add interest and subtlety to an image.

Page 19: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Shape Detection

Page 20: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Gestalt Application

S. Kiranyaz, M. Ferreira, and M. Gabbouj, “A Generic Shape/ Texture Descriptor Over Multiscale Edge Field: 2-D Walking Ant Histogram,” IEEE Trans. Image Processing, vol. 17, no. 3, pp. 377-391, March, 2008.

Page 21: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Gray Image

,f x y

(x,y) = An image’s position or pixelf(x,y) = The intensity of the image at (x,y).

Page 22: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Color Image ,f x y

(x,y) = An image’s position or pixelf(x,y) = (r,g,b)

The red, green, and blue components of the image at (x,y).

Page 23: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Gray Image Represented by Color Image

,f x y

(x,y) = An image’s position or pixelf(x,y) = (i,i,i)

The intensity of white color of the image at (x,y).

Page 24: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Image AcquisitionSpatial

Sampling

Intensity Quantization

,

,

f x y

x y

Continue IntensityContinue Spatial

Page 25: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Image AcquisitionSpatial

Sampling

Intensity Quantization

f(0,0) f(7,0)f(6,0)f(5,0)f(4,0)f(3,0)f(2,0)f(1,0)

f(0,1) f(7,1)f(6,1)f(5,1)f(4,1)f(3,1)f(2,1)f(1,1)

f(0,2) f(7,2)f(6,2)f(5,2)f(4,2)f(3,2)f(2,2)f(1,2)

f(0,3) f(7,3)f(6,3)f(5,3)f(4,3)f(3,3)f(2,3)f(1,3)

f(0,4) f(7,4)f(6,4)f(5,4)f(4,4)f(3,4)f(2,4)f(1,4)

f(0,5) f(7,5)f(6,5)f(5,5)f(4,5)f(3,5)f(2,5)f(1,5)

,

,

f x y

x y

,

0,1, , 1

0,1, , 1

f i j

i M

j N

Continue IntensityContinue Spatial Continue Intensity

Discrete Spatial

Page 26: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Image AcquisitionSpatial

Sampling

Intensity Quantization

a(0,0) a(7,0)a(6,0)a(5,0)a(4,0)a(3,0)a(2,0)a(1,0)

a(0,1) a(7,1)a(6,1)a(5,1)a(4,1)a(3,1)a(2,1)a(1,1)

a(0,2) a(7,2)a(6,2)a(5,2)a(4,2)a(3,2)a(2,2)a(1,2)

a(0,3) a(7,3)a(6,3)a(5,3)a(4,3)a(3,3)a(2,3)a(1,3)

a(0,4) a(7,4)a(6,4)a(5,4)a(4,4)a(3,4)a(2,4)a(1,4)

a(0,5) a(7,5)a(6,5)a(5,5)a(4,5)a(3,5)a(2,5)a(1,5)

,

0,1, , 1

0,1, , 1

f i j

i M

j N

, ,

0,1, , 1

0,1, , 1

a i j q f i j

i M

j N

Continue IntensityDiscrete Spatial Discrete Intensity

Discrete Spatial

Page 27: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Image Acquisitionq(f(I,j))

f(I,j)

max min

,, round

, 2k

f i jq f i j

Q

f fQ L

L

k=the number of bitsk=1; L=2 k=5; L=32k=2; L=4 k=6; L=64k=3; L=8 k=7; L=128k=4; L=16 k=8; L=256

Page 28: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Sampling with Different Resolutions

Lena 256x256 Lena 128x128

Lena 64x64

Page 29: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Quantize with Different Levels

L=2 L=16

L=64

L=8

L=128 L=256

Page 30: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Size of Uncompressed Image Size of Image = M x N x k bits

= M x N x k/8 Bytes

64x64x8

=32768 bits

=4kB

256x256x8

=524288 bits

=64kB

Page 31: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Size of Uncompressed Image

128x128x1

=16384 bits

=2kB

128x128x8

=131072 bits

=16kB

Higher Fidelity = Bigger Image Size

Page 32: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Image Representationa(0,0) a(1,0) a(2,0) a(3,0) a(4,0) a(5,0) a(6,0) a(7,0) a(8,0) a(9,0)

a(0,1) a(1,1) a(2,1) a(3,1) a(4,1) a(5,1) a(6,1) a(7,1) a(8,1) a(9,1)

a(0,2) a(1,2) a(2,2) a(3,2) a(4,2) a(5,2) a(6,2) a(7,2) a(8,2) a(9,2)

a(0,3) a(1,3) a(2,3) a(3,3) a(4,3) a(5,3) a(6,3) a(7,3) a(8,3) a(9,3)

a(0,4) a(1,4) a(2,4) a(3,4) a(4,4) a(5,4) a(6,4) a(7,4) a(8,4) a(9,4)

a(0,5) a(1,5) a(2,5) a(3,5) a(4,5) a(5,5) a(6,5) a(7,5) a(8,5) a(9,5)

a(0,6) a(1,6) a(2,6) a(3,6) a(4,6) a(5,6) a(6,6) a(7,6) a(8,6) a(9,6)

a(0,7) a(1,7) a(2,7) a(3,7) a(4,7) a(5,7) a(6,7) a(7,7) a(8,7) a(9,7)

a(0,8) a(1,8) a(2,8) a(3,8) a(4,8) a(5,8) a(6,8) a(7,8) a(8,8) a(9,8)

An image with size MxN is an array of a(x,y) with xϵ{0,M-1} and yϵ{0,N-1}

Page 33: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Programming VC++, Visual Studio 2008 CxImage

Page 34: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Build CxImgLib

1. Unzip CxImage600_full.zip into a folder, for example, at C:\CxImage

2. Open C:\CxImage\CxImgLib.dsw

3. Select Menu Build -> Batch Build

4. Click Select All

5. Rebuild

4

5

Page 35: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Run Demo Program

1. Go to Solution Explorer (at the left/right panel of VS2008)

2. Right click at demo and select

“set as start up project”

3. Click green arrow at toolbar

to run Demo program

3

2

Page 36: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Demo Program

Page 37: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Build a New Program

1. Select Menu File -> New -> Project

2. Select MFC -> MFC Application

Page 38: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Build a New Program (2)

1. Click Browse and select the CxImage folder, for example, “c:\CxImage”

2. Enter Project Name

12

Page 39: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Set Project Properties

1. Right Click at Project Name

2. Select Properties

3. Select Configuration Properties

4. Select General

5. Set Character Set to

“Use Multi-Byte

Character Set”

1

5

Page 40: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Set Project Properties

6. Select C/C++ -> General

7. Set Additional Include Directories to

..\..\CxImage

7

Page 41: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Set Project Properties

8. Select C/C++ -> Preprocessor

9. Set Preprocessor Directories to

WIN32;_DEBUG;_WINDOWS;VATI_EXTENSIONS;_CRT_SECURE_NO_DEPRECATE

9

Page 42: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Set Project Properties

10. Select Linker -> Input

11. Set Additional Dependencies to

../../png/Debug/png.lib ../../jpeg/Debug/jpeg.lib ../../zlib/Debug/zlib.lib ../../tiff/Debug/tiff.lib ../../jbig/Debug/jbig.lib ../../jasper/Debug/jasper.lib ../../mng/Debug/mng.lib ../../cximage/Debug/cximage.lib ../../raw/debug/libdcr.lib

9

Page 43: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Example of Load an Image File

void CDIP1Dlg::OnBnClickedOpen() { CFileDialog fOpenDlg(TRUE, "jpg", NULL, OFN_HIDEREADONLY|

OFN_FILEMUSTEXIST, "JPEG (*.jpg)|*.jpg|BITMAP (*.bmp)|*.bmp||", this);

fOpenDlg.m_pOFN->lpstrTitle="Select an Image File";

fOpenDlg.m_pOFN->lpstrInitialDir="c:";

if(fOpenDlg.DoModal()==IDOK) { CString FN = fOpenDlg.GetPathName(); int Type = CxImage::GetTypeIdFromName(FN.Mid(FN.ReverseFind('.')+1));

m_ViewImage.Load(FN,Type); RedrawWindow(); } }

Page 44: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Example of Save an Image File

void CDIP1Dlg::OnBnClickedSave() { CFileDialog fOpenDlg(FALSE, "jpg", NULL, OFN_HIDEREADONLY|

OFN_FILEMUSTEXIST, "JPEG (*.jpg)|*.jpg|BITMAP (*.bmp)|*.bmp||", this);

fOpenDlg.m_pOFN->lpstrTitle="Select an Image File";

fOpenDlg.m_pOFN->lpstrInitialDir="c:";

if(fOpenDlg.DoModal()==IDOK) { CString FN = fOpenDlg.GetPathName(); int Type = CxImage::GetTypeIdFromName(FN.Mid(FN.ReverseFind('.')+1));

m_ViewImage.Save(FN,Type); } }

Page 45: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Example of Changing from a Color Image to a Gray Image

void CDIP1Dlg::OnBnClickedGrayImage() { DWORD Width = m_ViewImage.GetWidth(); DWORD Height = m_ViewImage.GetHeight(); DWORD x,y; RGBQUAD rgb; BYTE Gray;

for(y=0;y<Height;y++) for(x=0;x<Width;x++) { rgb = m_ViewImage.GetPixelColor(x,y); Gray = (BYTE) ((((float) rgb.rgbRed) + ((float) rgb.rgbGreen) + ((float) rgb.rgbBlue))/3.0); rgb.rgbRed = Gray; rgb.rgbGreen = Gray; rgb.rgbBlue = Gray; m_ViewImage.SetPixelColor(x,y,rgb); }

RedrawWindow(); }

Page 46: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

Example of Displaying an Image

void CDIP1Dlg::OnPaint() { if (IsIconic()) {

• :

} else { CPaintDC dc(this); // device context for painting CRect rect; CWnd *pWnd; pWnd = GetDlgItem(IDC_IMAGE_VIEW); pWnd->GetWindowRect( &rect ); ScreenToClient( &rect ); if(m_ViewImage.IsValid()) m_ViewImage.Stretch(dc.GetSafeHdc(), rect); CDialog::OnPaint(); } }

Page 47: Dr. Thurdsak LEAUHATONG Dept. of electronics, Faculty of Engineering, KMITL klthurds@gmail.com thurdsak@hotmail.com klthurds@kmitl.ac.th.

How Computer Store an Image

a(0,0) a(1,0) a(2,0) a(3,0) a(4,0) a(5,0) a(6,0) a(7,0) a(8,0) a(9,0)

a(0,1) a(1,1) a(2,1) a(3,1) a(4,1) a(5,1) a(6,1) a(7,1) a(8,1) a(9,1)

a(0,2) a(1,2) a(2,2) a(3,2) a(4,2) a(5,2) a(6,2) a(7,2) a(8,2) a(9,2)

a(0,3) a(1,3) a(2,3) a(3,3) a(4,3) a(5,3) a(6,3) a(7,3) a(8,3) a(9,3)

a(0,4) a(1,4) a(2,4) a(3,4) a(4,4) a(5,4) a(6,4) a(7,4) a(8,4) a(9,4)

a(0,5) a(1,5) a(2,5) a(3,5) a(4,5) a(5,5) a(6,5) a(7,5) a(8,5) a(9,5)

a(0,6) a(1,6) a(2,6) a(3,6) a(4,6) a(5,6) a(6,6) a(7,6) a(8,6) a(9,6)

a(0,7) a(1,7) a(2,7) a(3,7) a(4,7) a(5,7) a(6,7) a(7,7) a(8,7) a(9,7)

a(0,8) a(1,8) a(2,8) a(3,8) a(4,8) a(5,8) a(6,8) a(7,8) a(8,8) a(9,8)