1、Digital Image ProcessingChapter 3:Image Enhancement in the Spatial Domain15 June 2007What is spatial domain The space where all pixels form an image In spatial domain we can represent an image by f(x,y)where x and y are coordinates along x and y axis with respect to an origin There is duality betwee
2、n Spatial and Frequency DomainsImages in the spatial domain are pictures in the xy planewhere the word“distance”is meaningful.Using the Fourier transform,the word“distance”is lost but the word“frequency”becomes alive.Image Enhancement means improvement of images to be suitable for specific applicati
3、ons.Example:Note:each image enhancement technique that is suitable for one application may not be suitable for other applications.(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Original imageEnhanced image using Gamma correction(Images from Rafael C.Gonzalez a
4、nd Richard E.Wood,Digital Image Processing,2nd Edition.=Image enhancement using processes performed in the Spatial domain resulting in images in the Spatial domain.We can written as(,)(,)g x yT f x ywhere f(x,y)is an original image,g(x,y)is an output and T is a function defined in the area around(x,
5、y)Note:T may have one input as a pixel value at(x,y)only ormultiple inputs as pixels in neighbors of(x,y)depending in each function.Ex.Contrast enhancement uses a pixel value at(x,y)only for an input while smoothing filte use several pixels around(x,y)as inputs.-Single pixel methods-Gray level trans
6、formations Example-Historgram equalization-Contrast stretching-Arithmetic/logic operations Examples-Image subtraction-Image averaging-Multiple pixel methodsExamplesSpatial filtering-Smoothing filters-Sharpening filtersTransforms intensity of an original image into intensity of an output image using
7、a function:()sT rwhere r=input intensity and s=output intensityExample:Contrast enhancement(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.WhiteBlackInput intensityOutput intensityOriginaldigitalmammogram1sLr L=the number of gray levels 0L-1L-1Negativedigitalma
8、mmogram(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.BlackWhiteFourierspectrumLog Tr.ofFourierspectrumlog(1)scrApplication(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.scr(Images from Rafael C.Gonzalez and Richard E.Wo
9、od,Digital Image Processing,2nd Edition.Desired imageImage displayed atMonitorAfterGammacorrection(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Image displayed atMonitorMRI Image after Gamma Correction(Images from Rafael C.Gonzalez and Richard E.Wood,Digital
10、Image Processing,2nd Edition.Ariel imagesafter GammaCorrection(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Before contrast enhancementAfter Contrast means the difference between the brightest and darkest intensities(Images from Rafael C.Gonzalez and Richard
11、E.Wood,Digital Image Processing,2nd Edition.Notice the slope of T(r)-if Slope 1 Contrast increases-if Slope 1 Contrast decrease-if Slope=1 no changeDrDsSmaller Dr yields wider Ds=increasing Contrast(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.(Images from Ra
12、fael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Bit 7Bit 6Bit 2Bit 1Bit 5Bit 3(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Histogram=Graph of population frequencies Grades of the course 178 xxx()kkh rn pixel pixel=graph of no.of pixel
13、s vs intensities(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Bright image has histogram on the rightDark image has histogram on the leftlow contrast image has narrow histogram(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edit
14、ion.high contrast image has wide histogram =intensity transformation based on histogram information to yield desired histogram-Histogram equalization-Histogram matchingTo make histogram distributed uniformlyTo make histogram as the desire=Function that is only increasing or constant)(rTs Properties
15、of Histogram processing function1.Monotonically increasing function2.10for 1)(0rrTand relation between s and r isHistogram is analogous to Probability Density Function(PDF)which represent density of populationLet s and r be Random variables with PDF ps(s)and pr(r)respectively)(rTs We getdsdrrpsprs)(
16、)(rrdwwprTs0)()(LetWe get1)(1)()(1)(1)()()(0rprpdrdwwpdrpdrdsrpdsdrrpsprrrrrrrs!Formula in the previous slide is for a continuous PDFFor Histogram of Digital Image,we usekjjkjjrkkNnrprTs00 )()(nj=the number of pixels with intensity=jN=the number of total pixelsIntensity#pixels0201522531041555610710T
17、otal100Accumulative Sum of Pr20/100=0.2(20+5)/100=0.25(20+5+25)/100=0.5(20+5+25+10)/100=0.6(20+5+25+10+15)/100=0.75(20+5+25+10+15+5)/100=0.8(20+5+25+10+15+5+10)/100=0.9(20+5+25+10+15+5+10+10)/100=1.01.0Intensity(r)No.of Pixels(nj)Acc Sum of PrOutput valueQuantized Output(s)0200.20.2x7=1.41150.250.25
18、*7=1.7522250.50.5*7=3.533100.60.6*7=4.244150.750.75*7=5.255550.80.8*7=5.666100.90.9*7=6.367101.01.0 x7=77Total100(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.(Images from
19、Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.OriginalimageAfter histogram equalization,the imagebecome a low contrast image(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Ima
20、ge Processing,2nd Edition.rrdwwprTs0)()(Concept:from Histogram equalization,we haveWe get ps(s)=1We want an output image to have PDF pz(z)Apply histogram equalization to pz(z),we getzzduupzGv0)()(We get pv(v)=1Since ps(s)=pv(v)=1 therefore s and v are equivalentTherefore,we can transform r to z by r
21、T()sG-1()zTo transform image histogram to be a desired histograms=T(r)v=G(z)z=G-1(v)1234(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Intensity(s)#pixels0201522531041555610710Total100Input imagehistogramIntensity(z)#pixels0511021532042051561075Total100Desired
22、 HistogramExampleUser defineOriginaldatar(nj)SPrs0200.21150.2522250.533100.644150.755550.866100.967101.071.Apply Histogram Equalization to both tablesz(nj)SPzv050.0501100.1512150.323200.544200.755150.8566100.957751.07sk=T(rk)vk=G(zk)rs01122334455666772.Get a mapvz0011224354657677sk=T(rk)zk=G-1(vk)r
23、sv zs vWe getr z0112223344556576z#Pixels0012023031041551561070 Actual Output HistogramDesired histogramTransfer functionActual histogram(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.OriginalimageAfterhistogram equalizationAfterhistogram matchingConcept:Perfor
24、m histogram equalization in a small neighborhoodOrignal imageAfter Hist Eq.After Local Hist Eq.In 7x7 neighborhood(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.We can use statistic parameters such as Mean,Variance of Local area for image enhancementImage of t
25、ungsten filament taken usingAn electron microscopeIn the lower right corner,there is afilament in the background which isvery dark and we want this to be brighter.We cannot increase the brightness of the whole image since the white filament will be too bright.(Images from Rafael C.Gonzalez and Richa
26、rd E.Wood,Digital Image Processing,2nd Edition.Example:Local enhancement for this task otherwise ),(and when),(),(210yxfMkDkMkmyxfEyxgGsGGsxyxyOriginal imageLocal Varianceimage Multiplicationfactor(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Output image(Ima
27、ges from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.ANDORResult Region of InterestImage maskOriginalimageApplication:Crop areas of interest(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Error imageApplication:Error measurement(Im
28、ages from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Application:Mask mode radiography in angiography work(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Application:Noise reduction),(),(1yxyxgKAveraging results in reduction of No
29、ise variance),(),(),(yxyxfyxgDegraded image(noise)Image averagingKiiyxgKyxg1),(1),(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.Sometime we need to manipulate values obtain
30、ed from neighboring pixelsExample:How can we compute an average value of pixelsin a 3x3 region center at a pixel z?446761922275226445212133429577358222Pixel zImage446761922275226445212133429577358222Pixel zStep 1.Selected only needed pixels467691334467691334Step 2.Multiply every pixel by 1/9 and the
31、n sum up the values191691391 691791991 491491391y11111111191XMask orWindow orTemplateQuestion:How to compute the 3x3 average values at every pixels?446761922275226445212133429577Solution:Imagine that we havea 3x3 window that can be placedeverywhere on the imageMasking Window4.3Step 1:Move the window
32、 to the first location where we want to compute the average value and then select only pixels inside the window.446761922275226445212133429577Step 2:Computethe average value3131),(91ijjipySub image pOriginal image419223297Output imageStep 3:Place theresult at the pixelin the output image Step 4:Move
33、 the window to the next location and go to Step 2 The 3x3 averaging method is one example of the mask operation or Spatial filtering.w The mask operation has the corresponding mask(sometimes called window or template).w The mask contains coefficients to be multiplied with pixelvalues.w(2,1)w(3,1)w(3
34、,3)w(2,2)w(3,2)w(3,2)w(1,1)w(1,2)w(3,1)Mask coefficients11111111191Example:moving averaging The mask of the 3x3 moving average filter has all coefficients=1/9The mask operation at each point is performed by:1.Move the reference point(center)of mask to the location to be computed 2.Compute sum of pro
35、ducts between mask coefficients and pixels in subimage under the mask.p(2,1)p(3,2)p(2,2)p(2,3)p(2,1)p(3,3)p(1,1)p(1,3)p(3,1)Subimagew(2,1)w(3,1)w(3,3)w(2,2)w(3,2)w(3,2)w(1,1)w(1,2)w(3,1)Mask coefficientsNiMjjipjiwy11),(),(Mask frameThe reference pointof the maskThe spatial filtering on the whole ima
36、ge is given by:1.Move the mask over the image at each location.2.Compute sum of products between the mask coefficeintsand pixels inside subimage under the mask.3.Store the results at the corresponding pixels of the output image.4.Move the mask to the next location and go to step 2until all pixel loc
37、ations have been used.Examples of Spatial Filtering MasksExamples of the masksSobel operators011002-1-2-1-2-11020-101xP compute toyP compute to111111111913x3 moving average filter-1-1-18-1-1-1-1-1913x3 sharpening filterApplication:noise reductionand image smoothingDisadvantage:lose sharp details(Ima
38、ges from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.subimageOriginal imageMoving windowStatistic parametersMean,Median,Mode,Min,Max,Etc.Output image(Images from Rafael C.Gonzalez and
39、 Richard E.Wood,Digital Image Processing,2nd Edition.There are intensity discontinuities near object edges in an image(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.2040608010012014016018020000.5105010015020000.10.2050100150200-0.0500.05Intensity profile1st de
40、rivative2nd derivativep(x)dxdp22dxpdEdge050100150200-0.500.511.5050100150200-0.500.511.52210)(dxpdxp Laplacian sharpening results in larger intensity discontinuity near the edge.p(x)2210)(dxpdxpp(x)Before sharpeningAfter sharpening-1-1-18-1-1-1-1-1-1004-1-10-10111-811111100-411010Application:Enhance
41、 edge,line,pointDisadvantage:Enhance noiseUsed for estimating image Laplacian22222yPxPPorThe center of the mask is positiveThe center of the mask is negativepP2P2PP2(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.PP2Mask for1 11-811111-1-1-19-1-1-1-1-1-1 005-1-
42、10-101 00-411010orMask forP2or(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.-1-1-1k+8-1-1-1-1-1-100k+4-1-10-10Equation:),(),(),(),(),(22yxPyxkPyxPyxkPyxPhbThe center of the mask is negativeThe center of the mask is positive(Images from Rafael C.Gonzalez and R
43、ichard E.Wood,Digital Image Processing,2nd Edition.2040608010012014016018020000.51050100150200-0.200.205010015020000.10.2Intensity profile1st derivative2nd derivativep(x)dxdpdxdpEdgesSobel operators011002-1-2-1-2-11020-101xP compute toyP compute toPxPyP22yPxPPGradient magnitudeA gradient image empha
44、sizes edges(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.PxPyPPMix things up!+-AP2SharpeningPsmoothBECD(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.ECMultiplicationFMix things up!ASGHPowerLaw Tr.(Images from Rafael C.Gonzalez and Richard E.Wood,Digital Image Processing,2nd Edition.祝您成功!