[Geoserver-users] WMS Raster Interpolation - Data vs Rendered Image

I have a question related to interpolation of raster data in a WMS. In an oversampling situation, where I am zoomed in past the native resolution of my data, what exactly is interpolated? The rendered image or the source data?

For instance, I have a single banded geotiff that contains gridded data values (not RGB colors) to which I apply a ColorMap within an SLD.

When interpolation (bilinear, cubic, etc.) is applied, is the interpolation applied to the full-color RGB output image after styling is applied or to the source data from the single banded geotiff before the ColorMap is applied?

I am thinking it is applied to the full-color RGB after applying the ColorMap, because the only real outcome I see is more of a blurring, which I expect if now all 3 RGB bands are being interpolated and then added back together. This is because I am now interpolating colors, not data, right?

If the underlying data were being interpolated first, and then the ColorMap applied, wouldn’t I expect more of a smoothing, rather than blurring, outcome to the interpolation?

It is this smoothing of the single band source data, rather than interpolation of expanded RGB output after the map is applied, that I am after when I am oversampling … or zoomed in past the native resolution of my gridded data.

Is there a way to accomplish this in GeoServer?

Are there major holes in my assumptions above and/or am I just not thinking about this clearly?

Thanks again,

Mike Grogan

Since there is no response yet (which is ok - not trying to be pushy) … I worried that maybe I didn’t explain this well enough. So, I generated an example of what I am talking about outside of GeoServer and attached it here.

The left part of the image shows what happens if I scale and interpolate the resultant IMAGE after categorized styling (i.e. a ColorMap) is applied. It just becomes blurry and hard to look at.

The right part of the image shows what happens if I scale and interpolate the DATA and then apply styling (i.e. a ColorMap). It’s a much more pleasing, smoothing effect.

Is there any way to get this behavior out of GeoServer? Would I need to go the route of a writing a custom WPS to do this?

(For reference, the underlying data is weather radar reflectivity data).

Thanks again,

Mike Grogan

interpolation_order.png

···

On Tue, Apr 8, 2014 at 10:34 PM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

I have a question related to interpolation of raster data in a WMS. In an oversampling situation, where I am zoomed in past the native resolution of my data, what exactly is interpolated? The rendered image or the source data?

For instance, I have a single banded geotiff that contains gridded data values (not RGB colors) to which I apply a ColorMap within an SLD.

When interpolation (bilinear, cubic, etc.) is applied, is the interpolation applied to the full-color RGB output image after styling is applied or to the source data from the single banded geotiff before the ColorMap is applied?

I am thinking it is applied to the full-color RGB after applying the ColorMap, because the only real outcome I see is more of a blurring, which I expect if now all 3 RGB bands are being interpolated and then added back together. This is because I am now interpolating colors, not data, right?

If the underlying data were being interpolated first, and then the ColorMap applied, wouldn’t I expect more of a smoothing, rather than blurring, outcome to the interpolation?

It is this smoothing of the single band source data, rather than interpolation of expanded RGB output after the map is applied, that I am after when I am oversampling … or zoomed in past the native resolution of my gridded data.

Is there a way to accomplish this in GeoServer?

Are there major holes in my assumptions above and/or am I just not thinking about this clearly?

Thanks again,

Mike Grogan

[Sorry, not trying to intentionally bump, but I think there may have been a problem with my second post in this thread due to image attachment size … so I have linked to it instead. My second post just showed up blank on sourceforge. Original second post below.]

Since there is no response yet (which is ok - not trying to be pushy) … I worried that maybe I didn’t explain this well enough. So, I generated an example of what I am talking about outside of GeoServer and uploaded it here:

http://imgur.com/3YdvfXI

The left part of the image shows what happens if I scale and interpolate the resultant IMAGE after categorized styling (i.e. a ColorMap) is applied. It just becomes blurry and hard to look at.

The right part of the image shows what happens if I scale and interpolate the DATA and then apply styling (i.e. a ColorMap). It’s a much more pleasing, smoothing effect.

Is there any way to get this behavior out of GeoServer? Would I need to go the route of a writing a custom WPS to do this?

(For reference, the underlying data is weather radar reflectivity data).

Thanks again,

Mike Grogan

···

On Thu, Apr 10, 2014 at 4:59 PM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

Since there is no response yet (which is ok - not trying to be pushy) … I worried that maybe I didn’t explain this well enough. So, I generated an example of what I am talking about outside of GeoServer and attached it here.

The left part of the image shows what happens if I scale and interpolate the resultant IMAGE after categorized styling (i.e. a ColorMap) is applied. It just becomes blurry and hard to look at.

