Download
image processing n.
Skip this Video
Loading SlideShow in 5 Seconds..
Image Processing PowerPoint Presentation
Download Presentation
Image Processing

Image Processing

252 Views Download Presentation
Download Presentation

Image Processing

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Image Processing

  2. Image processing • Once we have an image in a digital form we can process it in the computer. • We apply a “filter” and recalculate the pixel values of the processed image. • We will look at the application of filters to sharpen and soften (make less sharp) the image.

  3. Filters or Kernals • Our filters take the form of a small matrix or vector which we place (in turn ) over the image at each pixel position. • Typically our filters are symmetrical 3 x 3 matrices. • We use a process called convolution to apply the filter to the image.

  4. Convolution • Convolution is the process of multiplying each element of our filter by the pixel values of the image that the filter covers and adding the products. • We can describe the result as “the original image convolved with the filter”. • conv2 is a Matlab function which can do this. Strictly what is described above is not a convolution but a correlation, however if our filters are symmetric the result is the same.

  5. -1 -1 0 0 0 0 -1 -1 -1 -1 4 4 -1 -1 0 0 0 0 Convolution and filters Filter 56 56 56 56 56 56 59 89 15 Image sample set 1 5 4 2 3 7 9 4 5

  6. Convolution and filters 56 56 56 56 56 56 59 89 15 Image sample set 1 -1 0 5 0 4 -1 2 3 7 -1 4 9 -1 4 5 0 0

  7. Convolution and filters 1 -1 0 5 0 4 2 -1 3 7 -1 4 4 5 9 -1 4 5 3 7 0 0 9 4 5 So the value of 3 in the centre of the original image is replaced with –5 on the convolved image.

  8. Image softening • If we make all the elements of the filter equal to one ninth, then the convolution value will be the average of all the elements “covered” by the filter. • It is the same as adding all the 9 values together and dividing by nine.

  9. Image softening • The following block of image samples represents a sharp vertical edge as pixel values suddenly change from 0 (black) to 255 (white). • We will attempt to smooth it (make it less sharp). Sample Block

  10. Image softening • Consider the operation of the averaging filter on the block of image samples. Filter Sample Block

  11. Image softening • As we “run” the filter over the centre of the sample block. The following changes will take place. See next slide. Filter Sample Block

  12. Image softening • The zeros in the 4th column are replaced with 85, since:

  13. Image softening • Similarly as we perform the convolution of the filter with the rest of the centre of the sample block we get:

  14. Image softening • The resultant convolution (image) no longer has a sharp edge, but a more gradual one.

  15. Image softening • That’s the theory; lets try it. for i=1:256 grey(i, 1:3)=(i-1)/255 end colormap(grey) myedge=zeros(5, 8) myedge(:, 5:8)=255 filt=ones(3,3)/9 image(myedge) myconv=conv2(myedge,filt, 'valid') image(myconv)

  16. Softening an image im=imread(‘urban.bmp'); smooth=[ 1 1 1; 1 1 1; 1 1 1]/9 % convolve all colours smoothim(:,:,1)=conv2(im(:,:,1),smooth); smoothim(:,:,2)=conv2(im(:,:,2),smooth); smoothim(:,:,3)=conv2(im(:,:,3),smooth); image(im) figure image(uint8(smoothim))

  17. Image sharpening • It is easier to see this in one dimension initially. • Consider some neighbouring pixels that are not sharp. • If they are not sharp there will be no abrupt change in value between them. • If we can cause an a more abrupt change in value between neighbouring pixels, we will sharpen the image.

  18. Image sharpening • It is easier to see this in one dimension initially. • Consider some neighbouring pixels that are not sharp. • If they are not sharp there will be no abrupt change in value between them. • If we can cause an a more abrupt change in value between neighbouring pixels, we will sharpen the image.

  19. Image sharpening • The idea is to generate artificial sharp edges at the points of differing neighbouring pixels and then add these edges to the original image. • The following diagram shows the variation in brightness values for: • (a) A perfect (sharp) edge. • (b) A blurred edge. • (c) The artificial correction to be added. • (d) The corrected (enhaced) edge.

  20. Image sharpening 200 (a) 100 200 (b) 150 100 50 (c) -50 250 200 150 (d) 100 50

  21. -1 0 0 -1 -1 4 -1 0 0 -1 -1 2 2 Image sharpening • What kernal (filter) will (when convolved with the image) generate the correction waveform (c) ? • In one dimension • Check it. • It produces zero for flat fields, but a negative and positive edge at edges • In two dimensions

  22. -1 0 -1 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 -1 0 -1 1 4 5 1 -1 0 -1 0 0 0 0 0 0 0 0 0 Image sharpening • We need to produce a kernal which will add the artificial edges and the original together. • The original will be produced if we only have a one (1) in the centre of the a convolution kernal. Check it. • Add this to the edge generator + =

  23. Sharpening an Image im=imread(‘urban.bmp'); sharp=[ 0 –1 0; -1 5 –1; 0 –1 0] % convolve all colours sharpim(:,:,1)=conv2(im(:,:,1),sharp); sharpim(:,:,2)=conv2(im(:,:,2),sharp); sharpim(:,:,3)=conv2(im(:,:,3),sharp); image(im) figure image(uint8(sharpim))