Smoothing an Image
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:
Smoothing with Average 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. Run the example procedure by entering smoothingwithsmooth at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT smoothingwithsmooth.pro.
- Import the image from the
rbcells.jpgfile: - Initialize the display:
- Create a window and display the original image:
- Create another window and display the original image as a surface:
- Smooth the image with the SMOOTH function, which uses the average value of each group of pixels affected by the 5 by 5 kernel applied to the image:
- Create another window and display the smoothed image as a surface:
- Create another window and display the smoothed image:
file = FILEPATH('rbcells.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, image
imageSize = SIZE(image, /DIMENSIONS)
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Original Image' TV, imageThe 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.
Smoothing with Median Values
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. Run the example procedure by entering smoothingwithmedian at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT smoothingwithmedian.pro.
- Import the image from the
rbcells.jpgfile: - Initialize the display:
- Create a window and display the original image:
- Create another window and display the original image as a surface:
- Smooth the image with the MEDIAN function, which uses the middle value of each group of pixels affected by the 5 by 5 kernel applied to the image:
- Create another window and display the smoothed image as a surface:
- Create another window and display the smoothed image:
file = FILEPATH('rbcells.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, image
imageSize = SIZE(image, /DIMENSIONS)
WINDOW, 0, XSIZE = imageSize[0], YSIZE = imageSize[1], $ TITLE = 'Original Image' TV, imageThe 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.
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.







