영상처리 프로그래밍 : 영상 처리의 실제 practical image processing

50
영영영영 영영영영영 : 영영 영영영 영영 Practical Image Processing

Upload: melina-parks

Post on 13-Dec-2015

279 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

영상처리 프로그래밍: 영상 처리의 실제

Practical Image Processing

Page 2: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Contact Information

• 김백섭 A1201 x2313• www.hallym.ac.kr/~bskim• [email protected]

Page 3: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Course Outline

• Image Enhancement : 영상을 밝게 / 어둡게 , 부드럽게 / 샤프하게

• Geometric processing : 이동 , 회전 , 확대 / 축소• Frequency domain : 주파수 공간으로 변환 / 처리

PhotoShop

• Programming : Windows

IPP (Image Processing Platform)

Page 4: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing
Page 5: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing
Page 6: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing
Page 7: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing
Page 8: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Chap.1 Introduction

• What is the Image Processing• Digital Image Definition• Types of operations• Applications• Representation of color images• Programming tools• Image file formats and Data structures

Page 9: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

What is Image Processingscience of manipulating picture(image)science of manipulating picture(image)

Enhancement(Enhancement( 향상향상 ))Analysis(Analysis( 해석해석 ))Compression(Compression( 압축압축 ))

Related areasRelated areasCV : Computer Vision (Image Understanding)CV : Computer Vision (Image Understanding)CG : Computer GraphicsCG : Computer GraphicsPR : Pattern RecognitionPR : Pattern Recognition

ImageImage SymbolSymbol

CVCV

CGCGIPIP PRPR

Page 10: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Digital Image

Image (N x M)Image (N x M)

RegionRegion(window)(window)

Pixel (L) Pixel (L) PelPel(Picture element)(Picture element)

Columns (N)Columns (N)

Row

s (M)

Row

s (M)

Ex) 640 x 480 x 8 bit imageEx) 640 x 480 x 8 bit image

LennaLenna

Page 11: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Digital Image (cont.)Columns (N)Columns (N)

Row

s (M)

Row

s (M)

x, colx, col

y, rowy, row

2 dimensional array2 dimensional arrayunsigned char im[N][M]unsigned char im[N][M]

int im[n][m]int im[n][m]

float im[n][m]float im[n][m]

unsigned char im[n][m][3]unsigned char im[n][m][3]

1 dimensional array1 dimensional arrayunsigned char im[N*M]unsigned char im[N*M]

Page 12: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

512x512512x512

32x3232x32 16x1616x16

256x256256x256

Page 13: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

16 816 8

4 2 4 2

Page 14: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Types of Operations• Point Operation

– the output value at a specific coordinate is dependent only on the input value at that same coordinate

– Ex) brightness control, contrast control

Page 15: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

•Local (Region, Mask, Area) Operation

–the output value at a specific coordinate is dependent on the input values in the neighborhood of that same coordinate

–Ex) smoothing, sharpening, edge enhancement

Page 16: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

4-connected4-connected 8-connected8-connected 6-connected6-connected

Note : types of neighborhoods

Page 17: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

• Global Operation– the output value at a specific coordinate is

dependent on all the values in the input image– Ex) Fourier transform

Page 18: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

18

ApplicationsApplications• science and space

space probes generate images of space

• movies image composition, morphing, image warping

• paperless office document image processing, optical character

recognition

• medical industry CT (computer-aid tomography), MRI

• machine vision control manufacturing environment

• law enforcement fingerprint image analysis, facial image analysis

Page 19: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Input DevicesInput Devices• TV Camera, Vidicon Tube, Digital camera• CCD Camera

– Single IC device – Consists of an array of photosensitive cells – each cell produces an electric current dependent on the

incident light falling on it.

– Video Signal Output – Less geometric distortion – More linear Video output.

• Frame Grabber– A/D conversion + Video memory (frame memory)

Page 20: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

발표 #1

• 3/22 ( 월 )1) digital camera 를 조사하라 . ( 화소수 , CCD

크기 , 기억장치 , PC interface 방법등 종류와 각각에 대한 장단점 )

2) digital camera 영상을 인쇄 (print) 하는 방법들을 조사하라 . (printer, 종이 , 인터넷 서비스 )

3) camcoder 종류를 조사하라 .4) 영상처리 , 그래픽스 프로그램을 조사하라 .

Page 21: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

맹점 (blind spot)

참고 : 사람의 눈

fovea직경 : 2cm

