0% found this document useful (0 votes)
84 views45 pages

DIP U 2 Enhancement Notes

Digital image processing unit 2 notes

Uploaded by

Mini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
84 views45 pages

DIP U 2 Enhancement Notes

Digital image processing unit 2 notes

Uploaded by

Mini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 45
Fig, 4.1 4.2 _ Spatial Domain Methods : ce ‘The term spatial domain means working in the gi implies working with the pixel values or in other words, {at fx) be the orginal image where fis the grey level 3 oordinates. For a 8-bit image, f can take values from 0 - 255 where 0 “Spasents whit an ll he intermediate values represent shades of rey. Fie de 822256 % 256, andy can take values fom (0,0) 0 (255, 255) as sho in the Fig. 42 4 3 this case, the image | tly with the raw data (x, y) are the im Tepresents black. > ‘The modified image can be expressed as 80% 9) = T[fkx, y] Here f(x, y) is the original image and T is the transfo modified image g(x, y). For all spatial domain techniques t¢ general equation remains the same, J To summarize, spatial domain techniques are those, which values to get a new image based on Equation (4.1) Spatial domain enhancement can be carried out in two different (1) Point processing ; (2) Neighbourhood processing Enhancement In SF = Digital Image Processing (PU) 4-5 Image MATLAB program for finding the digital negative —__. ~~ %% MATLAB code to calculate negative %% clear all cle iaa=imread (‘satum.tif’); la-double (aa) lc - % for a 8-bit image % b=c-a; figure(1) colormap(gray) imagesc(a) figure(2) colormap(gray) |imagese(b) Q) (a) Original image (b) Digital negative Fig. 46 Contrast stretching : Many times we obtain low contrast images due to poor illuminations or due to wrong setting of the lens aperture. The idea behind contrast stretching is to increase the contrast of the images by making the dark portions darker and the bright portions brighter. Fig, 4.7 shows the transformation used to achieve contrast stretching. In the Fig. 4.7, the dotted line indicates the identity transformation and the solid line is the contrast stretching transformation. As is evident from the Fig. 4.7, we make the dark grey levels darker by assigning a slope of less than one and make the bright grey levels brighter by assigning a slope greater than one. One can assign different slopes depending on the input image and the application. As was mentioned, image enhancement is a subjective technique and hence there is no one set of slope values that would yield the desired result Where /, m and n are the slopes, It is ¢ while m is greater than one. The contrast range of the modified image. Contrast Slopes taken alll; 4 cle; * a=imread(“xray] tif’) ' coll=sizelay, UT = input(“Enter the upper for x=1:1:row for y=1:L:col ifa(xy)<-LT ; B(x yH0.5talxy); else if a(x,y)<=UT )=2' else b(x,y)=0.5" od = MATLAB program for contrast 7 oe 50))&&(21i,j)<150) 2(i,j=255, else 2i,j)=pid: end end end figure (1); _., __-- grey level slicing with background figure (2); i imshow yint8(Z))_ = —_—— %p----- original image 6) (b) Grey level slicing with background Fig. 4.13 Bit plane slicing : In this technique, we find out the contribution made by each bit to the final image. As mentioned earlier, an image is defined as say a 256 x 256 x 8 image In this, 256 x 256 is the number of pixels present in the image and 8 is the number of bits required to represent each pixel. 8-bits simply means 28 or 256 grey levels. Now cach pixel will be represented by 8-bits. For example black is represented as 00000000 and white is represented as 11111111 and between them, 254 grey levels are accomodated. In bit plane slicing, we see the importance of each bit in the final image This can be done as follows. Consider the LSB value of each pixel and plot the image using only the LSBs. Continue doing this for cach bit till we come to the MSB. Note that we will get 8 different images and all the 8 images will be binary E41: Given a3 x3 image, plot its bit planes. 1 2 O 4 3 7 5 2 Soin. : Since 7 is the maximum grey level, we need only 3-bits to represent the grey levels Hence we will have 3-bit planes. Converting the image to binary we get, es a 001 | O10 | 000 1 0 0 0 I 0 0 100 | 011 | 010 0 1 0 | | P|. | Mt 111} 101 | O10 1 1 0 1 0 I 1 Binary image LSB plane Middle bit plane MSB plane BEI Digital im (6) Workers of the World, Unite Lenin (©) Stego image (d) Retrieved data Fig, 4.16 Dynamic range compression (Log transformation) : At times, the dynamic range of the image exceeds the capability of the display device. What happens is that some pixe| values are so large that the other low value pixels get obscured. A simple day-to-day example of such a phenomena is that during daytime, we cannot see the stars. The reason behind this is that the intensity of the sun is so large and that of the Stars is so low that the eye cannot adjust to such a large dynamic Tange. In image Processing, a classic example of such large differences i spectrum (will be discussed in detail in the frequency In the Fourier spectrum only some of the values are very large while Most of the values are foo small. The dynamic range of pixels is of the order of 10°. Hence, when Biriot the Fourier spectrum, we see only small dots, which represent the large Shis . values as well. Th _ compressing the dynamic range is known as dynamic This technique of that the log operator is an excellent compressing fu : compression is achieved by using a log operator. Cis the norma sation dynamic range si Oxlog (1 +[r)) Fig. 4.17 MATLAB program for dynamic range compression %% Dynamic range compression %% clear all cle aa=imread(‘saturn.tif); a=double(aa) : [row,col]=size(a); for x=1:1:row for y=1:1:col o(x.y=a(x.y)*((-1) (x+y); %% Needed to center the transform end end d=abs(fR2(c)); d_log=log(1+d); '%%% Plotting figure(1) colormap(gray) imagesc(d) figure(2) colormap(gray) imagesc(d_log) (a) (b) Fig, 4.18 : Dynamic range compression (7) Power law transformation : The basic formula for power-law transformation is a(x, y) = x fix, yy It can also be written as s= cr (4.8) Here ¢ and y are positive constants. The transformation is shown below for different tor, We observe that by changing the values of y which is also called the gamma correction fe Value of gamma, we obtain a family of transformation curves. aise \cemnent in Spatial Domain Fig. 4.20 44 Neighbourhood Processing : This, as mentioned before, is also a spatial domain technique in image enhancement Unlike ‘the Point processing techniques where we consider one pixel at a time and modify it depending on our requirement, here we not only consider a pixel but also its immediate neighbours. Tocut a long story short, we change the value of the pixel f(x, y) based on the values of ‘#58 neighbours as shown in Fig. 4.21. Instead of a 3 x 3 neighbourhood, we could also use a $x5ora7 x 7... neighbourhood. 7-3 y y+t y > x-1 fx -1,y) |f(« -1,y+1) wi we ws fx,y+1) ye wa ws we +1,y-1)] testy) | ix+1,y+1) {+———— w7 we wo A3 x 3 neighbourhood Fig. 4.21: A 3 3 neighbourhood Fig, 4.22 : 3x 3. mask ‘There are a lot of things that can be achieved by neighbourhood processing which are le with point processing, Fig. 4.22 shown is called a mask or a window or a . To achieve neighbourhood processing, we place this 3 x 3 (it could also be a5 x 5 or 7...) mask on the image, multiply cach component of the mask with the corresponding ‘Of the image, add them up and place the value that we get, at the center. image Enhancement FE digital mage Processing (PU) This operation is the same as convolution. Remember convolution ? Of the ; wwe take one, flip it and then move it across the other signal step By step The same }, done here. We don’t need to flip the mask as it is symmetric. If Fis the original image and g is the modified image, then a(x, y) = fle — 1, y= 1) x wl + fx = 1, y) x w2 + fx xw4 + fix, y) xwS +... + fx tly +1) x wo 4 oo ae =1, yt 1) x w3 + fix, we Fig. 4.23 Once g(x. y) is calculated, we shift the mask by one step towards the right to the ». 1 pixel Now w3 coincides with f(x, y + 1). One of the important operations that can be ac’ using acighbourhood processing is that of image filtering. We can perform low pass, hizh pa: and band pass filtering using neighbourhood operations. Before explaining the procedur: performing filtering on images, it is imperative to understand what we mean by frequencies as image !! We are all well versed with frequencies in I-dimensional signals ee signals, we can casily distinguish between the lower frequency si highe ICNCy Sis enc signal. Refer Fig. 4.23 eo Low frequency region High frequency region Low frequency region Fig. 4.24 We can conclude that the lower signal is of a much higher frequeney, by number of oscillations. That is, higher the frequency, greater are the number of ose If the two signals represent voltages, then, how fast the voltages change is an indicati, is frequency. The same concepts can be applied to images. In images, instead of have grey levels. If the grey levels change slowly over a region, itis considered t0 hays frequency, whereas, if the grey levels change very rapidly, that region is considered tg high frequencies. Hence in images, regions where the grey levels change slowly are the Image Enhancement in Spat Digital Image Processing (PU) a b Grey level Fig, 4.29 Generally a and b are black and white grey levels respectively. Hence for a 8-bit image. 2 =0,b = 255 because of which the noise is called salt (white) and pepper (black). Some books refer to it as speckle noise. Take the same image as the one taken for the Gaussian example. eo @ ‘a (a) When salt and pepper creeps in, the image looks like se (b) Fig. 4.30 a) Salt and pepper noise creeps into images in situations where quick transients, such as faulty switching takes place. 4.4.4 Low Pass Averaging Filter : ___ If an image has Gaussian noise present in it, we use a low pass averaging filter to climinate the noise. The frequency response of the low-pass filter along with its spatial Tesponse is shown in Fig. 4.31. This relationship will be proved in chapter of Image nt in frequency Domain. — Image Enhancement in Sj spatial vor ital Image Processing (PU) 50 50 50 50 50 50 50 50 We place a 3 x 3 mask on this image. We start from the left hand top corner. We cannot \work with the borders and hence are normally left as they are. We then multiply each component of the image with the corresponding value of the mask. Since all the nine values of the image are 10, the average is also ten and the centre pixel (the underlined pixel) remains ten. We now shift the mask towards the right till we reach the end of the line and then move it downwards. Some of the mask po should be written in a new matrix (image). ions are shown here, 50 50 50 50 50 50 10 10 10 10 10 10 10 50 50 50 10 10 10 10 10 10 10 10 10 10 10 10 10 0) 10 10 10 10 fo 10 10 | 10 10 10 10 me? 10 10 , 10 10 10 10 10 10 10 19 i 50 50 50 50 50 50 50 50 50 50 50 sy 5 %0 50 50 50 50 50 50 50] |50 50 50 50 50 5 50 5 % 50 50 50 $0 50 50 50} |s0 so 50 so so 50 50 5 50 50 5050 30 50 50 50] 50 so so 50 50 10 | | 10} 10 | | 50} 50 | 50 50 50| 30 10] 10 10 10 30 50 50 50 50 50 50 50 50 50 50 50 The last one in the sequence being 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 50 50 50 50 50 50 50 50 50 50 50 so so {s0 50 50 50 50 50 505050 30 50 50 50 50 30 50 50 50 50 The result of convolving the image with the 3 x 3 averaging mask is shown. wo 10 10 1 10 10 10 10 1 1 10 10 10 10 10 10 1 10 10 10 10 10 10 10 é& 4152 233 233 233 233 233 233 233 23.3 ae 36.6 36.6 36.6 36.6 36.6 366 36.6 36.6 Sara so 30 50 50 50 50 5050 a . 50. 500 (50 50 ’ 50 50 50 50 3 50 50 «50 «(50 50 500—s 50s“ "As we notice, the low frequency regions have remained unchanged, but the sharp edge between 10 and 50 has become blurred. The transition has reduced. Now from 10, the grey level changes to 23.3 (23 after rounding off), from 23 it changes to 36.6 (36 after rounding off) and finally from 36 it changes to 50. Hence we can say that the sharp edge has become blurred Check for yourself, what would happen if you took a bigger mask, say, 5 x 5. (You will have to take a bigger image to test your results). These kinds of averaging filters are excellent when the image contains Gaussian noise. It Sees cere by tinting ton eles Some of the other low pass averaging masks are [ofoto] aan a ith Gaussia, n MATLAB program for low pass filtering along with the ima; d %'% Low pass filter used on an image with Gaussian noise clear all cle aa=imread(“xray.tif); % size 600 x 800 f=double(aa); ab=imnoise(aa, gaussian’): % adding noise a=double(ab); WILL LL Lys [row col} for x=2:L:row-1 for y=, ize(a); sL:col-L al(xy)= W(1)*a(x-Ly-1)+w(2)*a(x- Ly w(3)F,., absLyt1bw(4)#a(xy-1)+w(5)*aGcy) (6). abeyt Dew(7)*a(+L y-1}+0(8)*a( cL yee(O)e a(x+ly+1): : end end figure (1) imshow (uint8 (a)) ; figure (2) limshow (uint8 (al) (b) Low p al image with Gaussian noise Fig, 4.33 sseq title (“Low Pass Filtered 4.4.5 Low Pass Median Filtering : The averaging filter removes the noise by blurring it till it is 4 longer seen. Bu , Process, it also blurs the edges. Bigger the averaging mask more is the blurring. Ther, toss when the image contains salt and pepper noise. If we use an averaging filter to remy the same, it will blur the noise but it would also ruin the edges. Hence when w¢ nee eliminate salt and pepper noise, we work with a non-linear filter known as the Median § They are also called order-statistic filters because their response is based on the ordering ranking of the pixels contained within the mask, In this case, we use a mask similar to the averaging filter except that the mask has values. So it’s like working directly with the 8 neighbours of the centre pixel. The steps to perform median filtering are as follows : (1) Assume a3 x 3 empty mask, (2) Place the empty mask at the left hand corner, G) Arrange the 9 pixels in ascending or descending order, (4) Choose the median from these nine values, (5) Place this median at the centre. (6) Move the mask in a similar fashion to the averaging filter, In median filtering, the grey level of the centre pixel j 4 the neighbourhood. Always write the resultant in gone nae imag median value 0 median filtering with an example. In the image shown below let 250 Be, © shall explai: noise. If we use an averaging filter, the noise would spread out and the the salt and pepp«: Up getting blurred. If we only want to remove the noige a edges Would also end median filter a PI the cdacs, we v. 10 10 10 10 10 10 19 10 10 250 10 10 19 10 10 10 10 10 10 19 50 50 50 50 50 50 50 50 50 50 59 50 50 50 50 $0 59 [50 50 50 $0 $0 50 10 10 10 10-10. 10 10 1010 SekDasl0: 10 10 10 10 10 10 10 10 10 ats 42: if x= {2343456} and w=(-10 1}, perform median filtering. join. : w= {-1, 0, 1} simply means that the size of the mask is | x 3 and the term 0 indicat. the position from where the filtering starts. [2343456] Boundary value = 2 =1 01] Median (4,3,4) = 87) Gade, [ToT] Boundary value - WV 3 1 ot Median (2,3,4) = 3 [<707] Median (3,4,5) = 4 u v EREPE Median (3.4.3) =@ Median (4,5,6) = 6 L vi uw 4 ie {23.9445 6}. The principal function of median . Hence the final answer 1s y ints with distinct intensities to be more like their neighbours : is to force po! BF oigtar Image Processing (PU) 4-33 Image Enhancement in Spatial Domain MATLAB program for median filtering along with the images with salt and pepper noise %% Median filter on image with salt and pepper noise %'% clear all lele \I-imread (‘deepa.tif); \J-imnoise (I, ‘salt & pepper’,0.02); % Adding noise ja=double(J): bx: \frow col]=size(a); ifor x=2: I:row-1; | for y=2:1:col-1; | %% To make a3 x 3 mask into a1 x 9 mask al=[a(x-I.y-1) a(x-l.y) a(x-Ly+1) a(xy-1) a(xy).. | a(xytl) a(x+Ly-1) a(xt+Ly) a(x+1y+l)]: a2=sort(al); | ‘med=a2(5); % the fifth value is the median r ‘ Fi (a) Original image with salt (b) Median filtered image and pepper noise Fig, 4.34 45 Hi i ie retaining or enhanc; Highpass filtering eliminates the | ea have no backer, high frequency components. An image, which is high+ hanced edges. Hence hic (as background are low frequency regions) and would have ES tow a oe filters are used to sharpen blurred images, Once we have ung . Srilier as over the entire image for the averaging filter, the same applies 10 ee se and ae All that needs to be changed are the mask coefficients. The Fog ae response of a high pass filter are shown in Fig, 4.35. This will be proved ay Enhancement in frequency Domain. low frequency regions whi that they have a positive value at the centre and negative One of the high pass masks is shown in Fig, 4.35. ‘The important thing to note is that the sum of th to be equal to zero. This is because, when we place the result should be zero. - Let us take an example of a pscudo-imagi - |9 - 10480) \ 00 (08 MATLAB program for high pass filtering {%% High pass filtering %% clear all jele \aa=imread (“xray.tif); \a=double (aa): |[row colj=size(a); |w=[-l 1-1; -18-1, -1-1-1] for x=2:1:row-1 | for y=2:1:col-1 | al (x.y)= w(1)*a(x-L.y-1)+w(2)*a(x-1.y)+w()* ., a(x-Ly+1)+w(4)*a(x,y-1)+w(5)*a(x.y)+w(6)* Peni a(xtLy+]); end = oat figure(1) f imshow(uint8(a)) ‘ ¢ Ifigure(2) imsbow(uints(a)) Pan a (b) High pass filtere, ‘dimage [21 Digital mage Processing (PU) 4-41 Image tnne ‘As stated earlier, we start from the first row. We replicate each pixel and then replicate each row, The first row now looks like 11223344 We now replicate this row to get 12a ei alan’ 11223344 Performing this operation on the entire image we get Hence a 4 x 4 image is zoomed to a 8 x 8 image. This method can be repeated to get bigger images. Remember, this is an image enhancement technique and hence no new data is added. In the zoomed pseudo-image, we observe that as we increase the size of the image, clusters of grey levels are formed which are disconcerting to the observer. Hence zooming increases the’size of the image no doubt, but it also gives the image a patchy look. Zooining by replication can be implemented on the computer by using a replication mask. The first step is to interlace the original image with zeros. This is known as zero interlacing, In this we add zeros after every pixel and then add a complete row of zeros. Adding zeros to every other pixel of the first row we get, 10203040 This is also known as zero interlacing the columns, as we add zeros at every other Column. Now inserting a row full of zeros gives us. This is known as zero interlacing the rows 8 we add zeros at every other row. 10203040 00000000 = (1 Digital image Processing (PU) = a Method 2: sa In the second method, instead of plotting the number of pixels directly. WE lor probability of occurrence i.e., pi) = * Lo k" grey level a n, — Number of pixelsimthek grey level n ~ Total number of pixels in an image This is known as a normalised histogram. The d the maximum value to be plotted will always be 1. G 0 and white as the maximum. Just by looking at the information can be obtained. Some of the typical histo cr) P(r) LL i Grey le Grey level © @ Fig. 53 In Fig. 5.3(a) all the pixels belong to the lower grey levels 0, 1, .... and hence we can be sure that the image, represented by this histogram, is a dark image. Similarly, Fig. 5.3(b) is the histogram of a bright image. Fig. 5.3(¢) is a low contrast image since only a small range grey levels are present. Fig. 5.3(d) is a high contrast image. Of all the 4 histograms shown, the last histogram represents the best image. Our aim in this chapter would be to transform the first three histograms into the fourth histogram. In other words, We try to increase the dynamic range of the image. Though MATLAB has a inbuilt function to plot the histogram (hist) we shall write our own code. MATLAB code for plotting the histogram of an image. _ 5 "digital image Processing (PU) 5-4 Image end end for n=1:1:row for m=1:1:col ta(n.m); 6% Takes the value of the pixel ex, 12 h(y=hi+1; 96% Incrementing cach counter n(12) ‘Ono way. to increase the dysamic range i Dy iia age stretching. le —- We first plot the original histogram n 4 1023

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy