|
Image Processing : Contrasting and Filtering |
|
Smoothing is often used to reduce noise within an image or to produce a less pixelated image. Most smoothing methods are based on low pass filters. See Low Pass Filtering for more information.
Smoothing is also usually based on a single value representing the image, such as the average value of the image or the middle (median) value. The following examples show how to smooth using average and middle values:
The following example shows how to use the SMOOTH function to smooth an image with a moving average. Surfaces of the original and smooth images are displayed to show how discontinuous values are made more continuous. This example uses the photomicrograph image of human red blood cells contained within the rbcells.jpg file in the examples/data directory. Complete the following steps for a detailed description of the process.
| Example Code See smoothingwithsmooth.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
rbcells.jpg file:
file = FILEPATH('rbcells.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, image
imageSize = SIZE(image, /DIMENSIONS)
DEVICE, DECOMPOSED = 0 LOADCT, 0
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Original Image' TV, image
The following figure shows the original image. This image contains many varying pixel values within the background.
WINDOW, 1, TITLE = 'Original Image as a Surface' SHADE_SURF, image, /XSTYLE, /YSTYLE, CHARSIZE = 2., $ XTITLE = 'Width Pixels', $ YTITLE = 'Height Pixels', $ ZTITLE = 'Intensity Values', $ TITLE = 'Red Blood Cell Image'
The following figure shows the surface of the original image. This image contains many discontinuous values shown as sharp peaks (spikes) in the middle range of values.
![]() |
smoothedImage = SMOOTH(image, 5, /EDGE_TRUNCATE)
The width argument of 5 is used to specify that a 5 by 5 smoothing kernel is to be used.
WINDOW, 2, TITLE = 'Smoothed Image as a Surface' SHADE_SURF, smoothedImage, /XSTYLE, /YSTYLE, CHARSIZE = 2., $ XTITLE = 'Width Pixels', $ YTITLE = 'Height Pixels', $ ZTITLE = 'Intensity Values', $ TITLE = 'Smoothed Cell Image'
The following figure shows the surface of the smoothed image. The sharp peaks in the original image have been decreased.
![]() |
WINDOW, 3, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Smoothed Image' TV, smoothedImage
The following figure shows the smoothed image. Less variations between pixel values occur within the background of the resulting image.
The following example shows how to use IDL's MEDIAN function to smooth an image by median values. Surfaces of the original and smooth images are displayed to show how discontinuous values are made more continuous. This example uses the photomicrograph image of human red blood cells contained within the rbcells.jpg file in the examples/data directory. Complete the following steps for a detailed description of the process.
| Example Code See smoothingwithmedian.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
rbcells.jpg file:
file = FILEPATH('rbcells.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, image
imageSize = SIZE(image, /DIMENSIONS)
DEVICE, DECOMPOSED = 0 LOADCT, 0
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Original Image' TV, image
The following figure shows the original image. This image contains many varying pixel values within the background.
WINDOW, 1, TITLE = 'Original Image as a Surface' SHADE_SURF, image, /XSTYLE, /YSTYLE, CHARSIZE = 2., $ XTITLE = 'Width Pixels', $ YTITLE = 'Height Pixels', $ ZTITLE = 'Intensity Values', $ TITLE = 'Red Blood Cell Image'
The following figure shows the surface of the original display. This image contains many discontinuous values shown as sharp peaks (spikes) in the middle range of values.
![]() |
smoothedImage = MEDIAN(image, 5)
WINDOW, 2, TITLE = 'Smoothed Image as a Surface' SHADE_SURF, smoothedImage, /XSTYLE, /YSTYLE, CHARSIZE = 2., $ XTITLE = 'Width Pixels', $ YTITLE = 'Height Pixels', $ ZTITLE = 'Intensity Values', $ TITLE = 'Smoothed Cell Image'
The following figure shows the smoothed surface. The sharp peaks in the original image are decreased by the MEDIAN function.
![]() |
WINDOW, 3, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Smoothed Image' TV, smoothedImage
The following figure shows the results of applying the median filter. Less variations occur within the background of the resulting image, yet feature edges remain clearly defined.
IDL Online Help (March 06, 2007)