The right part of the image shows what happens if I scale and interpolate the DATA and then apply styling (i.e. a ColorMap). It’s a much more pleasing, smoothing effect.

Is there any way to get this behavior out of GeoServer? Would I need to go the route of a writing a custom WPS to do this?

(For reference, the underlying data is weather radar reflectivity data).

Thanks again,

Mike Grogan

On Tue, Apr 8, 2014 at 10:34 PM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

I have a question related to interpolation of raster data in a WMS. In an oversampling situation, where I am zoomed in past the native resolution of my data, what exactly is interpolated? The rendered image or the source data?

For instance, I have a single banded geotiff that contains gridded data values (not RGB colors) to which I apply a ColorMap within an SLD.

When interpolation (bilinear, cubic, etc.) is applied, is the interpolation applied to the full-color RGB output image after styling is applied or to the source data from the single banded geotiff before the ColorMap is applied?

I am thinking it is applied to the full-color RGB after applying the ColorMap, because the only real outcome I see is more of a blurring, which I expect if now all 3 RGB bands are being interpolated and then added back together. This is because I am now interpolating colors, not data, right?

If the underlying data were being interpolated first, and then the ColorMap applied, wouldn’t I expect more of a smoothing, rather than blurring, outcome to the interpolation?

It is this smoothing of the single band source data, rather than interpolation of expanded RGB output after the map is applied, that I am after when I am oversampling … or zoomed in past the native resolution of my gridded data.

Is there a way to accomplish this in GeoServer?

Are there major holes in my assumptions above and/or am I just not thinking about this clearly?

Thanks again,

Mike Grogan

I believe the source data, since we want it to work with non colour information such as elevation.

···

Jody Garnett

On Wed, Apr 9, 2014 at 12:34 PM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

I have a question related to interpolation of raster data in a WMS. In an oversampling situation, where I am zoomed in past the native resolution of my data, what exactly is interpolated? The rendered image or the source data?

For instance, I have a single banded geotiff that contains gridded data values (not RGB colors) to which I apply a ColorMap within an SLD.

When interpolation (bilinear, cubic, etc.) is applied, is the interpolation applied to the full-color RGB output image after styling is applied or to the source data from the single banded geotiff before the ColorMap is applied?

I am thinking it is applied to the full-color RGB after applying the ColorMap, because the only real outcome I see is more of a blurring, which I expect if now all 3 RGB bands are being interpolated and then added back together. This is because I am now interpolating colors, not data, right?

If the underlying data were being interpolated first, and then the ColorMap applied, wouldn’t I expect more of a smoothing, rather than blurring, outcome to the interpolation?

It is this smoothing of the single band source data, rather than interpolation of expanded RGB output after the map is applied, that I am after when I am oversampling … or zoomed in past the native resolution of my gridded data.

Is there a way to accomplish this in GeoServer?

Are there major holes in my assumptions above and/or am I just not thinking about this clearly?

Thanks again,

Mike Grogan


Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees


Geoserver-users mailing list
Geoserver-users@anonymised.comsts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Jody,

Thanks for responding. I would hope it would be of the source data for the very reason you mention, but the resulting output when interpolation is enabled for WMS looks blurred (like the resulting image has been scaled then interpolated) rather than smooth (like the source data has been scaled and interpolated).

(See my follow-up post where I show the differences … my GeoServer outputs look like the left part of the image, not the right part. )

Where should I dig in the source to figure out the order for sure … or see what I might be doing wrong?

Thanks,

Mike

···

On Fri, Apr 11, 2014 at 9:59 AM, Jody Garnett <jody.garnett@anonymised.com> wrote:

I believe the source data, since we want it to work with non colour information such as elevation.

Jody Garnett

On Wed, Apr 9, 2014 at 12:34 PM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

I have a question related to interpolation of raster data in a WMS. In an oversampling situation, where I am zoomed in past the native resolution of my data, what exactly is interpolated? The rendered image or the source data?

For instance, I have a single banded geotiff that contains gridded data values (not RGB colors) to which I apply a ColorMap within an SLD.

When interpolation (bilinear, cubic, etc.) is applied, is the interpolation applied to the full-color RGB output image after styling is applied or to the source data from the single banded geotiff before the ColorMap is applied?

I am thinking it is applied to the full-color RGB after applying the ColorMap, because the only real outcome I see is more of a blurring, which I expect if now all 3 RGB bands are being interpolated and then added back together. This is because I am now interpolating colors, not data, right?

