Global Mapper Pro

EXPORT_RASTER 4 band to 3 bands

AndrewW
AndrewW Global Mapper UserTrusted User
edited October 2010 in GM Script Language
I am writing a script to convert 4 band RGBI images to 3 band IGB images. The following script sort of works in that I end up with a 3 band image but:
1. The I (infrared) band exports correctly
2. The Green band is inverted i.e negative.
3. The Blue band is inverted.
This is with v12. V11 had a different combination which also was not correct.

GLOBAL_MAPPER_SCRIPT VERSION=1.00
UNLOAD_ALL

//Help - http://www.globalmapper.com/helpv11/ScriptReference.html

// Loop over all files in a folder and crop them by no of pixels.
DIR_LOOP_START DIRECTORY="." FILENAME_MASKS="1-1133.tif" RECURSE_DIR=NO

// Import a tif file.
IMPORT FILENAME="%FNAME_W_DIR%"
//CLIP_COLLAR=PIXELS CLIP_COLLAR_BOUNDS=0,500,0,0



// Export to a new tif file.
EXPORT_RASTER FILENAME="%DIR%%FNAME_WO_EXT%_GBI.tif" TYPE=GEOTIFF PALETTE=MULTIBAND NUM_BANDS=3 BAND_BIT_DEPTH=8 BAND_EXPORT_SETUP="1?4?" BAND_EXPORT_SETUP="2?2?" BAND_EXPORT_SETUP="3?3?" GEN_WORLD_FILE=YES COMPRESSION=NONE

// Unload the loaded data
UNLOAD_ALL

// End the loop
DIR_LOOP_END

Comments

  • global_mapper
    global_mapper Administrator
    edited October 2010
    When you say the green and blue bands are inverted, are there actually signed values stored in those bands or something? Where are you seeing them inverted?

    In any case, there is an easier way to do this since you want a 24-bit 3-band output. Leave off all of the band stuff and the PALETTE paramter in the EXPORT_RASTER command and instead add the parameter BAND_SETUP="3,1,2" to the IMPORT command, which specifies that the source image should be rendered as IGB rather than the default RGB. Note that the band indices are 0-based in the BAND_SETUP paremter but 1-based in the band setup parameters to the EXPORT_RASTER command.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • AndrewW
    AndrewW Global Mapper User Trusted User
    edited October 2010
    Thanks Mike,
    Ok that fixed the export 4 band to 3 band IGB issue, but when I load resulting file into GM the file is inverted IE, it views as a negative. Viewing each separate band shows they are all negative and very flat too.
    Updated script as follows.

    GLOBAL_MAPPER_SCRIPT VERSION=1.00
    UNLOAD_ALL

    //Help - http://www.globalmapper.com/helpv11/ScriptReference.html

    // Loop over all files in a folder and crop them by no of pixels.
    DIR_LOOP_START DIRECTORY="." FILENAME_MASKS="1-1133.tif" RECURSE_DIR=NO

    // Import a tif file.
    IMPORT FILENAME="%FNAME_W_DIR%" BAND_SETUP="3,1,2"




    // Export to a new tif file.
    EXPORT_RASTER FILENAME="%DIR%%FNAME_WO_EXT%_IGB.tif" TYPE=GEOTIFF GEN_WORLD_FILE=YES COMPRESSION=NONE


    // Unload the loaded data
    UNLOAD_ALL

    // End the loop
    DIR_LOOP_END
  • global_mapper
    global_mapper Administrator
    edited October 2010
    If you load one of the source files into Global Mapper and go to the Band Setup tab of the Options dialog for the layer and re-arrange it to IGB (red from band 4, green and blue original), do you get the same appearance?

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • AndrewW
    AndrewW Global Mapper User Trusted User
    edited October 2010
    Compared to the original image it is very flat and views as a negative.

    Andrew
  • global_mapper
    global_mapper Administrator
    edited October 2010
    Andrew,

    Can you provide one of the files or at least some screenshots so that I can see what you are talking about? Do you have something from another source where you can tell what is should look like as an IGB image?

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • AndrewW
    AndrewW Global Mapper User Trusted User
    edited October 2010
    Original 4band RGBI (4bands.tif) and result 3band IGB ($band_IGB.tif) are attached

    4bands.zip4bands_IGB.zip IGB attached.
  • global_mapper
    global_mapper Administrator
    edited October 2010
    Ah I see the issue. The source 4-band file doesn't properly mark the 4th band as data or an alpha channel, so when you load it normally the user is prompted and you select that it is data and not an alpha channel and all is fine. There's no prompt from a script and the default of treating the 4th band as an alpha is used. You need to add LOAD_FLAGS="0~0~0~4~0~0" to your IMPORT command and then the 4th band will be treated as data rather than alpha and you should be fine.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • AndrewW
    AndrewW Global Mapper User Trusted User
    edited October 2010
    Fantastic Globalmapper comes through yet again.
    Can you just explain to me the LOAD_FLAGS command or point me to the relevant help as I'm sure I'm going to need it again.
    Thanks also for your prompt support.
    Andrew
  • global_mapper
    global_mapper Administrator
    edited October 2010
    The LOAD_FLAGS isn't documented officially as its meaning varies from type to type. Basically it holds anything that the user might have been prompted for when loading a particular file type.

    The best way to see what to use is to load a file in the user interface with the desired settings, then just save a workspace file and see what the LOAD_FLAGS value is for the options that you chose. The vast majority of formats don't use LOAD_FLAGS at all.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
Sign In or Register to comment.