tiffunsigned16-bitdm-script

Save as tiff - 16bit unsigned


I receive 'integer 2 unsigned tiff' images from colleagues. They look fine in 'Paint' and in DM. After data processing in DM, I have real images. After taking care of the range, ConvertToShort() creates 'integer 2 signed' images. But any attempt on creating the correct tiff file (16bit unsigned) fails.
I am using ImageGetOrCreateImageDocument() followed by ImageDocumentSaveToFile() setting the tag groups "Save As Grey Scale", "Include Annotation" and "Save As Grey Scale" all to "1". The resulting images look very different in DM versus Paint.
Example code:

void my_SaveAsTiff( image tbdat, string path)
{   //  Default values for Tif:  keep actual size and burn in annotations
    number saveGreyScale = 1    // Convert to grey scale
    number includeAnno = 1      // "burn in" annotations on the display 
    number fullScale = 1        // Use data size not display-size of image
    tagGroup tg = GetPersistentTagGroup().TagGroupGetOrCreateTagGroup( "Private:Save Display" )
    tg.TagGroupSetTagAsBoolean( "Save As Grey Scale" , saveGreyScale )
    tg.TagGroupSetTagAsBoolean( "Include Annotation" , includeAnno )
    tg.TagGroupSetTagAsBoolean( "Full Scale" , fullScale )
        
    imageDocument doc = tbdat.ImageGetOrCreateImageDocument()
    doc.ImageDocumentSaveToFile( "TIFF Format", path, 1)        //  "0"... Save as shown - but full resolution (via 'includeAnno')
}   

string path = "C:/...................."

out = realImage("temp", 4, 2048, 768)   
out = 100 + 20.9*icol 
out.ConvertToShort()    //  
out.showImage()

my_SaveAsTiff( out, pathConcatenate(path, "temp"))

Help would be greatly appreciated!


Solution

  • To convert data to unsigned 16 bit (uint16) you can use

    number uint16Type = ImageConstructDataType( "scalar", "uint", 0, 16 )
    yourImage.ImageChangeDataType( uint16Type )
    

    Alternatively, you can always create an image of correct size and data format and then just copy the data:

    image conv := IntegerImage("temp",2,0,2048, 768)   
    conv = yourImage