[mapserver-users] SCALE=AUTO applied to current view or entire layer?

Frank Warmerdam warmerdam at pobox.com
Wed Jul 23 20:42:05 EDT 2008


John Maurer wrote:
> Dear MapServer users,
> When applying the PROCESSING directive "SCALE=AUTO" to a RASTER layer in 
> MapServer, I was hoping this would apply a suitable contrast stretch for 
> the currently selected spatial extent of the layer. But it seems that 
> the contrast stretch is being applied to the entire layer regardless of 
> where I am zoomed into. This means for a file with a large dynamic range 
> that when zooming in to some areas, the contrast stretch is quite 
> horrible (e.g. mostly gray tones or mostly dark tones or mostly light 
> tones). My laborious workaround has been to create separate layers for 
> the same raster data file with separate contrast stretches ranging from 
> ultra-high contrast to ultra-low contrast using different 
> "SCALE=min,max" settings. Is there a better way?? What is needed is a 
> way for MapServer to apply an automatic contrast stretch to the current 
> map view for the selected raster layer. You can get this kind of feature 
> in many image processing applications (e.g. ENVI) so it would be 
> fantastic to have this in MapServer as well. Thanks for any help!

John,

I'm quite surprised at the behavior you report.  MapServer *should* be
computing a minimum and maximum for scaling purposes based on the data
loaded for the particular map draw request, not the layer as a whole.

I've just reviewed the code, and that is what it calls for.  Is it possible
you have a few pixels which are quite different from the rest in the render
areas?  This will result in inappropriately broad dynamic ranges.  In
particular the autoscaling does not doing anything like histogram tail
trimming when coming up with the min/max to use.

You might want to enable debugging for the layer, and check the
"scaling to 8bit, src range=..." reports to see if it really is using the
same min/max everywhere.

I *suspect* you need smarter min/max computation using histogram tail trimming
but doing this runs the risk of slowing things down noticably.

PS. the code for autoscaling is in mapdrawgdal.c and looks like this:

/* -------------------------------------------------------------------- */
/*      If we are using autoscaling, then compute the max and min       */
/*      now.  Perhaps we should eventually honour the offsite value     */
/*      as a nodata value, or get it from GDAL.                         */
/* -------------------------------------------------------------------- */
     if( dfScaleMin == dfScaleMax )
     {
         dfScaleMin = dfScaleMax = pafRawData[0];

         for( i = 1; i < nPixelCount; i++ )
         {
             dfScaleMin = MIN(dfScaleMin,pafRawData[i]);
             dfScaleMax = MAX(dfScaleMax,pafRawData[i]);
         }
         if( dfScaleMin == dfScaleMax )
             dfScaleMax = dfScaleMin + 1.0;
     }

     if( layer->debug > 0 )
         msDebug( "msDrawGDAL(%s): scaling to 8bit, src range=%g,%g\n",
                  layer->name, dfScaleMin, dfScaleMax );

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the mapserver-users mailing list