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

 

Transfer Calibration
Function
Transfers calibration between images.
Version
version:20011001, v3.0
Author
D. R. G. Mitchell
Acknowledgements
Comments
Handy for copying calibrations from a directly acquired image (which is calibrated by default), to a calculated image, which is not.
System Requirements
Should be compatible with all recent versions of DigitalMicrograph.
Known Issues
Needs the two images to be displayed in DM.
Supported
Yes
Included Files
Main script file.
Source Code

// Script to transfer the spatial calibration

// from one image to another, irrespective of binning differences between the two

// Warnings are posted if the source and target images are of different sizes.

 

// version:20011001

// adminnospam@dmscripting.com (remove the nospam to make this email address work)

 

// D. Mitchell, Oct 2001

// version 1.0

 

image sourceimage, targetimage

number xscale, yscale

number width, height

string units

 

 

// Set up calibration (source) and destination (target) images.

 

gettwoimageswithprompt(" Source (0),Target (1)","Select Source and Target Images", sourceimage, targetimage)

getscale(sourceimage, xscale, yscale)

getsize (sourceimage, width, height)

units=getunitstring(sourceimage)

 

// Check to make sure that the source image is calibrated.

 

if(units=="")

{

OKdialog("Your Source image is not calibrated")

exit(0)

}

 

// Compare the target and source images, and if differently binned, appropriate scaling is applied.

 

number targetwidth, targetheight

getsize(targetimage, targetwidth, targetheight)

 

// Tests to see if the target and souce images are the same size in x and y directions.

// Posts a warning if not with options to continue or abort

 

If((width/targetwidth)!=1 || (height/targetheight)!=1)

{

if(!twobuttondialog("Warning: Images are different sizes."+"\n"+"Source Image = "+width+" x "+height+"\n"+"Target Image =

"+targetwidth+" x "+targetheight, "Proceed", "Abort"))

{

exit(0)

}

}

 

number scalex=((width/targetwidth)*xscale)

number scaley=((height/targetheight)*yscale)

setscale(targetimage, scalex, scaley)

setunitstring(targetimage, units)

showimage(targetimage)

 

// Apply scale bar

 

ImageDisplay display = targetimage.ImageGetImageDisplay(0)

ApplyDataBar(display)