[mapserver-users] Resampling and image quality?

Frank Warmerdam warmerdam at pobox.com
Fri Mar 28 00:45:32 EDT 2008


Gregor Mosheh wrote:
> Hi, all. We're seeing some distortion in an image, a loss of viewing 
> quality, and am hoping that y'all can provide some insight into what may 
> be the issue.
> 
> Here are the URLs:
>    http://dev.geowake.com/chart.test/index.php
>    http://ms2.geowake.com/
> Yes, it's Google Maps, but bear with me. :)
> The "dev" one is using a PNG sliced for use in Google Maps.
> The "ms2" one is Mapserver WMS, using the same PNG but with a worldfile 
> and without slicing since the idea here is to use WMS and save a lot of 
> work as well as being vendor-neutral.

Gregor,

Thanks for the direct pngs.

I know it is was really obvious to you, but there wasn't enough of the
maps paged in before I started zooming for me to even realize there was
a subregion that was different.

> You'll see that the "dev" one has a much "smoother" look to it. If you 
> zoom in three notches, you can read the map's title clearly. The 
> Mapserver WMS version, the text is very obviously blocky even if you 
> zoom in 4 notches. As you keep zooming in, the quality difference 
> becomes more obvious as you can read the PNG's smaller text but not the 
> WMS's.
> 
> 
> So, what to do? I have tried and eliminated several possibilities, and 
> am stumped.
> 
> - Source image quality; the PNGs on both sides are visually identical in 
> an image viewer. I have tried the source image in TIFF and PNG with 
> various options.
> 
> - Bad world file; the spatial extent matches that of the other map, and 
> I've checked the math repeatedly and found it A-OK
> 
> - Image format options; I have tried every image format supported, and 
> the image always comes out looking the same, so it's not interlacing 
> gone wrong, nor lossy JPEG compression, etc. The outputformat block is 
> set to generate PNG-24 RGBA, and I have verified by downloading from the 
> WMS that it is doing so.
> 
> Possibilities I've not yet exhausted:
> 
> - Resampling; using PROCESSING "RESAMPLE=AVERAGE" improved the image 
> quality but only very slightly.
> 
> - Reprojection; the images are in WGS84 (EPSG 4326) and I know that 
> Google uses their weird Mercator (54004). I added 54004 to our EPSG 
> file, and have tried various approaches such as reprojecting the image 
> to 54004 ahead of time, and using 54004's numbers in a worldfile so 
> there'd be no reprojection at all, but the effect is always the same.

I guess I don't get the process that the nice image is going through.
Are you having to pre-reproject it to Mercator before slicing it
up for the exact Google maps zoom levels?  Or do you just provide
it in 4326 and google maps takes care of reprojecting it?

Are the source PNGs paletted or RGB 24bit?  Paletted images won't
respond well to alternative resampling algorithms.  I'm guessing
that the nice images are effectively bilinearly interpolated in
RGB space though I'm not clear on where that is happening.
Selecting PROCESSING "RESAMPLE=BILINEAR" and giving it 24bit RGB
input files should give something fairly similar I'd think.

One problem is that Mapserver actually leaves it to GDAL to do much
of the downsampling in highly decimated situations.  So it is also
important to build overview levels in some appropriate fashion.
Likely you will need to do this with -r average for gdaladdo.

It *might* be possible to fool with the OVERSAMPLE_RATIO processing
option in your map to give a better bilinear resampling without
having to pre-build overviews.  This might also improve the appearance
of average resampling.  Something like:

   PROCESSING "OVERSAMPLE_RATIO=16"

But basically, resampling fine text like this (or delicate linework)
from a raster source is just a crappy situation to be in.  Even the
good results are pretty crappy in my opinion.

Good luck,
-- 
---------------------------------------+--------------------------------------
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