gray level 변환 및 arithmetic 연산을 사용한 영상 개선

29
Arithmetic 연산 및 Gray-level 변환을 사용한 영상 개선 김성영교수 금오공과대학교 컴퓨터공학과

Upload: truongkiet

Post on 05-Feb-2017

225 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

Arithmetic 연산및 Gray-level 변환을

사용한영상 개선

김성영교수

금오공과대학교

컴퓨터공학과

Page 2: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

2

학습 내용

단일픽셀처리(point pixel processing) 개요

Scalar and Image arithmetic operations

Gray-level transformations

Page 3: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

3

point pixel processing

이웃픽셀과는독립적으로입력영상의각픽셀값을변환한후결과영상의동일한위치에출력하는연산

f(x, y)

I I’

I = I’: in-place transformation

Page 4: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

444

Arithmetic operations

Gray-level transformations

Histogram modifications

techniques

Page 5: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

555

Improving image contrast and brightnessImage contrast: a measure of the distribution and range of the gray levels

the difference between the brightness and darkest pixel values, andhow the intermediate values are arranged

Image brightness: the overall average or mean pixel value in the image

objective

Page 6: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

666

Contrast & Brightness

Page 7: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

7

연산 구 현

덧셈 OutImage[x][y] = InImage[x][y]+C1

뺄셈 OutImage[x][y] = InImage[x][y]-C2

곱셈 OutImage[x][y] = InImage[x][y]*C3

나눗셈 OutImage[x][y] = InImage[x][y]/C4

if( OutImage[x][y] > 255 ) OutImage[x][y] = 255;

if( OutImage[x][y] < 0 ) OutImage[x][y] = 0;

클리핑(clipping) 처리

Scalar arithmetic operation

Page 8: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

888

덧셈연산 (+50) 뺄셈연산 (-50)

Page 9: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

999

곱셈연산 (*1.2) 나눗셈연산 (/1.2)

Page 10: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

101010

void scalarAdd( Mat &image, Mat &result, int value ){

int numOfLines = image.rows; // number of lines in the imageint numOfPixels = image.cols; // number of pixels per a line

result.create( image.rows, image.cols, image.type() );for( int r=0; r<numOfLines; r++ ){

const uchar *data_in = image.ptr<uchar>( r );uchar *data_out = result.ptr<uchar>( r );for( int c=0; c<numOfPixels; c++ ){

data_out[c] = saturate_cast<uchar>( data_in[c] + value );}

}}

Page 11: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

111111

cv::add( image, cv::Scalar(value), result )result = image + value

cv::subtract( image, cv::Scalar(value), result )result = image - value

cv::multiply( image, cv::Scalar(value), result )result = image * value

cv::divide( image, cv::Scalar(value), result )result = image / value

Page 12: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

12

+

Image arithmetic operation

Page 13: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

131313

void imageAdd( Mat &image1, Mat &image2, Mat &result ){

int numOfLines = image1.rows; // number of lines in the imageint numOfPixels = image1.cols; // number of pixels per a line

result.create( image1.rows, image1.cols, image1.type() );for( int r=0; r<numOfLines; r++ ){

const uchar *data1_in = image1.ptr<uchar>( r );const uchar *data2_in = image2.ptr<uchar>( r );uchar *data_out = result.ptr<uchar>( r );for( int c=0; c<numOfPixels; c++ ){

data_out[c] = saturate_cast<uchar>( data1_in[c] + data2_in[c] );}

}}

Page 14: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

141414

-

subtract diff

Page 15: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

151515

void imageDiff( Mat &image1, Mat &image2, Mat &result ){

int numOfLines = image1.rows; // number of lines in the imageint numOfPixels = image1.cols; // number of pixels per a line

result.create( image1.rows, image1.cols, image1.type() );for( int r=0; r<numOfLines; r++ ){

const uchar *src1 = image1.ptr<uchar>( r );const uchar *src2 = image2.ptr<uchar>( r );uchar *dst = result.ptr<uchar>( r );for( int c=0; c<numOfPixels; c++ ){

dst[c] = saturate_cast<uchar>( abs(src1[c] – src2[c]) );

}}

}

Page 16: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

161616

-

Page 17: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

171717

cv::addWeighted( src1, alpha, src2, beta, gamma, dst )dst = src1*alpha + src2*beta + gamma

ex) result = image1*0.7 + image2*0.5 + 0.0

ex) result = image1*1.0 + image2*(-1.0) + 0.0

cv::scaleAdd( src1, alpha, src2, dst )dst = src1*alpha + src2ex) result = image1*0.7 + image2

Page 18: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

18

Gray-level transformations

Improving image contrast and brightness by using mapping functionO(x, y) = M[I(x, y)]

gray-level scaling or gray-scale modification

Page 19: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

191919

(10,50) 범위의 gray level을 (10,250) 범위로확장

original gray-level values

mod

ified

gra

y-le

vel v

alue

s

10 5030

≤<≤≤−<≤

=255),(50),(50),(1050)],([6

50),(0),()],([

yxIforyxIyxIforyxI

yxIforyxIyxIM

example

Page 20: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

202020

original gray-level values

mod

ified

gra

y-le

vel v

alue

s

(r1, s1)

(r2, s2)

General Form of Gray-Scale Modification

Page 21: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

212121

Gray-scale Compression

original gray-level values

mod

ified

gra

y-le

vel v

alue

s

153

0.6

Page 22: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

222222

Gray-scale Stretching

original gray-level values

mod

ified

gra

y-le

vel v

alue

s

40 170

1.96

Page 23: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

232323

original gray-level values

mod

ified

gra

y-le

vel v

alue

s

5 40

Page 24: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

242424

original gray-level values

mod

ified

gra

y-le

vel v

alue

s

110 200

Gray-level Slicing

Page 25: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

252525

original gray-level values

mod

ified

gra

y-le

vel v

alue

s

Page 26: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

262626

Gray-level Thresholding

original gray-level values

mod

ified

gra

y-le

vel v

alue

s

T

Page 27: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

272727

original gray-level values

mod

ified

gra

y-le

vel v

alue

sGray-level Negative

Page 28: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

28

요약

point pixel processing 이웃픽셀과는독립적으로입력영상의각픽셀값을변환한후결과영상의동일한위치에출력하는연산

목적: Improving image contrast and brightness

Arithmetic operation Scalar operation: 단일영상에상수를더하거나빼는연산

Image operation: 영상간에더하거나빼는연산

Gray-level transformations Improving image contrast and brightness by using mapping function

Gray-scale Compression, Gray-scale Stretching, Gray-level Sliding, Gray-level Thresholding, Gray-level Negative 등

Page 29: Gray level 변환 및 Arithmetic 연산을 사용한 영상 개선

29

Reference

Scott E Umbaugh, Computer Imaging, CRC Press, 2005

R. Laganière, OpenCV2 Computer Vision: Application Programming Cookbook, PACKT Publishing, 2011

G. Bradski and A. Kaebler, Learning OpenCV: Computer Vision with the OpenCV Library, O’REILLY, 2008

정성환, 이문호, 오픈소스 OpenCV를이용한컴퓨터비전실무프로그래밍, 홍릉과학출판사, 2007