수용체 (receptor): 센서 종류 간상세포 ( 어두운 빛 ) 원추세포 ( 밝은 빛 + 색깔 )

중심와 (fovea) : 망막의 중심 . ( 중심부에 가장 깊이 들어간 부분 )

원추세포만 있음 (1 도 범위에 120 만개 ) 2μ m 간격

빛 양에 따라 크기 조절 .카메라 조리개에 해당

거리조절 .카메라 렌즈에 해당

Page 22: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

참고 : 보안 시스템 , 영상처리

Page 23: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

참고 : 생체인식 , 영상처리

Page 24: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

수용체 (receptor) 밀도 ( 분포 )

맹점

관자놀이 코

rod( 간상세포 ) : 거의 180 도에 분포 . ( 전 영역에 골고루 ) : 1.2억개 *

cone( 원추세포 ) : 망막 중심 (fovea) 에 밀집 : 600 만개 *

* 여러 학설 있으나 Dr. John Penn (UAMS eye center) 주장

Page 25: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

수용체의 반응수용체의 반응• Rod( 간상세포 )

– 밝기 (brightness) 에 민감 . 녹색 (500nm) 에 제일 민감 .– 망막 전 영역 (180 도 ) 에 고루 분포 ( 약 120M 개 )– 반응 느림 ( 약 1/10 초 ). 대신 어두운 빛에도 반응

( 망막외곽의 움직임에는 약간 분포되어 있는 원추세포가 반응 )• Cone( 원추세포 )

– 색 (colo) 에 민감 . – fovea 주변 +-10 도에 주로 분포 . 나머지 부분에도 약간이지만 고르게 분포 ( 약 6M

개 )– 3 가지 종류 (blue, green, red) 가 같은 수 있음 2M 화소에 해당

가시광선 : 380~780 nano

밝기 대한 반응

색에 대한 반응 :원추세포

Page 26: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Stimulus Sensitivity• 대비 (contrast) 에 민감 : 같은 빛의 세기 (Intensity) 라도 주관적으로 밝기 (Brightness) 를

다르게 느낀다 : ( 예 ) 주변이 어두우면 대상을 밝게 느낌 • Weber-Fechner law : 사람은 빛의 세기 (intensity) 에 log 형태로 반응한다 .

R ∝ log(I)• ∆I / I ∝ d (log I) = 상수 (=0.02 : 50 개 정도 등급을 구별할 수 있다는 의미 ) • 사각형 (I) 안에 작은사각형 (I+ I)∆ 의 intensity 를 증가하면서 얼마큼 증가해야 사람이 구별하는지 실험• intensity 가 1 에서 1.1 로 바뀐 것이나 5 에서 5.5 로 바뀐 것이나 같은 정도 바뀐 것으로 인식한다 .

• Mach Band Effect : 경계부분에 민감하다 .

MachMachBand Band EffectEffect

밝기가 지수적으로 변한 것 .

이렇게 변해야 사람은 비례적 (선형적으로 변한 것으로 느낀다 )

Page 27: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Color Representation• 삼원색 (three primary colors) 을 혼합해서 임의의

색을 만들 수 있다고 가정• CIE : 1931 년에 삼원색의 표준 정함 X(435.8nm), Y

(546.1nm), Z(700nm) : 단색 어떤 색 L=(a, b, c) : 삼자극치 (tristimulus value)(a : X 의 양 (amount), b : Y 의 양 , c : Z 의 양 )

• 색도좌표 (Chromacitiy coordinate) : 삼자극치를 정규화 한 것 : (x, y, z) (x, y) 만 있으면 됨x = a/(a+b+c), y = b/(a+b+c), z = 1-(x+y)

• 색도도표 (Chromacitiy diagram) : 각각 색을 색도좌표로 바꾸어 평면에 표시한 것

Page 28: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Color : Spectrum

Visible : 380~780 nano ( 다른 책 : 400~700nano) 400: 자주 , 700: 빨강

Page 29: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Sun 600Sun 600°K :°K : (0.32, 0.33)(0.32, 0.33)

형광등형광등 :: (0.35, 0.37)(0.35, 0.37)

Red Red 형광물질형광물질 :: (0.68, 0.32)(0.68, 0.32)

Green Green 형광물질형광물질 :: (0.28, 0.60)(0.28, 0.60)

Blue Blue 형광물질형광물질 :: (0.15, 0.007)(0.15, 0.007)

진한 보라색 : CRT 에서 본 적이 있는지

