Global Mapper v25.0

Raster calculator

hgleixner
hgleixner Global Mapper UserTrusted User
edited October 2014 in Bug Report
Hello,
in order to test the raster calculator I simply tried to force RGB=128,128,128 for all pixels (constant grey).
B1=128
B2=128
B3=128
Look at the attached screen, the blue and red pixels and please help!

Regards.
Henry (GM16.0 64bit)

PS:
1. The grey values are 127 instead of the requested 128
2. change the extension txt to gm_formula

Comments

  • hgleixner
    hgleixner Global Mapper User Trusted User
    edited September 2014
    And here is another exmple, that I don't understand: I get a black screen after applying instead of a sligthly brighter orthophoto below RGB=85,85,85:

    GM FORMULA FILE
    OUTPUT_TYPE=IMAGE
    OUTPUT_BIT_DEPTH=8
    INPUT_BIT_DEPTH=8
    FORMULA=IF(B1<85, B1=B1*0.765+20, B1)
    FORMULA=IF(B2<85, B2=B2*0.765+20, B2)
    FORMULA=IF(B3<85, B3=B3*0.765+20, B3)

    Henry
    (Change txt into gm_formula)
  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User
    edited September 2014
    Hi Henry,

    OK, I think that I see what's going on here: the raster calculator only allows you to create new raster imagery based on its source imagery; it doesn't allow you to modify the source imagery. I think that our documentation could be a little clearer on this point, and probably in general for the raster calculator.

    To take your original example "B1 = 128": This is a comparison expression, not an assignment. That is, the result of the formula is not the constant 128; instead, for each pixel in the output later would be either 1 if the corresponding pixel in the input band were equal to the 128, and 0 otherwise.

    Similarly, the formula "IF(B1<85, B1=B1*0.765+20, B1)" probably doesn't do what you're expecting, because the second argument to the IF() statement ("B1=B1*0.765+20") is a comparison rather than an assignment.

    Depending on your Output Grid Settings, you'll either create a new multi-band layer (one band per formula) or a shaded single band.

    For example, I took your formulas, slightly modified and added them as custom formulas, and selected a multi-band output:

    IF(B1<85, B1*0.765+20, B1)
    IF(B2<85, B2*0.765+20, B2)
    IF(B3<85, B3*0.765+20, B3)

    This made a multi-band image with 3 bands that lightened up the original Landsat. This image could then be saved to disk.

    Let me know if this helps.

    Best regards,

    ~Jeff
  • hgleixner
    hgleixner Global Mapper User Trusted User
    edited September 2014
    Jeff,
    thanks!

    Please look at the attachments: I tryed to slightly (!) lighten up by the formulas above (*.txt > *.gm_formula), but what result?

    I attached an excel sheet too (*.txt > *.xls), which shows the very slight curve.

    Henry
    (GM 16, 64 bit)
  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User
    edited September 2014
    Hello Henry,

    I took the new formula file that you made and ran it against some aerial photography that is 8-bit RGB (not LandSat, though), and got the desired brightening in the output image. Are you sure that you had your input bands set up correctly? In my testing, I was able to get a similar result to yours by leaving the red channel alone; perhaps you are not mapping that band correctly?
  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User
    edited September 2014
    One question for you: after you loaded your formula file, did you use Update Selected Item to update a formula in the list? I just discovered a bug with our handling of that situation that would cause problems with the generated band for that formula.

    thanks,

    ~Jeff
  • hgleixner
    hgleixner Global Mapper User Trusted User
    edited September 2014
    Jeff,
    your last thread helped: Now I get a plausible result if loading the formula from a file each. I dont' succeed if changing the formula in the dialog.

    But unfortunately there is still a strange thing:

    Not the shadows get brighter but the lights! The formula seems to work inverted.

    I attached the Orthophoto (DOP20_part.txt > DOP20_part.tif) and too screens after zooming in. Look at the railroad and the rural road: I do not intend to lighten that part of the histogram!


    Regards
    Henry
  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User
    edited September 2014
    Hello Heny,

    OK, I think I finally understand what's going on here. The raster calculations are correct when they're performed, as far as that goes. However, there is a Global Mapper setting that causes Global mapper to subsequently adjust the image's contrast when it's loaded internally as a layer. To disable this behavior, bring up the Configuration dialog (Tools / Configure), and switch to the General tab. At the bottom, under Miscellaneous Advanced Options, look for the setting "Never Automatically Contrast Adjust Images on Load" and make sure that the checkbox is checked. That should leave the new image with the actual pixel values that your formulas calculate.

    I hope that this helps; my test on your sample image appeared to work: the dark areas were lightened up and the light areas were left alone. I'm going to consult with the rest of the team about whether we should ignore this setting during raster calculation, or possibly make it a setting on the Raster Calculator dialog.

    Thanks for your patience while we've been addressing the issue, and thanks for using Global Mapper!

    best regards,

    ~Jeff
  • hgleixner
    hgleixner Global Mapper User Trusted User
    edited September 2014
    Thanks, Jeff!

    Now it works on 8bit imagery.

    Unfortunately I need your help concerning 16 bit 4 channel imagery.

    The attached formula didn't work (*.txt > *.gm_formula)

    Henry
  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User
    edited September 2014
    Hello Henry,

    According to Mike, if calculated layers are 8-bits per band, then no auto-contrast is needed. For higher bit depths, you will need to have auto-contrast enabled to convert the band values to 8 bits for display. So if you uncheck the "Never Automatically Contrast Adjust Images on Load" setting (the same one as above), you should get the results you require.

    We are considering putting a checkbox on the dialog to govern this setting, and adding it to the formula file format.

    Please let me know if this helps,

    thanks,

    ~Jeff
  • hgleixner
    hgleixner Global Mapper User Trusted User
    edited October 2014
    Jeff,
    it helped but now I'm forced to accept the autocontrast. Please put a checkbox on the dialog!

    Thanks
    Henry
  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User
    edited October 2014
    Hi Henry,

    We have a version in the works that will help with all of that, and not require a checkbox. You'll be able to leave the global setting unchecked, and the raster calculator will perform auto-contrasting only if there are more than 8 bits per band. We'll post here when that's ready for you to download.

    thanks,

    ~Jeff
  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User
    edited October 2014
    Hi Henry,

    You can find a version of Global Mapper that fixes the auto-contrasting issue at the links below. Essentially, the fix causes auto-contrast to run if you have a bit-depth greater than 8, unless you have the "Never Automatically Contrast Adjust Images on Load" option checked.

    32-bit: http://www.bluemarblegeo.com/downloa...l_mapper16.zip
    64-bit: http://www.bluemarblegeo.com/downloa...er16_64bit.zip

    Just download the .zip file for the build that you are using and extract over your existing installation files (do not uninstall Global Mapper). The likely locations to extract to are as follows:

    32-bit: C:\Program Files (x86)\GlobalMapper16
    64-bit: C:\Program Files\GlobalMapper16_64bit

    best regards,

    ~Jeff
  • hgleixner
    hgleixner Global Mapper User Trusted User
    edited October 2014
    Jeff,
    thanks.

    Now If the contrast check box is unchecked I get a good result (WITH autocontrast), if it is checked (WITHOUT autocontrast) it looks like a "colored salt and pepper pattern".

    See the attachment (using a slightly changed formula).
    Regards
    Henry
  • JeffH@BMG
    JeffH@BMG Global Mapper Developer Trusted User
    edited October 2014
    Hi Henry,

    That's correct, and it's what we intended. You should generally not run with the option checked. Essentially, the idea is this:

    * For 8-bit imagery, you will most likely *not* want auto-contrasting to run, because the pixel values are already in the range 0-255. That would just clobber the pixels that you generated using your own carefully crafted formula. The code is set up to never run auto-contrasting on 8-bit pixels.

    * For pixel sizes > 8, you most likely will *always* want auto-contrasting to run, so that the generated pixels are correctly cut down to values in the range of 0-255. The software is set up to prefer to perform auto-contrasting automatically for pixel sizes > 8 bits, but in the unlikely event that you do want auto-contrasting not to run, you would then enable the setting.

    This is one of those settings where we think we know what setting you'll almost always want to have, and just do the right thing, but we'll let you override that if you know better in a certain use case.

    I hope that helps.

    Best regards,

    ~Jeff