Scripting Resources for DigitalMicrograph™ |
Example: Set Image Threshold |
|
Function |
Image thresholding is demonstrated |
Version |
version:20040722, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
Use of the rasterimage . . . and mp . . . (morphological processing) commands are demonstrated. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
- |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
// Example script to show how to create a binary threshold from an // image through use of the rasterimage commands and associate mp-commands
// D. R. G. Mitchell, July 2004 // version:20040722, v1.0
// Variables
number xsize, ysize, lolimit, hilimit, imgmin, imgmax
// Get the foremost image and extract some data on it
image frontimg:=getfrontimage() setwindowposition(frontimg, 142,24) getsize(frontimg, xsize, ysize) minmax(frontimg, imgmin, imgmax) string imgname=getname(frontimg)
rasterimagedisplay ridimg=imagegetimagedisplay(frontimg,0) rasterimagedisplaysetthresholdon(ridimg,1)
showimage(frontimg) updateimage(frontimg)
while (3>2) {
// enter the lower and upper threshold limits while (3>2) { if(!getnumber("Enter lower threshold value (minimum is "+imgmin+")",imgmin, lolimit)) exit(0) if(lolimit>=imgmin && lolimit<imgmax) break }
while (3>2) { if(!getnumber("Enter upper threshold value (maximum is "+imgmax+")",imgmax, hilimit)) exit(0) if(hilimit<=imgmax && hilimit>lolimit) break }
// Set up the threshold
rasterimagedisplaysetthresholdlimits(ridimg,lolimit,hilimit)
if(!twobuttondialog("Adjust thresholding or create binary?","Adjust","Create Binary")) break }
// Create the binary
image mask:=binaryimage("",xsize, ysize) mask=0 RasterImageDisplayAddThresholdToMask( ridimg, mask, 0, 0, ysize, xsize) showimage(mask) setname(mask, "("+lolimit+"-"+hilimit+") "+imgname) setwindowposition(mask,172, 54)
// There are a number of morphological processing tools - MP commands some are used here
image maskoutline=mpoutline(mask) showimage(maskoutline) setname(maskoutline,"Outline of ("+lolimit+"-"+hilimit+") threshold") setwindowposition(maskoutline, 202, 84)
image maskdistance=mpdistancemap(mask) showimage(maskdistance) setname(maskdistance,"Distance map of ("+lolimit+"-"+hilimit+") threshold") setwindowposition(maskdistance, 232, 114)
// Turn off the thresholding in the original image
rasterimagedisplaysetthresholdon(ridimg,0)
|