Scripting Resources for DigitalMicrograph™ |
Invert Image Contrast |
|
Function |
Inverts the contrast of the front-most image. In binary-valued images, 0 become 1 and vice versa. In greyscale images the minimum becomes the maximum and vice versa, with everything in between scaled appropriately. |
Version |
version:20160325, v2.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
This script works on 1D and 2D images. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
- |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
// Script to invert the front-most image's contrast. An image which has binary values
// versa, with all values in between inverted/scaled appropriately. The image and // its inverse have the property that when summed the entire image has // a constant value .
// D. R. G. Mitchell, adminnospam@dmscripting.com (remove the nospam to make this work) // version 20160325, v2.0, Mar 2016, www.dmscripting.com
// Check an image is displayednumber nodocs=countdocumentwindowsoftype(5)
if(nodocs<1) { showalert("Ensure an image is displayed front-most.",2) exit(0) }
// Source the front-most image and get some info from it
number minval, maxval, range, xsize, ysize image front:=getfrontimage() front.minmax(minval, maxval) front.getsize(xsize, ysize) string imgname=getname(front) range=maxval-minval
// Create an ouputimage. This must be real so that it can handle the inversion maths below. If it were // integer then a blank image would result from inversion, since the image is normalised values between // zero and one during the conversion.
// Create a copy of front (real by default) and copy the calibrations and taggroups from the front image to it.
image output=front imagecopycalibrationfrom(output, front) taggroup fronttags=front.imagegettaggroup() taggroup outputtags=output.imagegettaggroup() taggroupcopytagsfrom(outputtags, fronttags)
// Normalise the values to run from 0 to 1
output=(front-minval)/range
// Invert the values so that zero is 1 and vice versa
output=output-1 output=sqrt(output**2)
// Create the original value range
output=(output*range)+minval showimage(output) setname(output, imgname+" (inverted)")
// set the image display to autosurvey. Different commands are needed // for intensity profiles (ysize=1) and images
imagedisplay outputdisp=output.imagegetimagedisplay(0) if(ysize>1) outputdisp.imagedisplaysetdoautosurvey(1) if(ysize==1) outputdisp.lineplotimagedisplaysetdoautosurvey(1,1)
|