If the underlying data were being interpolated first, and then the ColorMap applied, wouldn’t I expect more of a smoothing, rather than blurring, outcome to the interpolation?

It is this smoothing of the single band source data, rather than interpolation of expanded RGB output after the map is applied, that I am after when I am oversampling … or zoomed in past the native resolution of my gridded data.

Is there a way to accomplish this in GeoServer?

Are there major holes in my assumptions above and/or am I just not thinking about this clearly?

Thanks again,

Mike Grogan


Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees


Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

I have done some extended analysis on this, and it still looks like GeoServer is scaling and interpolating the resulting IMAGE rather than the underlying DATA for WMS requests and a WMS “bilinear” interpolation setting.

Here are the steps in my extended analysis:

  1. I wanted to remove anything that I was doing with my gridded dataset … and any differences I have from a “stock” GeoServer install … from the equation.

  2. I installed a completely stock GeoServer 2.5 instance and worked with the included sample nurc:Arc_Sample Layer from the arcGridSample datastore.

  3. Since the example style (rain) only had four entries, I created expanded ColorMaps, one as an “interval”, and another as a “ramp”.

  4. I made WMS requests for both, and all I got when zoomed in is a blurry mess.

  5. I copied the source data (file:coverages/arc_sample/precip30min.asc) over to ArcMap, which I know interpolates the DATA first for bilinear interpolation, not the image.

  6. I recreated the SLD from GeoServer as my Symbology in ArcMap.

  7. I created the comparisons below, both for an “interval” ColorMap and a “ramp” ColorMap, for the same bounding box and approx. the same image size.

The left part of the images below are from GeoServer, the right part of the images are from ArcMap.

This is for the “interval” ColorMap:

http://i.imgur.com/kcWp3bN.png

http://imgur.com/kcWp3bN

This is for the “ramp” ColorMap:

http://i.imgur.com/y4JBTxF.png

http://imgur.com/y4JBTxF

Now, yes, I know I am comparing two different products, but what I am really showing, I think, is that GeoServer is not interpolating the DATA first but rather the resulting IMAGE.

As Jody notes, “I believe the source data, since we want it to work with non colour information such as elevation.”

But, it looks like is is not. It looks like just the resulting IMAGE after the color map is applied is being put through JAI interpolation or something.

Again, anyone, please point out any flaws in my approach …

Am I doing something wrong?

Has interpolating the DATA never been the intended approach for GeoServer?

How can I get GeoServer to interpolate the DATA first, as shown in the ArcMap examples? A custom WPS? Something else?

Thanks !!

  • Mike Grogan
···

On Fri, Apr 11, 2014 at 10:13 AM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

Jody,

Thanks for responding. I would hope it would be of the source data for the very reason you mention, but the resulting output when interpolation is enabled for WMS looks blurred (like the resulting image has been scaled then interpolated) rather than smooth (like the source data has been scaled and interpolated).

(See my follow-up post where I show the differences … my GeoServer outputs look like the left part of the image, not the right part. )

Where should I dig in the source to figure out the order for sure … or see what I might be doing wrong?

Thanks,

Mike

On Fri, Apr 11, 2014 at 9:59 AM, Jody Garnett <jody.garnett@anonymised.com> wrote:

I believe the source data, since we want it to work with non colour information such as elevation.

Jody Garnett

On Wed, Apr 9, 2014 at 12:34 PM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

I have a question related to interpolation of raster data in a WMS. In an oversampling situation, where I am zoomed in past the native resolution of my data, what exactly is interpolated? The rendered image or the source data?

For instance, I have a single banded geotiff that contains gridded data values (not RGB colors) to which I apply a ColorMap within an SLD.

When interpolation (bilinear, cubic, etc.) is applied, is the interpolation applied to the full-color RGB output image after styling is applied or to the source data from the single banded geotiff before the ColorMap is applied?

I am thinking it is applied to the full-color RGB after applying the ColorMap, because the only real outcome I see is more of a blurring, which I expect if now all 3 RGB bands are being interpolated and then added back together. This is because I am now interpolating colors, not data, right?

If the underlying data were being interpolated first, and then the ColorMap applied, wouldn’t I expect more of a smoothing, rather than blurring, outcome to the interpolation?

It is this smoothing of the single band source data, rather than interpolation of expanded RGB output after the map is applied, that I am after when I am oversampling … or zoomed in past the native resolution of my gridded data.

Is there a way to accomplish this in GeoServer?

Are there major holes in my assumptions above and/or am I just not thinking about this clearly?

Thanks again,

Mike Grogan


Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees


Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

It may be a case of reviewing the order in which image processing operations are applied in the rendering code. I also encourage you to look at the different interpolation settings in the hopes they can offer you greater clarity on what is occurring.

Read: https://github.com/geotools/geotools/blob/master/modules/library/render/src/main/java/org/geotools/renderer/lite/gridcoverage2d/GridCoverageRenderer.java

In particular the comments are very extensive and describe what is being set up.

Note we are using Java Advanced Imaging here, setting up a chain of operations which are then in charge of processing the content as we request the final image.

This class is used when raster content is being used along with vector data. GeoServer also has an optimisation when a single raster is being displayed on its own (which more more like a straight crop). The two execution paths may be slightly different … not sure.

···

Jody Garnett

On Sat, Apr 12, 2014 at 2:45 AM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

I have done some extended analysis on this, and it still looks like GeoServer is scaling and interpolating the resulting IMAGE rather than the underlying DATA for WMS requests and a WMS “bilinear” interpolation setting.

Here are the steps in my extended analysis:

  1. I wanted to remove anything that I was doing with my gridded dataset … and any differences I have from a “stock” GeoServer install … from the equation.

  2. I installed a completely stock GeoServer 2.5 instance and worked with the included sample nurc:Arc_Sample Layer from the arcGridSample datastore.

  3. Since the example style (rain) only had four entries, I created expanded ColorMaps, one as an “interval”, and another as a “ramp”.

  4. I made WMS requests for both, and all I got when zoomed in is a blurry mess.

  5. I copied the source data (file:coverages/arc_sample/precip30min.asc) over to ArcMap, which I know interpolates the DATA first for bilinear interpolation, not the image.

  6. I recreated the SLD from GeoServer as my Symbology in ArcMap.

  7. I created the comparisons below, both for an “interval” ColorMap and a “ramp” ColorMap, for the same bounding box and approx. the same image size.

The left part of the images below are from GeoServer, the right part of the images are from ArcMap.

This is for the “interval” ColorMap:

http://i.imgur.com/kcWp3bN.png

http://imgur.com/kcWp3bN

This is for the “ramp” ColorMap:

http://i.imgur.com/y4JBTxF.png

http://imgur.com/y4JBTxF

Now, yes, I know I am comparing two different products, but what I am really showing, I think, is that GeoServer is not interpolating the DATA first but rather the resulting IMAGE.

As Jody notes, “I believe the source data, since we want it to work with non colour information such as elevation.”

But, it looks like is is not. It looks like just the resulting IMAGE after the color map is applied is being put through JAI interpolation or something.

Again, anyone, please point out any flaws in my approach …

Am I doing something wrong?

Has interpolating the DATA never been the intended approach for GeoServer?

How can I get GeoServer to interpolate the DATA first, as shown in the ArcMap examples? A custom WPS? Something else?

Thanks !!

  • Mike Grogan

On Fri, Apr 11, 2014 at 10:13 AM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

Jody,

Thanks for responding. I would hope it would be of the source data for the very reason you mention, but the resulting output when interpolation is enabled for WMS looks blurred (like the resulting image has been scaled then interpolated) rather than smooth (like the source data has been scaled and interpolated).

(See my follow-up post where I show the differences … my GeoServer outputs look like the left part of the image, not the right part. )

Where should I dig in the source to figure out the order for sure … or see what I might be doing wrong?

Thanks,

Mike

On Fri, Apr 11, 2014 at 9:59 AM, Jody Garnett <jody.garnett@anonymised.com> wrote:

I believe the source data, since we want it to work with non colour information such as elevation.

Jody Garnett

On Wed, Apr 9, 2014 at 12:34 PM, Mike Grogan <d.michael.grogan@anonymised.com> wrote:

I have a question related to interpolation of raster data in a WMS. In an oversampling situation, where I am zoomed in past the native resolution of my data, what exactly is interpolated? The rendered image or the source data?

For instance, I have a single banded geotiff that contains gridded data values (not RGB colors) to which I apply a ColorMap within an SLD.

When interpolation (bilinear, cubic, etc.) is applied, is the interpolation applied to the full-color RGB output image after styling is applied or to the source data from the single banded geotiff before the ColorMap is applied?

I am thinking it is applied to the full-color RGB after applying the ColorMap, because the only real outcome I see is more of a blurring, which I expect if now all 3 RGB bands are being interpolated and then added back together. This is because I am now interpolating colors, not data, right?

If the underlying data were being interpolated first, and then the ColorMap applied, wouldn’t I expect more of a smoothing, rather than blurring, outcome to the interpolation?

