Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-507] RS_AsImage and RS_AsPNG could properly handle non-integral band data #1258

Merged
merged 1 commit into from
Feb 28, 2024

Conversation

Kontinuation
Copy link
Member

@Kontinuation Kontinuation commented Feb 27, 2024

Did you read the Contributor Guide?

Is this PR related to a JIRA ticket?

What changes were proposed in this PR?

RS_AsImage only produces PNG images for rasters with integral band data, and produces TIFF images for rasters with floating point band data. TIFF cannot be displayed on many mainstream browsers, so we should not use TIFF to visualize rasters.

This PR make RS_AsPNG work for all types of band data, so that RS_AsImage won't produce TIFF base64 output.

  • If the band data type is byte, we try converting it to PNG directly. This will preserve the original color of the raster if the raster is RGB or using a color table
  • If the raster has one single band, we normalize the band data to 0~255 and generate a grayscale image, with nodata pixels masked as transparent
  • Otherwise we use the color model to translate pixel values to RGB value, and generate an RGB image.

How was this patch tested?

  • Tested locally on various rasters to make sure that they are displayed properly.
  • Added a smoke test to make sure that it does not break when processing rasters with various band data types

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the docs.

@Kontinuation Kontinuation marked this pull request as ready for review February 28, 2024 02:01
@jiayuasu
Copy link
Member

@Kontinuation

  1. With the normalization in this function, does a user still need to call RS_NormalizeAll to normalize an image (values not within 0 - 255) before calling AsImage?
  2. When a raster has > 3 bands, I assume this will take the first 3 bands for visualization?

@Kontinuation
Copy link
Member Author

@Kontinuation

  1. With the normalization in this function, does a user still need to call RS_NormalizeAll to normalize an image (values not within 0 - 255) before calling AsImage?
  2. When a raster has > 3 bands, I assume this will take the first 3 bands for visualization?
  1. No. The RS_AsImage will do the normalization by itself.
  2. It depends on the color model of the raster. For RGB rasters it works properly, for rasters such as EuroSAT it does not work well. We may need to revisit how to deal with multi-band rasters later.

@jiayuasu
Copy link
Member

@Kontinuation What will happen exactly when it comes to EuroSat images?

@Kontinuation
Copy link
Member Author

Kontinuation commented Feb 28, 2024

@Kontinuation What will happen exactly when it comes to EuroSat images?

The generated PNG image is mostly black, while visualizing one single band looks OK.
image

@jiayuasu jiayuasu merged commit 244122f into apache:master Feb 28, 2024
49 checks passed
jiayuasu pushed a commit that referenced this pull request Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants