Scripting Resources for DigitalMicrograph™

banner

Dave Mitchell's DigitalMicrograph™ Scripting Website

Home | Scripts | Examples | Functions | Recent Updates | Tutorials | Resources | Publications | Consulting | Projects | Contact & Bio |PyJEM| Search

 

Example: Butterworth Filter
Function
An example script which shows how to create a Butterworth filter - useful for spatial filtering with FFTs.
Version
20070228. v1.0
Author
D. R. G. Mitchell
Acknowledgements
Comments
Filtering is achieved by multiplying the FFT by the Butterworth filter then doing the IFFT. This Butterworth filter removes high frequency information (smooths). If the Butterworth filter is inverted it will remove low frequencies (sharpens).
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
Supported
Yes
Included Files
Main script file.
Source Code

// a function to create a Butterworth filter for filtering out high frequencies

// in the FFT.

 

// D. R. G. Mitchell, adminnospam@dmscripting.com (remove the nospam to make this email address work

// version: 20070228

// v1.0, Feb. 2007

 

 

image butterworthfilter(number imgsize, number bworthorder, number zeroradius)

{

 

// See John Russ's Image Processing Handbook, 2nd Edn, p 316

image butterworthimg=realimage("",4,imgsize, imgsize)

butterworthimg=0

 

 

// note the halfpointconst value sets the value of the filter at the halfway point

// ie where the radius = zeroradius. A value of 0.414 sets this value to 0.5

// a value of 1 sets this point to root(2)

 

number halfpointconst=0.414

butterworthimg=1/(1+halfpointconst*(iradius/zeroradius)**(2*bworthorder))

return butterworthimg

}

 

number butterworthorder=3

number zeroradius=128

number imgsize=1024

image butterworthimg=butterworthfilter(imgsize, butterworthorder, zeroradius)

showimage(butterworthimg)

 

// To use this filter create an FFT of the image you want to process, multiply the FFT by the

// butterworth image, then compute the inverse FFT. This filter will remove the high frequency

// component from the image - smooth. If you invert the Butterworth filter, it will remove the low frequency

// component - sharpen.