2.3.2 Contrast Stretching

61
2.3.2 Contrast Stretching Contrast The contrast of an image is its distribution of light and dark pixels Fig. 2.12 Low and high contrast histogram.

description

2.3.2 Contrast Stretching. Contrast The contrast of an image is its distribution of light and dark pixels. Fig. 2.12 Low and high contrast histogram. Contrast Stretching. Contrast stretching Clipping thresholding. Contrast Stretching. Contrast Stretching, a = 80, b= 160. Original Image. - PowerPoint PPT Presentation

Transcript of 2.3.2 Contrast Stretching

Page 1: 2.3.2 Contrast Stretching

2.3.2 Contrast StretchingContrast

The contrast of an image is its distribution of light and dark pixels

Fig. 2.12 Low and high contrast histogram.

Page 2: 2.3.2 Contrast Stretching

Contrast Stretching Contrast stretching

Clipping

thresholding

Lubvbu

buavau

auu

v

LvLuufv

b

a

)(

)(

0,

],0[],,0[)(

0 ],[ bautba

Page 3: 2.3.2 Contrast Stretching

Contrast Stretching

5.0

5.0

5.1

5.1

5.0

5.0

5.0

5.1

5.0

Contrast Stretching, a = 80, b= 160

Page 4: 2.3.2 Contrast Stretching

Contrast Stretching

Original Image

Original Image

Basic Contrast Stretching

End-in Search

Page 5: 2.3.2 Contrast Stretching

Original Image Convert ImageContrast Stretching

Page 6: 2.3.2 Contrast Stretching

Red Green Blue

Page 7: 2.3.2 Contrast Stretching

/******************************************** * Func: auto_contrast_stretch * Desc: performs basic contrast stretching on an image

* Params: source - pointer to source image

* cols - number of columns in the image *

rows - height of image * ********************************************* void auto_contrast_stretch(image_ptr source, int cols, int

rows) { long i; /* loop variable */ long number_of_pixels; /* total number of pixels in

image */

Page 8: 2.3.2 Contrast Stretching

long histogram[256]; /* image histogram */ unsigned char LUT[256]; /* Look-up table for point

process */ int lowthresh, highthresh; /* lower and upper

thresholds */ float scale_factor; /* scaling factor for contrast stretch

*/ /* compute histogram */ number_of_pixels = (long)cols * rows; for(i=0; i<256; i++) histogram[i]=0; for(i=0; i<number_of_pixels; i++) histogram[source[i]]++;

Page 9: 2.3.2 Contrast Stretching

/* compute low and high thresholds */ for(i=0; i<256; i++) if(histogram[i]) { lowthresh = i; break; } for(i=255; i>0; i--) if(histogram[i]) { highthresh = i; break; }

Page 10: 2.3.2 Contrast Stretching

printf("Low threshold is %d High threshold is %d\n",

lowthresh,highthresh);

/* compute new LUT */ for(i=0; i<lowthresh; i++) LUT[i]=0;

for(i=255; i>highthresh; i--) LUT[i]=255;

Page 11: 2.3.2 Contrast Stretching

scale_factor = 255.0 / (highthresh-lowthresh); for(i=lowthresh; i<=highthresh; i++) LUT[i]=(unsigned char)((i - lowthresh) *

scale_factor);

/* transfer new image */ for(i=0; i<number_of_pixels; i++) source[i] = LUT[source[i]]; }

Page 12: 2.3.2 Contrast Stretching

2.3.3 Intensity transformations

Digital negative Applications

Display of medical images Produce negative prints of images

Intensity level slicing Applications :

Segmentation of certain gray level regions

Page 13: 2.3.2 Contrast Stretching

Intensity transformations Intensity transformation

Convert an old pixel into a new pixel based on some predefined function

Implemented with simple look-up tables Simple transformation

Null transform new pixel = old pixel

Image negative y = -x+255

Gamma correction function Brightness of an image can be adjusted with a