It is this smoothing of the single band source data, rather than interpolation of expanded RGB output after the map is applied, that I am after when I am oversampling … or zoomed in past the native resolution of my gridded data.

Is there a way to accomplish this in GeoServer?

Are there major holes in my assumptions above and/or am I just not thinking about this clearly?

Thanks again,

Mike Grogan


Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees


Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Hi,
I’ve checked what the current code does by using the RenderedImageBrowser, a utility we use to show
a JAI image processing chain.

Indeed the image gets rescaled after the raster color map is applied, thus it is being rescaled in
RGB format, not against native data:

Inline image 1

All the code is indeed in GridCoverageRenderer, including the affine transformation that adds the scale operation in the chain
(the mosaic one is done in GeoServer, it’s actually done to crop the image in this case, but with more control than the crop operation).

I guess we could try to rescale the coverage before appling the raster symbolizer… but it’s not simple due to a few reasons:

  • at that point we have to rescale a GridCoverage2D, not a RendererImage, and we don’t have a general Affine operation for
    grid coverages, but just a Scale (so we’d be able to work it only in the simple case where the original raster has no rotational factors,
    and leave the current code path for rotated rasters, making the current code messier…)
  • we’d have to test a wide range of color/sample models to make sure the code works in at least the common cases (single and
    multibanded byte/int/short/float/double cases)

Long story short, this kind of change is not without risks, requires some base development to be done, a good amount of testing
after it’s done with an array of input imagery types, so it would probably need some funding to be carried on

Cheers
Andrea

···

==
Meet us at GEO Business 2014! in London! Visit http://goo.gl/fES3aK
for more information.

Ing. Andrea Aime

@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it


Thanks for confirming my suspicions. I know there would be some development work, but I hope you agree the interpolation should really be done on the data, not the resulting RGB image. As Jody pointed out, this is really what you want for elevation data, etc. Should I / may I open a JIRA as a Feature Request just to log this for the future?

In the interim, I have been able to accomplish this, at least tentatively, for my own purposes and want to see if you see any holes in my approach:

Here is output from GeoServer … and you can compare to my previous screen shots in this thread:

http://i.imgur.com/twqDa0r.png

http://imgur.com/twqDa0r

You’ll notice this is the Arc_Sample precip layer with the DATA interpolated, instead of the IMAGE.

Thus far, I have implemented this as a Custom Rendering Transformation WPS that does the following:

  1. Takes a GridCoverage2D along with output bounding box, width, and height as parameters.
  2. Crops the input GridCoverage2D to the output bounding box.
  3. Scales (within limits) the cropped GridCoverage2D based on its size compared to the size of the output width/height.
  4. Applies Bilinear interpolation while scaling in #3.
  5. Returns a scaled and bilinear interpolated GridCoverage2D to which a ColorMap is then applied in the SLD.

Any major holes in my approach? Things to consider or check?

Obviously I want to add some more input validation, etc.

One immediate thing I see is the need to perhaps crop a little larger than my output BBOX so I don’t see issues with discrepancies along tile boundaries.

Something else I thought of is that the WPS-style approach also lets people choose a per-layer WMS interpolation method, as has been requested in other threads.

Thanks,

Mike Grogan

image.png

···

On Sun, Apr 13, 2014 at 4:20 AM, Andrea Aime <andrea.aime@anonymised.com> wrote:

Hi,
I’ve checked what the current code does by using the RenderedImageBrowser, a utility we use to show
a JAI image processing chain.

Indeed the image gets rescaled after the raster color map is applied, thus it is being rescaled in
RGB format, not against native data:

Inline image 1

All the code is indeed in GridCoverageRenderer, including the affine transformation that adds the scale operation in the chain
(the mosaic one is done in GeoServer, it’s actually done to crop the image in this case, but with more control than the crop operation).

I guess we could try to rescale the coverage before appling the raster symbolizer… but it’s not simple due to a few reasons:

  • at that point we have to rescale a GridCoverage2D, not a RendererImage, and we don’t have a general Affine operation for
    grid coverages, but just a Scale (so we’d be able to work it only in the simple case where the original raster has no rotational factors,
    and leave the current code path for rotated rasters, making the current code messier…)
  • we’d have to test a wide range of color/sample models to make sure the code works in at least the common cases (single and
    multibanded byte/int/short/float/double cases)

Long story short, this kind of change is not without risks, requires some base development to be done, a good amount of testing
after it’s done with an array of input imagery types, so it would probably need some funding to be carried on

Cheers
Andrea

==
Meet us at GEO Business 2014! in London! Visit http://goo.gl/fES3aK
for more information.

Ing. Andrea Aime

@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it