Scripting Resources for DigitalMicrograph™ |
Function: Excise Central 2^n x 2^n Region |
|
Function |
This function will excise the largest possible central square (power of 2) region of a passed in image. |
Version |
version:201503015, v1.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
- |
Comments |
This function will excise the largest possible square region from the centre of a passed in image. The excised image has a power of 2 side length which makes it suitable for FFT-based processing. This can be useful for many things including cross-correlation-based image alignment. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
- |
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
// Function which excises the central 2^n x 2^n portion of an image (where n is an integer).
// version:150315, v1.0
// Function to excise the largest possible square region from the passed in image. The excised region will be centred within // the image and will have side length which is an integer power of 2.
image ExciseCentral2nby2n(image source) { // Get some info on the passed in image
number xsize, ysize getsize(source, xsize, ysize)
// Work out the maximum 2^n ROI
number xmod=log2(xsize) xmod=xmod-mod(xmod,1) number ymod=log2(ysize) ymod=ymod-mod(ymod,1)
xmod=2**xmod ymod=2**ymod
number xcentre=xsize/2 number ycentre=ysize/2 number top, left, bottom, right // Work out the ROI and excise it
top=ycentre-(ymod/2) left=xcentre-(xmod/2) bottom=ycentre+(ymod/2) right=xcentre+(xmod/2) image excised=source[top, left, bottom, right] return excised }
// Main Program - ensure an image is displayed to test this function
image front:=getfrontimage() image excise=excisecentral2nby2n(front) showimage(excise)
|