gamma correction transformation

Page 14: 2.3.2 Contrast Stretching

Intensity transformations

Posterizing reduces the number

of gray levels in an images

Thresholding results when number of gray levels is reduced to 2.

A bounced threshold reduces the thresholding to a limited range and treats the other input pixels as null transformation

Figure 2.18(pp.63) Fig. 2.18 (a) 8-Level posterize transformation; (b) posterized image; (c) threshold transformation; (d) threshold image; (e) bounded threshold; (f) bounded threshold image.

Page 15: 2.3.2 Contrast Stretching

Intensity transformations

Gamma correction

uv

Original gamma=0.45 gamma=2.20

Page 16: 2.3.2 Contrast Stretching

Intensity Transformation Intensity Transformation

Intensity transformation is a point process that converts an old pixel into a new pixel base on some predefined function. This transformation is implemented with the LUT with ease.

Gamma Correction

Page 17: 2.3.2 Contrast Stretching

Intensity Transformation

Page 18: 2.3.2 Contrast Stretching

Intensity Transformation

Page 19: 2.3.2 Contrast Stretching

Intensity Transformation

Page 20: 2.3.2 Contrast Stretching

Intensity transformations

Page 60. 참조

Fig. 2.15 (a) Null transformation; (b) image; (c) negative transformation; (d) negative image.

Fig. 2.16 (a) Gamma collection transformation with gamma=0.45; (b) gamma collected image; (c) gamma collection transformation with gamma=2.2; (d) gamma collected image.

Page 21: 2.3.2 Contrast Stretching

Intensity transformations

Page 62. 참조

Fig. 2.18 (a) 8-Level posterize transformation; (b) posterized image; (c) threshold transformation; (d) threshold image; (e) bounded threshold; (f) bounded threshold image.

Fig. 2.17 (a) Contrast stretch transformation; (b) contrast stretched image; (c) Contrast compression transformation; (d) contrast compressed image.

Page 22: 2.3.2 Contrast Stretching

Intensity transformations

Page 64. 참조

Fig. 2.19 (a) 2-bit bit-clipping transformation; (b) resulting image.

Fig. 2.20 Bit clipped image contrast stretched.Fig. 2.21 (a) Iso-intensity contouring transformation; (b) contoured image.

Page 23: 2.3.2 Contrast Stretching

Intensity tranformations

Page 65. 참조

Fig. 2.22 (a) Range-highlighting transformation; (b) resulting image.

Fig. 2.23 (a) Solarize transformation using a threshold of 150; (b) solarize image.

Page 24: 2.3.2 Contrast Stretching

Fig. 2.24 (a) First parabola transformation; (b) transformed image; (c) second parabola transformation; (d) second transformed image.

Page 25: 2.3.2 Contrast Stretching

HW – 03 a)

Plot กราฟ histogram

Page 26: 2.3.2 Contrast Stretching

HW – 03 b)

Page 27: 2.3.2 Contrast Stretching

Fourier Transform

MTCT DI&SP

2.4 Frequency-based Operations

Page 28: 2.3.2 Contrast Stretching

Spatial Frequency

Efficient data representation Provides a means for modeling and

removing noise Physical processes are often best

described in “frequency domain” Provides a powerful means of image

analysis

Page 29: 2.3.2 Contrast Stretching

What is spatial frequency?

Instead of describing a function (i.e., a shape) by a series of positions

It is described by a series of cosines Fourier series Fourier Transform

Page 30: 2.3.2 Contrast Stretching

1-D Fourier Transform

MTCT DI&SP

Page 31: 2.3.2 Contrast Stretching

Our starting place is the observation that a periodic function may be written as the sum of sines and cosines of varying amplitudes and frequencies.

Page 32: 2.3.2 Contrast Stretching

it is possible to form any function as a summation of a series of sine and cosine terms of increasing frequency

For example, in figure we plot a function, and its decomposition into sine functions.

Page 33: 2.3.2 Contrast Stretching

f(t)

Page 34: 2.3.2 Contrast Stretching

We take the first three terms only (blue, green, red) to provide the approximation of the original function (purple).

The more terms of the series we take, the closer the sum will approach the original function.

Page 35: 2.3.2 Contrast Stretching

(1)

where

(2)

k

tjkwekFtf 0)()(

dtetfT

kF tjkwT

T

02/

2/)(

1)(

Original function (purple) sines and cosines

Fourier coefficient

Equations 1 and 2 are called Fourier transform pairs, and they exist if f(t) is continuous and integrable, and F(k) is integrable. These conditions are usually satisfied in practice.

Page 36: 2.3.2 Contrast Stretching

1

2

3

1

2

3

4

4

I

II

f(t) => time-domain

F(u) => frequency-domain

Page 37: 2.3.2 Contrast Stretching

Any function can be represented in 2 formats: 1) time-domain representation, f(t), or

spatial domain, f(x), and 2) frequency-domain representationor

Fourier domain, F(u)

In other words, any space or time varying data can be transformed into a different

domain called the frequency space.

Page 38: 2.3.2 Contrast Stretching

Time-domain Frequency-domain

Page 39: 2.3.2 Contrast Stretching

FT properties:If F(u) and G(u) are FT of function f(t) and g(t), respectively,

Time scaling

Frequency scaling

)(1

)(a

uH

aatf

)()(1

auHa

tf

a

Page 40: 2.3.2 Contrast Stretching

Time shifting

Frequency shifting

020 )()( utjeuHttf

)()( 02 0 uuHetf tuj

Page 41: 2.3.2 Contrast Stretching

Convolution theorem

Correlation theorem

)()()()()()( uGuHdtgftgtf

dgtftgtfCorr )()())(),((

Page 42: 2.3.2 Contrast Stretching

2-D Fourier Transform

MTCT DI&SP

Page 43: 2.3.2 Contrast Stretching

แนวความค�ดของการแปลงฟ�เร�ยร�สามารถน�ามา ใช้�ก�บฟ�งก�ช้� นหร"อส�ญญาณ 2 ม�ติ� เช้&น ภาพ

ซึ่* งจะเป-นการแปลงฟ�งก�ช้� นบน spatial domain (ร�ปภาพ ) ไปเป-น frequency domain สมการคณ�ติศาสติร�แสดงความส�มพ�นธ์�น�1เป-นด�งน�1

dudvevuFyxf vyuxj )(2),(),(

dxdyeyxfvuF vyuxj )(2),(),(

FT

IFT

Page 44: 2.3.2 Contrast Stretching

ภาพแสดงความส�มพ�นธ์�ระหว&างภาพในspatial domain และความถ� ในfrequency (or Fourier) domain

Page 45: 2.3.2 Contrast Stretching

พบว&าระยะถ� - ห&างทางติ�าแหน&งในภาพ (x-y ในspatial domain) จะแปลงไปเป-นจ4ดในfrequency domain (u-v)

โดยบร�เวณท� ม�ระยะห&าง (ซึ่* งม�ความถ� ทางติ�าแหน&งติ� า ) เช้&น บร�เวณติ�วบ�านรวมท�1งหน�าติ&าง- ประติ� จะไป

อย�&ในติ�าแหน&งท� ใกล�จ4ดก�าเน�ด และในทางกล�บก�นบร�เวณท� ม�ระยะถ� (ซึ่* งม�ความถ�

ทางติ�าแหน&งส�ง ) เช้&น บร�เวณท� ม�ลวดลายบนหล�งคา บ�าน จะไปอย�&ในติ�าแหน&งท� ไกลจ4ดก�าเน�ดออกไป

Page 46: 2.3.2 Contrast Stretching
Page 47: 2.3.2 Contrast Stretching
Page 48: 2.3.2 Contrast Stretching
Page 49: 2.3.2 Contrast Stretching
Page 50: 2.3.2 Contrast Stretching
Page 51: 2.3.2 Contrast Stretching
Page 52: 2.3.2 Contrast Stretching

ค4ณสมบ�ติ�ของการแปลงแบบฟ�เร�ยร�2 ม�ติ�(Properties of the 2-D Fourier Transform)

ค4ณสมบ�ติ�ของ Fourier Transform ของฟ�ง ก�ช้� น 2 ม�ติ�ท� ถ�กขยายมาจากในกรณ� 1 ม�ติ�ม�

ด�งน�1

Page 53: 2.3.2 Contrast Stretching
Page 54: 2.3.2 Contrast Stretching

การแปลงแบบฟาส�ทฟ�เร�ยร� (The Fast Fourier Transform)

ในกรณ�ท� ข�อม�ลเป-นปร�มาณเติ6มหน&วย(discrete) ด�งเช้&นภาพท� ถ�กน�าเข�าส�&ระบบคอมพ�วเติอร� การแปลงฟ�เร�ยร�ข�างติ�นย�งคง

ใช้�ได�อย&างสะดวกหล�งจากม�การปร�บปร4งแล�ว โดยสมการคณ�ติศาสติร�ของความส�มพ�นธ์�ค�&น�1จ*ง

เป-นแบบเติ6มหน&วย (Discrete Fourier Transform-DFT) เป-นด�งน�1

Page 55: 2.3.2 Contrast Stretching

ส�าหร�บภาพท� ม�ขนาด NxM จะได�

)(21

0

1

0

),(),( vyuxjM

v

N

u

evuFyxf

)(21

0

1

0

),(1

),( vyuxjM

y

N

x

eyxfNM

vuF

Page 56: 2.3.2 Contrast Stretching

เม" อติ�องการใช้�คอมพ�วเติอร�ประมวลผลการแปลง น�1 จ�าเป-นติ�องใช้�ข� 1นติอนว�ธ์� (algorith-m) ท�

รวดเร6วและม�ประส�ทธ์�ภาพ ด�งน�1นจ*งม�ผ��เสนอข�1น ติอนว�ธ์�ท� เร�ยกว&า (The Fast Fourier Transfo

rm-FFT ) และได�ร�บความน�ยมอย&างกว�างขวาง

Page 57: 2.3.2 Contrast Stretching

Spatial FrequencyorHow I learned to love the Fourier Transform

Jean Baptiste Joseph Fourier

Page 58: 2.3.2 Contrast Stretching

2.5 Group-based Operations

• Convolution Operation

MTCT DI&SP

Page 59: 2.3.2 Contrast Stretching

• การกระทำ�าแบบคอนโวลู�ชั่��นเป็�นการหาค�าใหม่�ของจุ�ดภาพใด ๆ โดยพ$จุารณาระบบเพ&�อนบ'าน (Neighbors System) • ในข�(นแรกจุะต้'องก�าหนด window หร&อ kernel ซึ่+�งเป็�นต้ารางสี่-�เหลู-�ยม่จุต้�ร�สี่ขนาด 3x3, 5x5 หร&อขนาดอ&�น ๆ • แต้�ลูะชั่�องของต้ารางน-(จุะถู�กก�าหนดให'ม่-ค�าน�(าหน�ก (Weights) โดยแต้�ลูะชั่�องอาจุม่-ค�าเทำ�าก�นหร&อไม่�ก0ได' • จุากน�(นน�า kernel น-(ม่าทำาบบนภาพแลูะหาบวกของผลูค�ณระหว�างค�าน�(าหน�กก�บค�าความ่เข'ม่บนจุ�ดภาพ • แลู'วเลู&�อน kernel น-(เพ&�อไป็หาค�าใหม่�ของจุ�ดภาพถู�ดไป็

MTCT DI&SP

Page 60: 2.3.2 Contrast Stretching
Page 61: 2.3.2 Contrast Stretching