Scripting Resources for DigitalMicrograph™ |
Example: Smoothed Annular Mask Function |
|
Function |
A function which creates an annular mask, the edges of which can be smoothed to a gaussian shape. This can be useful for FFT filtering. |
Version |
version:20100725, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
Where gaussian smoothing is applied, the value of the mask at the specified internal and external radii is 0.5 ie the smoothing begins inside the mask limits. If the mask value is to be unity between the specified radii and then decrease from the mask edges, code to do this is included in the function - but commented out. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
Will produce square masks only, but with no checking for integral power of two dimensions. |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
// Example script shows how to create an annular mask with gaussian smoothed edges. // D. R. G. Mitchell, adminnospam@dmscripting.com.au // version:20100725, v1.0, July 2010
// Function create an image for the mask
image createannularmask(number filtersize, number innerradius, number outerradius, number gaussedgewidth) {
// Check that input values are OK and create a mask image
if (outerradius<innerradius) { number temp=outerradius outerradius=innerradius innerradius=temp }
if(innerradius>filtersize/2) innerradius=(filtersize/2)-2 if(outerradius>filtersize/2) outerradius=(filtersize/2)-1
number halfsize=filtersize/2 image mask=realimage("",4,filtersize, filtersize) mask=1
// This code (not used) applies gaussian smoothing to the mask // value so that it is 0.5 at the specified inner/outer radius
//mask=tert(iradius<innerradius+(gwidth/2), exp(-((innerradius+(gwidth/2)-iradius)**2+(innerradius+(gwidth/2)-iradius)**2)/(Gwidth**2)), temp) //mask=tert(iradius>(circsize-(gwidth/2)), exp(-((circsize-(gwidth/2)-iradius)**2+(circsize-(gwidth/2)-iradius)**2)/(Gwidth**2)), temp)
// The code below sets the values of the mask to 1 out to the specified radii. The gaussian // edges fall away from that point.
if(gaussedgewidth==0) gaussedgewidth=0.0001 // trap to avoid divide by zero mask=tert(iradius<=innerradius, exp(-((innerradius-iradius)**2+(innerradius-iradius)**2)/(gaussedgewidth**2)), mask) mask=tert(iradius>=outerradius, exp(-((outerradius-iradius)**2+(outerradius-iradius)**2)/(gaussedgewidth**2)), mask)
return mask }
// Main program starts here
image mask=createannularmask(512, 100, 300, 0) showimage(mask)
|