Page 30: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Note : terminologies• Radiance : total amount of energy from the

light source (Watt)• Luminance : amount of energy an observer

perceives from a light source (Lumen)• Brightness : a subjective descriptor

(intensity)• Hue : dominant wavelength (color)• Saturation : amount of white light mixed with

a hue (purity)

Page 31: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Color Models

• Different models for different usage– Monitor : primary colors of light (RGB)– Printer : primary colors of pigments (CMY)– Image Processing : HSI, YCbCr

– Color TV : YIQ• Others

– Lab, YUV, UVW

Page 32: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

RGB model

• Red, Green, Blue : 1 byte each -> 3 bytesEx) (255, 0, 0) : red, (255, 255, 255) ?

• For display devices(CRT, LCD) and Graphics

• RGB to Intensity(Color to Gray level image) – Y = 0.299R + 0.587G + 0.114B

(YCbCr , YIQ)– I = (R + G + B) / 3 (H

SI)– I = G (Simple)

Page 33: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Color 흑백 변환 예

• 0.299R + 0.587G + 0.114B

초록색이 밝게 나왔다

• (R+G+B)/3초록색이 검게 나왔다

Page 34: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

CMY model• Cyan( 청록 ), Magenta( 자홍 ), Yellow( 노

랑 )• For printers• RGB to CMY conversion

C = 255-R, M = 255-G, Y = 255-B

• CMYK : CMY + K (black)• CMY to CMYK conversion

K = min(C, M, Y), C = C-K, M = M-K, Y = Y-K

Page 35: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Additive, Subtractive Color

Page 36: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Original image

below : R, G, B images

What is R ? What is G ?

Page 37: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

HSI model

• Hue, Saturation, Intensity• For image processing :

– Separation of color information(H, S) from gray information(I)

• Hue : – 0° ~ 360 °, 0 ° : red, 120 ° :

green, 240 ° : blue

• Saturation : purity of color– 0 ~ 1, 0 : white or black(no

color), 1 : pure color

Page 38: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

HSI<-> RGB Conversion (http://www.robo.mein.nagoya-u.ac.jp/~niimi/color-space/COL_24.htm)

Reference :   Gonzalez and Woods, Digital Image Processing, Prentice-Hall, 2002

RGB to HSI

  I = 1/3(R+G+B)  S = 1 - ( 3/(R+G+B))*a    where a is the minimum of R, G and B H = cos^(-1) ( (0.5*((R-G)+(R-B))) / ((R-G)^2 + (R-B)*(G-B))^(0.5) ) If S = 0, H is meaningless.   If (B/I) > (G/I) then H = 360 - H since H is an angle in degrees we     then normalise to 0,1 with H=H/360   

HSI to RGB

First we restore H to degrees with H = 360*H If 0 < H <= 120 then      B = 1/3(1-S)      R = 1/3(1+ [(S cos H) / (cos(60 - H))] )      G = 1 - (B+R)  If 120 < H <= 240 then       H = H - 120       R = 1/3(1-S)      G = 1/3(1+ [(S cos H) / (cos(60 - H))] )      B = 1 - (R+G)   If 240 < H <= 360 then       H = H - 240       G = 1/3(1-S)      B = 1/3(1+ [(S cos H) / (cos(60 - H))] )      R = 1 - (G+B)  

Page 39: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

컬러 영상을 밝게 처리하면• 원영상

• R, G, B 각각에 대해 밝게 한 것 ( 중앙의 초록색이 다른 색으로 변했음 )

• RGB 를 YIQ 로 바꾼 후 Y에 대해서만 밝게 한 것

Page 40: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

YCbCr model• For image processing :

– Separation of color information(Cb, Cr) from gray information(Y)

– CCIR 권고안 601-1. JPEG 에 사용• easy to convert from RGB than HSI

– just linear operation• RGB-> YCbCr, YCbCr ->RGB conversion

– Y = 0.29900R + 0.58700G + 0.11400B Cb = -0.16874R - 0.33126G + 0.50000B Cr = 0.50000R - 0.41869G - 0.08131B

– R = 1.00000Y + 1.40200Cr G = 1.00000Y - 0.34414Cb - 0.71414Cr

B = 1.00000Y + 1.77200Cb

Page 41: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

컬러 공간들의 비교 

RGB CMY HSI YCbCr

Red(빨강 ) 1, 0, 0 0, 1, 1 0°, 1, 0.33 0.299, -0.16874, 0.5

Green( 초록 )

0, 1, 0 1, 0, 1 120°, 1, 0.330.587, -0.33126, -

0.41869

Blue(Blue( 파랑파랑 )) 0, 0, 1 1, 1, 0 240°, 1, 0.33 0.114, 0.5, -0.08131

Cyan(청록 )

0, 1, 1 1, 0, 0 180°, 1, 0.66 0.701, 0.1687, -0.5

Magenta(자홍 )

1, 0, 1 0, 1, 0 300°, 1, 0.66 0.413, 0.3313, 0.41869

Yellow(노랑 )

1, 1, 0 0, 0, 1 60°, 1, 0.66 0.886, 0.5, 0.08131

Page 42: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Types of Digital Images• Gray Image (Intensity Image)

– range of a pixel : [0, 255]. 1 byte

• Binary Image– range of a pixel : {0, 1} or {0, 255}. – 1 bit or 1 byte

• Color Image– 3 gray images. 3 bytes (or 3 float numbers)

• Complex Image– result of Fourier transform. 2 float numbers/pixel

• Indexed Image– for indexed color. (next slide) 1 byte/pixel

Page 43: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Indexed color : Color Map 사용

Page 44: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Image File Formats

• BMP (Bit MaP) – for Windows 3.0 이후 , DIB format

• TIFF (Tagged Image File Format)– Adobe + Silicon Graphics, tag+data field

• GIF (Graphics Interchange Format)– CompuServe. LZW Compressed

• JPEG (Joint Photographic Experts Group)– ITU. High compression rate

• PCX– Paintbrush.

Page 45: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

PBM file format

• simple. in universities.• pbm(binary), pgm(gray), ppm(color)• header : ascii text

– Magic number (file type) : P5 - table 1.5– Image Width : 640– Image Height : 480– Maximum gray level : 256

• data : binary or ascii– depending on the Magic number

Page 46: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

BMP formatThe Windows DIB (Device Independent Bitmap or BMP) format is the mos

t common file format used with Windows software (Microsoft, 1991). DIB files may be used by programmers as a Windows resource to store graphics inside an executable file, but they are also the native format used by virtually all Windows software that imports or exports graphics. DIB files may be monochrome, colourmapped with 16 or 256 colours, or they may be 24 bit true colour. They may also be stored in either an uncompressed format or with run length encoding. Although DIB files are ubiquitous in the Windows world they are rarely supported by software on other operating system, so this format is not often suitable for porting images between platforms.

ibis.nott.ac.uk/guidelines/ch62/chap6-2-A-2.html • www.imagemontage.com/Docs/BMP.html • www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

Page 47: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Image Data Structure• Image :

– data : 2 dimensional matrix, A– properties : width, height, type, ...

• Data – 1 D array : a[width*height]

• A(row, row) a[col + (row-1)*width]– 2 D array : a[width][height]

• A(row, col) a[col][row] – color : one more dimension : a[width][height][3]

• Red(row, col) <- a[col][row][0]

Page 48: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

• Properties : structure (or class members)typedef struct_IplImage { // IPL.H

int depth; // pixel depth in bitschar colorModel[4]; // RGB, ..int align; // 4- or 8-byte alignint width;int height;int widthStep; // size of a line in byteschar *imageData; // points data...

} IplImage;

Page 49: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

Programming tools

• collection of public/commercial codeswww.cs.cmu.edu/afs/cs/project/cil/www/txtv-source.html

• xv, cvip, aphelion, khorus• matlab• OpenCV : Open Souce Computer Vision Library

(Intel)www.intel.com/research/mrl/research/opencv

• user written programs (IPP, CImage, ...)

Page 50: 영상처리 프로그래밍 : 영상 처리의 실제 Practical Image Processing

HomeWork #1 : due = 3/29/2004HomeWork #1 : due = 3/29/2004

1.1. 영상을 저장하는 영상을 저장하는 file formatfile format 을 하나 선정해서 각 을 하나 선정해서 각 fieldfield 의 역활을 의 역활을 조사하여 정리하라조사하여 정리하라 ..

2.2. 다음 영상을 밝게다음 영상을 밝게 , , 어둡게 처리하라어둡게 처리하라 . (. ( 기존 영상처리기존 영상처리 // 그래픽 그래픽

프로그램을 이용하되 처리에 사용한 프로그램을 명기바람프로그램을 이용하되 처리에 사용한 프로그램을 명기바람 ))