Search code examples
image-processingdm-script

Query the image data type in DigitalMicrograph script


How do I query the image data type and size with a digitalmicrograph (DM) script? I want to find out if the image is signed or unsigned, real or integer, the size of the pixel, etc.


Solution

  • There are commands to return this info as a return value, and some which query for a specific type. You find the commands in the following F1 help section:

    enter image description here

    Here is some example code:

    number byteIN = 4
    number sx = 10, sy = 10
    image test := RealImage( "Test", byteIN, sx, sy )
    
    // General commands
    number dataTypeEnum = test.ImageGetDataType()
    Result( "Image is of data type " + dataTypeEnum + ".\n" )
    
    number byte = test.ImageGetDataElementByteSize()
    number bits = test.ImageGetDataElementBitSize()
    Result( "Image has " + byte +" bytes/pixel ( =" + bits + "bits/pixel )\n" )
    
    // Some specific commands (there are more), all return Boolean
    if ( test.ImageIsDataTypeFloat() ) 
        Result( "Image is a real image.\n" )
    
    if ( test.ImageIsDataTypeInteger() ) 
        Result( "Image is an integer image.\n" )
    
    if ( test.ImageIsDataTypeBinary() ) 
        Result( "Image is a binary image.\n" )
    
    if ( test.ImageIsDataTypeComplex() ) 
        Result( "Image is a complex image.\n" )