image-processingfftdm-scriptbandpass-filter

How to use the AddBandPassMaskToImage() method?


I am trying to apply a band pass filter to an image using dm script to filter out the noisy pixels. Can I achieve this task using the AddBandPassMaskToImage() method? It only works with the RealImage datatype and the filtered image that it's returning has a large black circular band in the middle. How do I use it correctly?

AddBandPassMaskToImage( ImageReference mask, Number x_center, Number y_center, Number
band_radius_1, Number band_radius_2, Number filter_length, Boolean do_inverse )

My code and images of the results are given below. I wasn't expecting any black bands as shown in the filtered image. I suspect that I am using the method incorrectly, but since the mask applies to RealImage data type and not ComplexImage data type, I assumed that I wouldn't need to do any operations on the FFT.

image front = GetFrontImage()
number xsize, ysize, zsize
get3dsize(front, xsize, ysize, zsize)
image frontCopy := front
AddBandPassMaskToImage(frontCopy, xsize/2, ysize/2, 5, 154, 1, 0)
showImage(frontCopy)

I don't have the reputation to post images but the links are given below:

Before applying the method BEFORE

After applying the method AFTER


Solution

  • In general I would advise using the Filter Palette to set up (named) filters and then using them with the IFMApplyFilter command, as it is also described in the Filtering section of the script-examples in the F1 help documentation:

    F1 help on filtering

    The command AddBandPassMaskToImage is just adding smooth donut-shaped zero-to-one valued sections to an image, to help creating band-pass masks in FourierSpace. The mask then needs to be applied (multiplied) to attenuate the intensity before back-transforming the image into real space.

    realimage img := RealImage( "Test Image 2D", 4, 512, 512 )
    img = abs( itheta*2*icol/(iwidth+1)* sin(iTheta*20)  ) 
    img = PoissonRandom(100*img)
    img.ShowImage()
    
    // Transform
    compleximage img_FFT := FFT(img)
    
    // Modify in F-Space
    // Build mask
    image mask:=RealImage("Mask in F-Space",4,512,512)
    mask.AddBandPassMaskToImage( 256, 256, 200, 40, 10, 0 )
    mask.ShowImage()
    
    //Apply mask
    img_FFT *= mask
    img_FFT.SetName( "Masked FFT" )
    img_FFT.ShowImage()
    
    // Transform back
    image img_filter := modulus(iFFT(img_FFT))
    img_filter.SetName("Filtered")
    img_filter.ShowImage() 
    
    EGUPerformActionWithAllShownImages("arrange")
    

    Example of Fourier-filtered image