第二章 影像處理基礎 國立雲林科技大學 資訊工程研究所 張傳育(Chuan-Yu Chang ) 博士 Office: EB 212 TEL: 05-5342601 ext. 4337 E-mail: [email protected] Website: http://MIPL.yuntech.edu.tw 第二章學習目標 瞭解數位影像的組成及基本處理技術 學習如何進行影像縮放與灰階轉換 2 第二章 影像處理基礎 2.1 影像的組成 2.2 影像取樣與量化 2.3 影像解析度與縮放 2.4 基本灰階轉換 3 Image Formation An analog image is described by the spatial distribution of brightness or gray-levels that reflect a distribution of detected energy. The image can be displayed using a medium such as paper or film. The image may show A black-and-white image with gray-levels representing. A true color image with red, green, and blue components. 4 影像的組成 y Pin-Hole Imaging The pin-hole imaging method is used in many imaging systems. The light from the object plane enters into the image plane through a pin-hole. The pin-hole is called the focal plane. x z f(x1,y1) Pin-hole g(x2,y2) z1 Object Plane z2 Focal Plane Image Plane 5 影像的組成 If a point in the object plane is considered to have (x1, y1, -z1) coordinates mapped into the image plane as (x2, y2, z2) coordinates, then Magnification factor y z 2 x1 z 2 y1 x2 and y2 z1 z1 x z f(x1,y1) Pin-hole g(x2,y2) z1 Object Plane z2 Focal Plane Image Plane 6 影像取樣與量化 Digital Image Acquisition Process 7 影像取樣與量化 Image Sampling and Quantization To create a digital image, we need to convert the continuous sensed data into digital form. This involves two processes: Sampling Digitizing the coordinate values Quantization Digitizing the amplitude values 8 影像取樣與量化 9 影像取樣與量化 10 影像取樣與量化 11 Representing Digital Images Representing Digital Images The result of sampling and quantization is a matrix of real numbers. f (0,0) f (1,0) f ( x, y ) : f ( M 1,0) a0,0 a 1, 0 A : aM 1,0 f (0,1) ... f (1,1) ... : : f ( M 1,1) ... a0,1 a1,1 : aM 1,1 f (0, N 1) f (1, N 1) : f ( M 1, N 1) ... a0, N 1 ... a1, N 1 ... : ... aM 1, N 1 12 Representing Digital Images 13 Representing Digital Images Spatial Resolution The smallest discernible detail in an image. Line pair Size: 1024*1024 14 Representing Digital Images 15 Representing Digital Images Gray-Level Resolution The smallest discernible change in gray level. The # of gray levels is usually an integer power of 2. 16 Representing Digital Images False contouring 17 Color Image Formation Three basic colors, red, green and blue (RGB) could be used as three variables for representing color images. When combined together, the red, green and blue intensities can produce a selected color at a spatial location in the image. 18 Color Models The RGB Color Model Each color appears in its primary spectral components of red, green and blue . The number of bits used to represent each pixel in RGB space is called the pixel depth. Schematic of the RGB color cube. 19 Color Models (cont.) Example Generating the hidden face planes and a cross section of the RGB color cube. RGB 24-bit color cube The three hidden surface planes 20 Color Models (cont.) Example (cont.) Generating the RGB image of the cross-sectional color plane (127, G, B)21 Color Models (cont.) Safe RGB color, All-system-safe color, Safe Web color, Safe browser color 216 colors are common to most systems Each of the 216 safe colors is formed from three RGB values, each value can only be 0, 51, 102, 153, 204, or 255. The values 000000 and FFFFFF represent black and white, respectively. The RGB safe-color cube 22 Color Models (cont.) Valid values of each RGB component in a safe color The 216 safe RGB colors All the grays in the 256-color RGB system 23 Color Models (cont.) RGB to Graylevel 人眼對綠色的亮度感最大,而對藍色最小 Gray = R*0.299 + G*0.587 + B*0.114 Gray = (R*30 + G*59 + B*11 + 50) / 100 適合人類眼睛的灰階影像 24 Color Models (cont.) The CMY color model Cyan, magenta, and yellow are the secondary colors of light When cyan is illuminated with white light, no red light is reflected from the surface. Most devices that deposit colored pigments on paper, such as color printers and copiers, require CMY data input or perform an RGB to CMY conversion internally. C 1 R M 1 G Y 1 B R 1 C G 1 M B 1 Y (6.2-1) The assumptions is that all color values have been normalized to range [0,1]. The CMYK color model In order to produce true black, a fourth color black is added 25 Image Enhancement The principal objective of enhancement is to process an image so that the result is more suitable than the original image for a specific application. Image enhancement approaches Spatial domain methods Based on direct manipulation of pixels in an image. Frequency domain methods Based on modifying the Fourier transform of an image. 26 Image Enhancement (cont.) Spatial domain Refers to the aggregate of pixels composing an image. Operate directly on these pixels Spatial domain process will be denoted by g(x,y)=T[f(x,y)] where f(x,y): input image g(x,y): processed image T: an operator mask filter kernel template windows 27 Image Enhancement (cont.) Gray-Level (intensity) transformation Function s=T(r) where T is gray-level transformation function Processing technologies: Point processing Enhancement at any point in an image depends only on the gray level at that point. Mask processing or filtering Use a function of the values of f in a predefined neighborhood of (x,y) to determine the value of g at (x,y) Contrast stretching thresholding 28 Image Enhancement (cont.) Some basic Gray Level Transforms s = T(r) r : the gray level value before process s: the gray level value after process Values of the transformation function typically are stored in a one-dimensional array and the mapping from r to s are implemented via table lookups. 29 Some Basic Gray Level Transforms (cont.) Image Negatives Reversing the intensity levels of an image Photographic Negative s=L-1-r Suited for enhancing white or gray detail embedded in dark regions of an image 30 Some Basic Gray Level Transforms (cont.) Log Transformations s=c log (1+r) Maps a narrow range of low gray-level values in the input image into a wider range of output levels. To expand the values of dark pixels in an image while compressing the higher-level values A Fourier spectrum with values in the range 0 to 1.5x106. c=1, the range 31 of values : 0 to 6.2. Some Basic Gray Level Transforms (cont.) Power-Law Transformations s=crg To account for an offset s= c (r +e )r where c and `g are positive constants Power-law curves with fractional values of r map a narrow range of dark input values into a wider range of output values, with the opposite being true for higher values of input levels. 32 Some Basic Gray Level Transforms (cont.) Gamma Correction The process used to correct this power-law response phenomena 33 Some Basic Gray Level Transforms (cont.) Example 3.1 MR image of fractured human spine Contrast manipulation c=1, g=0.6 Fracture dislocation c=1, g=0.4 The best enhancement in terms of contrast and discernable detail was obtained. c=1, g=0.3 褪色(Washed-out) 34 Some Basic Gray Level Transforms (cont.) c=1, g=3.0 Washed-out appearance c=1, g=5.0 c=1, g=4.0 35 Some Basic Gray Level Transforms (cont.) Picewise-Linear Transformation Function Contrast Stretching To increase the dynamic range of the gray levels in the image being processed. Linear function If r1=s1 and r2=s2 Thresholding If r1=r2, s1=0 and s2=L-1 Control points 36 Some Basic Gray Level Transforms (cont.) Gray-level Slicing Highlighting a specific range of gray levels in an image. To display a high value for all gray levels in the range of interest and a low value for all other gray levels. Brightens the desired range of gray levels but preserves the background and graylevel in the image. 37 Some Basic Gray Level Transforms (cont.) 38 Histogram Processing Histogram h(rk)= nk rk is the kth gray-level nk is the number of pixels in the image having gray-level k Normalized Histogram p(rk)=nk/n 39 Histogram Processing (cont.) Histogram Equalization s T (r ) 0 r 1 Assume that the transformation function T(r) satisfies the follows (a) T(r) is a single-valued and monotonically increasing (b) 0<=T(r)<=1 for 0<=r <=1 40 Histogram Processing (cont.) Condition (a) is changed to T(r) is a strictly monotonically increasing function in the interval 0<=r <L-1 41 Histogram Processing (cont.) The probability of occurrence of gray level rk in an image is approximated by n pr (rk ) k k 0,1,2,...,L 1 n The discrete version of the transformation function given as sk T (rk ) k nj j 0 n k pr (r j ) j 0 k 0,1,2,...,L 1 A processed image is obtained by mapping each pixel with level rk in the input image into a corresponding pixel with level sk in the output image. Histogram equalization automatically determines a transformation function that seeks to produce an output image that has a uniform histogram. 42 Histogram Processing (cont.) s T r L 1 pr wdw r 0 43 Histogram Processing (cont.) 44 Histogram Processing (cont.) Example 3.3Histogram equalization 45 Histogram Processing (cont.) 46 Local Enhancement Global enhancement Local enhancement The pixels are modified by a transformation function based on the gray-level content of an entire image. To design transformation functions based on the gray-level distribution in the neighborhood of every pixel in the image. Local enhancement Procedure Step 1: Define a square neighborhood Step 2: Move the center of this area from pixel by pixel Calculate the histogram of the points in the neighborhood. Apply the histogram equalization or specification Assign new gray level to the center pixel Step 3: Moved to an adjacent pixel location. Repeat Step 2 until end of the image 47 Histogram Processing (cont.) Example Enhancement using local histograms Original image Result of local Result of global histogram equalization histogram equalization 48 Histogram Processing (cont.) Enhancement using local histograms 49 Use of Histogram Statistics for Image Enhancement The global mean and variance The mean is a measure of average gray level in an image The variance is a measure of average contrast in an image. Let r denote discrete gray-levels in the range r [0, L 1] p(ri) denote the normalized histogram component corresponding to the ith value of r. The nth moment of r is defined as L 1 n (r ) ri mn p(ri ) i 0 where m is the mean value of r L 1 m ri p(ri ) i 0 50 Use of Histogram Statistics for Image Enhancement 根據前面二式 0=1, 1=0 The second moment is obtained by L 1 2 (r ) ri m 2 p(ri ) i 0 2 (r ) 上式為r的variance。 Standard deviation定義為variance的平方根(square root) 。 The global mean and variance are measured over an entire image and are useful primarily gross adjustments of overall intensity and contrast. 51 Histogram Statistics for Image Enhancement The local mean and variance The local mean is a measure of average gray level in neighborhood Sxy The variance is a measure of contrast in the neighborhood mS xy 2 S xy rs,t p(rs,t ) ( s ,t )S xy r ( s ,t )S xy s ,t mS xy p(r 2 s ,t ) 52 Histogram Processing (cont.) Example 鎢絲1(清楚) 鎢絲2(不清楚) 53 Histogram Processing (cont.) The problem is to enhance dark areas while leaving the light area as unchanged as possible. Consider the pixel as a point (x,y) as a candidate for processing (1) if mS xy k0 M G (2) if S xy k 2 DG (3) if k1DG S xy , k1 k 2 MG: global mean DG: global standard deviation k0 : positive constant <1.0 k1: < 10 k2: > 1.0 Thus E f ( x, y ) if (mS xy k0 M G )( S xy k 2 DG ) (k1DG S xy ), k1 k 2 g ( x, y ) otherwise f ( x, y ) 54 Histogram Processing (cont.) 對影像取local mean average 對影像取local standard deviation 三個條件判別 後的結果 白色部分為 E,用來對 原影像相乘, 以得到強化 的結果。 採用3x3 local region 55 Histogram Processing (cont.) 56 Enhancement using Arithmetic/Logic Operations Enhancement using Arithmetic/Logic Operations Arithmetic/Logic operations are performed on a pixel-by-pixel basis. Arithmetic operations: subtraction, addition, division, multiplication. Logic operations: AND, OR, NOT When dealing with logic operations on grayscale images, pixel values are processed as strings of binary numbers. 57 Enhancement using Arithmetic/Logic Operations (cont.) 58 Enhancement using Arithmetic/Logic Operations (cont.) 59 Enhancement using Arithmetic/Logic Operations (cont.) Image Subtraction The enhancement of difference between images The difference between two images f(x,y) and h(x,y) g ( x, y) f ( x, y) h( x, y) 60 Enhancement using Arithmetic/Logic Operations (cont.) Most images are displayed using 8 bits. Thus, we expect image values not to be outside the range from 0 to 255. The value in a difference image can range from a minimum of -255 to a maximum of 255. How to solve this problem? Solution 1: g’(x,y)=[g(x,y)+255]/2 Solution 2: g’(x,y)=g(x.y)-min(g(x,y)) g’’(x,y)=[g’(x,y)*255]/max(g’(x,y)) 61 Enhancement using Arithmetic Operations (cont.) Image averaging Noisy image g(x,y) formed by the addition of noise h(x,y) to an original image f(x,y) g ( x, y) f ( x, y) h ( x, y) Assume that at every pair of coordinates (x,y) the noise is uncorrelated and has zero average value. Averaging K different noisy images To reduce the noise content by adding a set of noisy images The standard deviation at any point in the average image is 1 K g ( x, y) g i ( x, y) K i 1 g ( x, y ) 1 h ( x, y) K As K increases, Eq(3.4-6) indicates that the noise of the pixel values at each location (x,y) decreases. 62 Enhancement using Arithmetic/Logic Operations (cont.) Example 3.8 Noise reduction by image averaging The images gi(x,y) must be registered in order to avoid the introduction of blurring and other artifacts. (a) Image of Galaxy pair NGC 3314. (b) Image corrupted by additive Gaussian noise with zero mean and a standard deviation of 64 gray levels. (c-f) Result of averaging K=8, 16, 64 and 128 noisy images. 63 Enhancement using Arithmetic/Logic Operations (cont.) In the histograms, the mean and standard deviation of the difference images decrease as K increases. 64 Reference Rafael C. Gonzalez and Richard E. Woods, Digital Image Processing (2nd, 3rd Edition) Atam P. Dhawan, Medical Image Analysis, Wiley Interscience, 2003. 65
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
advertisement