Image Processing - Philadelphia University

Transcription

Image ProcessingChapter(3)Part 2:Intensity Transformation andspatial filtersPrepared by: Hanan HardanHanan Hardan1

Image Enhancement? Enhancement تحسين الصورة : is to process an image so that the result is more suitable than theoriginal image for a specific application.Enhancement techniques are so varied, and useso many different image processing approachesThe idea behind enhancement techniques is tobring out details that are hidden, or simple tohighlight certain features of interest in an image.Hanan Hardan2

Image Enhancement?If we used 256 intensities of grayscale then:- In dark image the most of pixels value 128- In bright image the most of pixels value 128Let x:old imageS:new imageS x c where c is constant value S imadd(x,50); -----------------brighter imageS x-c where c is constant value S imsubtract(x,50); -------------darker image We can add 2 image :S x y (where x and y 2 image have same size) Hanan Hardan3

Image Enhancement Methods Spatial Domain Methods (Image Plane)Techniques are based on direct manipulation ofpixels in an imageFrequency Domain MethodsTechniques are based on modifying the Fouriertransform of the image.Combination MethodsThere are some enhancement techniques based onvarious combinations of methods from the first twocategories In this chapter, we are going to discuss spatialdomain techniquesHanan Hardan4

Spatial domain Spatial domain processes:1.intensity transformation(Point operation)- g depends only on the value of f at(x,y)spatial filter (or mask ,kernel, template orwindow)1.Hanan Hardan5

Intensity (Gray-level)transformationsfunctions Here, T is called intensity transformation function or (mapping,gray level function)g(x,y) T[f(x,y)]srs T(r)s,r : denote the intensity of g and f at any point (x,y) .In addition, T can operate on a set of input imagesHanan Hardan6

Intensity transformations functionsIntensity transformation functions fall into 2 approaches:1) Basic intensity transformations Linear Functions:- Negative Transformation- Identity Transformation Logarithmic Functions:- Log Transformation- Inverse-log Transformation Power-Law Functions:- nth power transformation- nth root transformationHanan Hardan7

Intensity transformations functions2) piecewise Linear transformation functions.a) Contrast stretching, thresholdingb) Gray-level slicingc) Bit-plane slicingHanan Hardan8

