X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



4730 Rate this article:
5.0

Removing Noise from an Image with FFT in IDL

This example uses the FFT transform to remove noise from an image in IDL. The image comes from the abnorm.dat file found in the examples/data sub-directory under your IDL directory.

After running the code example below, the first display contains the original image and its FFT transform. The noise is very evident in the image. A surface of the transform helps to determine the threshold necessary to remove the noise from the image. In the surface of the transform, the noise appears random below a ridge containing a spike. The ridge and spike represent the actual data within the image. A mask is applied to the transform to remove the noise and the inverse transform is applied resulting in a clearer image.

Code Example:

PRO removingNoiseFromAnImageWithFFT
 
    ; Determine the path to the file.
    file = FILEPATH('abnorm.dat', $
       SUBDIRECTORY = ['examples', 'data'])
 
    ; Initialize size parameter and image array.
    imageSize = [64, 64]
    image = BYTARR(imageSize[0], imageSize[1])
 
    ; Open file, read in image, and close file.
    OPENR, unit, file, /GET_LUN
    READU, unit, image
    FREE_LUN, unit
    
    ; Initialize display parameters, including a color
    ; table. If you are on a TrueColor display, set
    ; the DECOMPOSED keyword to 0 before using any color
    ; table related routines.
    displaySize = [128, 128]
    DEVICE, DECOMPOSED = 0
    LOADCT, 5
    WINDOW, 0, XSIZE = 2*displaySize[0], $
       YSIZE = displaySize[1], $
       TITLE = 'Original Image:Transformation'
 
    ; Display original image.
    TVSCL, CONGRID(image, displaySize[0], displaySize[1], $
       /INTERP), 0
 
    
    ; Transform image.
    transform = ALOG(SHIFT(FFT(image), (imageSize[0]/2), $
       (imageSize[1]/2)))
 
    ; Display transformation.
    TVSCL, CONGRID(transform, displaySize[0], $
       displaySize[1], /INTERP), 1
 
    ; Scale transform make its minimum value equal to zero.
    scaledTransform = transform - MIN(transform)
 
    ; Display results of scaling.
    WINDOW, 1, TITLE = 'Transform Scaled to a Zero Minimum'
    SURFACE, scaledTransform, /XSTYLE, /YSTYLE, $
       TITLE = 'Transform Scaled to a Zero Minimum'
 
    ; Filter scaled transform to only include high
    ; frequency data.
    mask = FLOAT(scaledTransform) GT 6.
    filteredTransform = (scaledTransform*mask) + $
       MIN(transform)
 
    
    ; Initialize display.
    WINDOW, 2, XSIZE = 2*displaySize[0], $
       YSIZE = displaySize[1], $
       TITLE = 'Filtered Transformation: Results'
 
    ; Display filtered transform.
    TVSCL, CONGRID(FLOAT(filteredTransform), displaySize[0], $
       displaySize[1], /INTERP), 0
 
    ; Apply inverse transformation to filtered transform.
    inverseTransform = ABS(FFT(EXP(filteredTransform), $
        /INVERSE))
 
    ; Display results of inverse transformation.
    TVSCL, CONGRID(inverseTransform, displaySize[0], $
       displaySize[1], /INTERP), 1
 
END

_________________________________________
Reviewed by BC on 09/05/2014
Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »