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

 

Scale Image to 0-255
Function
Scales the intensity values of the front-most image to the range 0 - 255.
Version
version:20040321, v1.0
Author
D. R. G. Mitchell
Acknowledgements
-
Comments
-
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
-
Supported
Yes
Included Files
Main script file.
Source Code

// script to convert the foremost image to a standard range

// ie one with values scaled (linearly) between 0 and 255

// Script to scale the front-most image so that its intensity values


// are scaled to run 0-255


// D. R. G. Mitchell, March 4th 2004

// version:20040321, v1.0

 

// function to scale the image

 

image stdrangeimage(image stdimage)

{

string imgname=getname(stdimage)

number minval, maxval, range

minval=min(stdimage)

maxval=max(stdimage)

range=maxval-minval

 

result("\n"+imgname+" : min = "+minval+", max = "+maxval+"\n")

 

image temp=imageclone(stdimage)

converttofloat(temp)

 

temp=temp-minval

temp=temp/range

temp=temp*255

converttoshort(temp)

return(temp)

}

 

 

// Main program starts here

 

// get foremost image and set up position

 

image front:=getfrontimage()

string imgname=getname(front)

showimage(front)

setwindowposition(front, 142, 24)

updateimage(front)

 

 

// rescale the image and display it

 

image finalimage:=stdrangeimage(front)

showimage(finalimage)

if(len(imgname)>22) imgname=left(imgname,21)+" 0-255"

else imgname=imgname+" 0-255"

setname(finalimage, imgname)

setwindowposition(finalimage, 172,54)

updateimage(finalimage)

result("\n"+imgname+" : min = 0, max = 255\n\n")