Basic intensity transformationsa) Linear ( negative and identity).b) logarithmic ( Log and Inverse Log) .c) Power( nth power and nth root). بالصورة بعد التعديل gray levels التدرجات اللونية 256 سيكون هناك 8 bit ان كان في البكسل , فمثال )L 256( تدرج Hanan Hardan بالصورة قبل التعديل gray levels التدرجات اللونية 9

Identity Function- Output intensities are identical to inputintensities- This function doesn’t have an effect on animage, it was included in the graph only forcompleteness- Its expression:s rHanan Hardan10

Image Negatives (Negative Transformation)The negative of an image with gray level in the range[0, L-1], where L Largest value in an image, isobtained by using the negative transformation’sexpression:s L–1–rWhich reverses the intensity levels of an inputimage , in this manner produces the equivalent of aphotographic negative.The negative transformation is suitable for enhancingwhite or gray detail embedded in dark regions of animage, especially when the black area are dominantin size11Hanan Hardan

Output gray levelImage Negatives (Negative Transformation)s L–1–rInput gray levelHanan Hardan12

Image Negatives (Negative Transformation)Image (r(Image (s ( after applying T (negative)Advantages of negative : Produces an equivalent of a photographic negative. Enhances white or gray detail embedded in dark regions.Hanan Hardan13

Image Negatives (Negative Transformation)Note how much clearer the tissue is in the negative imageHanan Hardan14

Image Negatives (Negative Transformation)Example 1:the following matrix represents the pixels values ofan 8-bit image (r) , apply negative transform andfind the resulting image pixel values.solution:L 28 256s L-1-rs 255-rApply this transform toeach pixel to find the negativeHanan HardanImage (r)1001109095981401451358990888510210599115Image 015

Image Negatives (Negative Transformation)Exercise:the following matrix represents the pixels values of a5-bit image (r) , apply negative transform and find Image (r)2126the resulting image pixel values.solution:Image (s)Hanan Hardan293019212030161626311918272316

Image Negatives (Negative Transformation)The negative of an image can be obtained also with IPTfunction imcomplement:g imcomplement (f);Hanan Hardan17

Log Transformations functionThe general form of the log transformation:s c log (1 r)Where c is a constant, and r 0 Log curve maps a narrow range of low gray-level valuesin the input image into a wider range of the outputlevels. Used to expand the values of dark pixels in an imagewhile compressing the higher-level values. It compresses the dynamic range of images with largevariations in pixel values. Log functions are particularly useful when the input greylevel values may have an extremely large range ofvaluesHanan Hardan18

Log Transformations function Logarithmic transformations are implemented using theexpression:g c * log (1 double (f))Hanan Hardan19

Log Transformations function But this function changes the data class of the image todouble, so another sentence to return it back to uint8should be done:gs im2uint8 (mat2gray(g)); Use of mat2gray brings the values to the range [0 1] andim2uint8 brings them to the range [0 255]Hanan Hardan20

Log Transformations function Example: g log(1 double(f)); gs im2uint8(mat2gray(g)); imshow(f), figure, imshow (g), figure, imshow(gs);fgHanan Hardangs21

Inverse Logarithm Transformation Do opposite to the log transformationsUsed to expand the values of high pixels inan image while compressing the darker-levelvalues.Hanan Hardan22

Logarithmic TransformationsInvLogLogHanan Hardan23

Power-Law Transformations Power-law(Gamma) transformationshave the basic form of:s c.rᵞWhere c and ᵞ are positive constants Mapa narrow range of dark inputvalues into a wider range of outputvalues or vice versaHanan Hardan24

Power-Law Transformations Different transformation curves areobtained by varying ᵞ (gamma)Hanan Hardan25

Power-Law TransformationsIf gamma 1 :the mapping is weightedtoward brighter output values. If gamma 1 (default):the mapping islinear. If gamma 1 :the mapping is weightedtoward darker output values. Hanan Hardan26

Power Law ExampleHanan Hardan27

Power Law ExampleHanan Hardan28

Power Law ExampleHanan Hardan29

Power Law ExampleHanan Hardan30

Power Law Example The images to the rightshow a magnetic resonance(MR) image of a fracturedhuman spine Different curves highlightdifferent detailHanan Hardan31

Power Law ExampleHanan Hardan32

Function imadjust Function imadjust is the basic IPT tool forintensity transformations of gray-scaleimages. It has the syntax:g imadjust (f, [low in high in], [low out high out], gamma)Hanan Hardan33

Function imadjust As illustrated in figure 3.2 (above), this function maps theintensity values in image f to new values in g, such thatvalues between low in and high in map to valuesbetween low out and high out.Values below low in and above high in are clipped; thatis values below low in map to low out, and those abovehigh in map to high out.Hanan Hardan34

Function imadjust The input image can be of class uint8, uint16, or double,and the output image has the same class as the input. All inputs to function imadjust, other than f, are specifiedas values between 0 and 1, regardless of the class of f. If fis of class uint8, imadjust multiplies the value supplied by255 to determine the actual values to use; if f is of classuint16, the values are multiplied by 65535. Using the empty matrix ([ ]) for [low in high in] of for[low out high out] results in the default values [0 1]. If high out is less than low out, the output intensity isreversed.Hanan Hardan35

Function imadjust Parameter gamma specifies the shape of the curve thatmaps the intensity values of f to create g. If gamma isless than 1, the mapping is weighted toward higher(brighter) output values, as fig 3.2 (a) shows. If gamma isgreater than 1, the mapping is weighted toward lower(darker) output values. If it is omitted from the functionarguments, gamma defaults to 1 (linear mapping).Hanan Hardan36

Function imadjust Example1: f imread ('baby-BW.jpg'); g imadjust (f, [0 1], [1 0]); imshow(f), figure, imshow (g); imshow(f), figure, imshow (g);This Obtaining the negative imagefHanan Hardang37

Function imadjust Example2: g imadjust (f, [0.5 0.75], [0 1], .5); imshow(f), figure, imshow (g);fgHanan Hardan38

Function imadjust Example3: g imadjust (f, [0.5 0.75], [0.6 1], 0.5); imshow(f), figure, imshow (g);fgHanan Hardan39

Function imadjust Example4: g imadjust (f, [ ], [ ], 2); imshow(f), figure, imshow (g);fgHanan Hardan40

Piecewise-Linear Transformation FunctionsPrinciple Advantage: Some importanttransformations can be formulated only as apiecewise function. Principle Disadvantage: Their specificationrequires more user input that previoustransformations Types of Piecewise transformations are: Contrast StretchingGray-level SlicingBit-plane slicingHanan Hardan41

Contrast StretchingOne of the simplest piecewise linearfunctions is a contrast-stretchingtransformation, which is used to enhancethe low contrast images. Low contrast images may result from: Poor illuminationWrong setting of lens aperture during imageacquisition.Hanan Hardan42

Contrast StretchingIf T(r) has the form as shown in the figure below,the effect of applying the transformation to everypixel of f to generate the corresponding pixels in gwould:Produce higher contrast than the originalimage, by: Darkening the levels below m in the originalimage Brightening the levels above m in theoriginal imageSo, Contrast Stretching: is a simple imageenhancement technique that improves thecontrast in an image by ‘stretching’ the range ofHanan Hardanintensity values it containsto span a desiredrange of values.43

Contrast Stretching(r2, s2)(r1, s1)Contrast stretchingAssume thata: rmin,b:rmax,Contrast stretching:(r1,s1) (rmin,0) , (r2,s2) (rmax,L-1)Hanan Hardan44

Contrast Stretching Example: in the graph, suppose we have the Remember that:g(x,y) T[f(x,y)]following intensities : a 90, b 180, m 100Or if r is above 180 ,it becomes 255 in s.s T(r) If r is below 90 , it becomes 0, If r is between 90, 180 , T applies as follows:Pixels above 180 become 255when r 100 , s closes تقترب to zero (darker)when r 100 , s closes to 255 (brighter)255brighterT If r 180; s 255If r 180 and r 90; s T(r)If r 90; s 0darker0Pixels less than 90 become 0255This is called contrast stretching, which means thatthe bright pixels in the image will become brighterand the dark pixels will become darker, this means :45Hanan Hardanhigher contrast image.

Contrast-Stretching Transformation The function takes the form of:Where r represents the intensities of the inputimage, s the corresponding intensity values inthe output image, and E controls the slope ofthe function.Hanan Hardan46

Contrast StretchingImage (r(Image (s ( after applying T(contrast stretching)Notice that the intensity transformation function T,made the pixels with dark intensities darker and thebright ones even more brighter,this is calledHanan Hardancontrast stretching 47

Contrast-Stretching Transformation This equation is implemented in MATLAB for theentire image asNote the use of eps to prevent overflow if f hasany 0 values.Hanan Hardan48

Contrast-Stretching TransformationExample1: g 1 ./ (1 (100 ./(double(f) eps)) . 20); imshow(f), figure, imshow(g); Hanan Hardan49

Contrast-Stretching TransformationExample2: g 1 ./ (1 (50 ./(double(f) eps)) . 20); imshow(f), figure, imshow(g); Hanan Hardan50

Contrast-Stretching TransformationExample3: g 1 ./ (1 (150 ./(double(f) eps)) . 20); imshow(f), figure, imshow(g); Hanan Hardan51

ThresholdingIs a limited case of contrast stretching, it produces a twolevel (binary) image.Some fairly simple, yet powerful, processing approachescan be formulated with grey-level transformations. Becauseenhancement at any point in an image depends only on thegray level at that point, techniques in this category oftenare referred to as point processing.52Hanan Hardan

ThresholdingAssume thata: rmin,b:rmax,k : intensity(r2, s2)Contrast stretching:(r1,s1) (rmin,0) , (r2,s2) (rmax,L-1)Thresholding:(r1,s1) (k,0) , (r2,s2) (k,L-1)(r1, s1)Thresholding:Hanan Hardan53

Thresholding Remember that: Example: suppose m 150 (called threshold),g(x,y) T[f(x,y)]Ors T(r)Pixels above 150 become 1if r (or pixel intensity in image f ) الصورة االصلية isabove this threshold it becomes 1 in s (or pixelintensity in image g ) الصورة بعد التعديل , otherwise itbecomes zero.255T If f(x,y) 150; g(x,y) 1If f(x,y) 150; g(x,y) 0Or simply 0Pixels less than 150 become 0255If r 150; s 1Hanan HardanIf r 150; s 0T This is calledthresholding,and it producesa binary image!54

ThresholdingImage (r (Image (s ( after applying T(Thresholding)Notice that the intensity transformation function T, convert thepixels with dark intensities into black and the bright pixels intowhite. Pixels above threshold is considered bright and below it is55Hanan Hardanconsidered dark, and this processis called thresholding.

Contrast StretchingHanan Hardan56

Application on Contrast stretching and thresholding8-bit image with low contrastAfter contrast stretching(r1,s1) (rmin,0) , (r2,s2) (rmax,L-1)Thresholding function(r1,s1) (m,0) , (r2,s2) (m,L-1)m : meanHananintensitylevel in the imageHardan57

Contrast Stretching Figure 3.10(a) shows a typical transformation used forcontrast stretching. The locations of points (r1, s1) and (r2,s2) control the shape of the transformation function.If r1 s1 and r2 s2, the transformation is a linearfunction that produces no changes in gray levels.If r1 r2, s1 0 and s2 L-1, the transformationbecomes a thresholding function that creates a binaryimage.Intermediate values of (r1, s1) and (r2, s2) producevarious degrees of spread in the gray levels of the outputimage, thus affecting its contrast.In general, r1 r2 and s1 s2 is assumed, so the functionis always increasing.Hanan Hardan58

Contrast Stretching Figure 3.10(b) shows an 8-bit image with low contrast. Fig. 3.10(c) shows the result of contrast stretching,obtained by setting (r1, s1) (rmin, 0) and (r2, s2) (rmax,L-1) where rmin and rmax denote the minimum andmaximum gray levels in the image, respectively. Thus, thetransformation function stretched the levels linearly fromtheir original range to the full range [0, L-1]. Finally, Fig. 3.10(d) shows the result of using thethresholding function defined previously, with r1 r2 m,the mean gray level in the image.Hanan Hardan59

piecewise Linear transformation functions.Exercise:the following matrix represents the pixels values of a 8-bit image(r) , apply thresholding transform assuming that the thresholdm 95, find the resulting image pixel values.Image (r)solution:Image (s)Hanan Hardan110120901309194982009091991008296859060

solution in matlab:function a2(x,s)y x;[m n] size(x);for i 1:mfor j 1:nif x(i,j) sy(i,j) 255;else y(i,j) 0;endendendfigure, imshow(x);figure, imshow(y);Hanan Hardan61

Image Negatives (Negative Transformation) The negative of an image with gray level in the range [0, L-1], where L Largest value in an image, is obtained by using the negative transformation's expression: s L - 1 - r Which reverses the intensity levels of an input image , in this manner produces the equivalent of a photographic negative.