Search code examples
dm-script

How to use dm script to realize the "save display as" function?


It is easy to save the false color image to BMP or JPG by using "save display as" function in menu. But it fails to save a image stack as the seperated images with the displaying color. "save display as" only saves the front image of the stack. I could not click hundreds of times to save the whole stack! But I do not find the corresponding script function in the dm manual. How to realize it?


Solution

  • The command you're looking for is ImageDisplayGetExportImage() and there is actually an example script in the F1 help documentation of latest GMS for that:

    enter image description here


    But the command - same as the menu item - will only act on the actual display, so you still need to iterate over the displayed layers by script using ImageDisplaySetDisplayedLayers()

    So your script will be something like the following example:

    image test:=RealImage("Stack",4,100,100,10)
    test=sin(icol/iwidth*Pi()*2) * cos(itheta*iplane) 
    test.ShowImage()
    imagedisplay disp = test.ImageGetImageDisplay(0)
    disp.ImageDisplaySetColorTableByName("Rainbow")
    
    number nz = test.ImageGetDimensionSize(2)
    for( number z=0; z<nz; z++){
        disp.ImageDisplaySetDisplayedLayers(z,z)
        imageDisplay newdisp 
        image asDisplayedRGB := disp.ImageDisplayGetExportImage( 7, newdisp ) 
        asDisplayedRGB.SetName( test.GetName() + "_" + z )
        asDisplayedRGB.ShowImage()
    }
    
    EGUPerformActionWithAllShownImages("arrange")