GeoTools
  1. GeoTools
  2. GEOT-1391

Support Histogram Contrast Stretching in GeoTools Rasters

    Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.4.0
    • Fix Version/s: None
    • Component/s: coverage
    • Labels:
      None

      Description

      I'd like to support histogram-statistical contrast stretching on rasters, specifically in ArcSDE, but possibly as a general filter for GridCoverages

      See http://www.fas.org/irp/imint/docs/rst/Sect1/Sect1_12a.html

      The idea is that you create a histogram of the colors a particular image, then calculate the mean pixel color and the standard deviation around that mean. You then consider the minimum pixel value of mean-(n*stddev) and the maximum pixel value of mean+(n*stddev). You then set the min pix val to image-output color zero, and the max pix val to image-output-color 255. Then you interpolate the remaining colors in the image into the 'stretched' color-space, causing higher contrast for the densest portion of the color-space.

        Activity

        Saul Farber made changes -
        Field Original Value New Value
        Assignee Martin Desruisseaux [ desruisseaux ] Saul Farber [ saul.farber ]
        Jody Garnett made changes -
        Fix Version/s 2.5-M0 [ 13594 ]
        Fix Version/s 2.5-M1 [ 13281 ]
        Jody Garnett made changes -
        Fix Version/s 2.5-M2 [ 14258 ]
        Fix Version/s 2.5-M1 [ 13281 ]
        Jody Garnett made changes -
        Fix Version/s 2.4.3 [ 14180 ]
        Fix Version/s 2.5-M2 [ 14258 ]
        Andrea Aime made changes -
        Fix Version/s 2.4.3 [ 14180 ]
        Fix Version/s 2.4.4 [ 14320 ]
        Andrea Aime made changes -
        Fix Version/s 2.4.4 [ 14320 ]
        Fix Version/s 2.4.5 [ 14338 ]
        Gabriel Roldan made changes -
        Fix Version/s 2.4.5 [ 14338 ]
        Fix Version/s 2.4.6 [ 14552 ]
        Hide
        Gabriel Roldan added a comment -
        Is this the same than the histogram support added in SLD?: <http://docs.codehaus.org/display/GEOTOOLS/Raster+Symbolizer+support>

        See the example called "Portrayal using an SLD with no Color Map, Gray Channel selection and Histogram Contrast Enhancement"
        Show
        Gabriel Roldan added a comment - Is this the same than the histogram support added in SLD?: < http://docs.codehaus.org/display/GEOTOOLS/Raster+Symbolizer+support > See the example called "Portrayal using an SLD with no Color Map, Gray Channel selection and Histogram Contrast Enhancement"
        Hide
        Saul Farber added a comment -
        Gabriel,

        No, this is not quite the same thing, although it's close. I believe the code to look at is ContrastEnhancementNode.java. ContrastEnhancementNode defines a number of allowed "contrast enhancement" types.

        To solve this bug, a new contrast enhancement type needs to be added called (roughly) "histogram-mean-stretch" which will also take a parameter, the number of std devs to stretch by (not sure how to tie this into the SLD render, perhaps as an attribute? operation="HISTOGRAM-MEAN-STRETCH" stdevs="2")

        The implementation will do the following calculation for each band:

         1. Calculate the mean value across all pixels in the image, as well as the std devation around that mean
         2. Create a new "false min/max" at N std-deviations above and below the mean
         3. consider each pixel in the original image:
            a. if its value is below or equal to the false min, send it to zero (or whatever the min for the band is)
            b. if its value is greater than or equal to the false max, send it to 255 (or whatever the max for the band is)
            c. if its value is between the false-min and false-max, its new value is (total pixel range/ (false max - false min)) * (pixel val - false min) -- basically you're "stretching" the values between the false min/max into the space of the whole color-range
        Show
        Saul Farber added a comment - Gabriel, No, this is not quite the same thing, although it's close. I believe the code to look at is ContrastEnhancementNode.java. ContrastEnhancementNode defines a number of allowed "contrast enhancement" types. To solve this bug, a new contrast enhancement type needs to be added called (roughly) "histogram-mean-stretch" which will also take a parameter, the number of std devs to stretch by (not sure how to tie this into the SLD render, perhaps as an attribute? operation="HISTOGRAM-MEAN-STRETCH" stdevs="2") The implementation will do the following calculation for each band:  1. Calculate the mean value across all pixels in the image, as well as the std devation around that mean  2. Create a new "false min/max" at N std-deviations above and below the mean  3. consider each pixel in the original image:     a. if its value is below or equal to the false min, send it to zero (or whatever the min for the band is)     b. if its value is greater than or equal to the false max, send it to 255 (or whatever the max for the band is)     c. if its value is between the false-min and false-max, its new value is (total pixel range/ (false max - false min)) * (pixel val - false min) -- basically you're "stretching" the values between the false min/max into the space of the whole color-range
        Simone Giannecchini made changes -
        Assignee Saul Farber [ saul.farber ] Simone Giannecchini [ simboss ]
        Simone Giannecchini made changes -
        Priority Major [ 3 ] Minor [ 4 ]
        Fix Version/s 2.4.6 [ 14552 ]
        Jody Garnett made changes -
        Fix Version/s 2.7-M0 [ 15891 ]
        Jody Garnett made changes -
        Fix Version/s 2.7-M1 [ 16521 ]
        Fix Version/s 2.7-M0 [ 15891 ]
        Jody Garnett made changes -
        Fix Version/s 2.7-RC1 [ 16571 ]
        Fix Version/s 2.7-M1 [ 16521 ]
        Jody Garnett made changes -
        Fix Version/s 2.7-M3 [ 16572 ]
        Fix Version/s 2.7-M2 [ 16571 ]
        Justin Deoliveira made changes -
        Fix Version/s 2.7-M4 [ 16726 ]
        Fix Version/s 2.7-M3 [ 16572 ]
        Andrea Aime made changes -
        Fix Version/s 2.7-beta1 [ 16974 ]
        Fix Version/s 2.7-M4 [ 16726 ]
        Justin Deoliveira made changes -
        Fix Version/s 2.7-RC1 [ 17076 ]
        Fix Version/s 2.7-beta1 [ 16974 ]
        Justin Deoliveira made changes -
        Fix Version/s 2.7.0 [ 17109 ]
        Fix Version/s 2.7-RC1 [ 17076 ]
        Justin Deoliveira made changes -
        Fix Version/s 2.7.1 [ 17255 ]
        Fix Version/s 2.7.0 [ 17109 ]
        Simone Giannecchini made changes -
        Fix Version/s 2.7.1 [ 17255 ]

          People

          • Assignee:
            Simone Giannecchini
            Reporter:
            Saul Farber
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: