cogeotiff / rio-tiler

User friendly Rasterio plugin to read raster datasets.
https://cogeotiff.github.io/rio-tiler/
BSD 3-Clause "New" or "Revised" License
511 stars 106 forks source link

Why do I get a tile and I get a black border on the border #362

Closed githubhanjunjun closed 3 years ago

githubhanjunjun commented 3 years ago

213432 Snipaste_2021-03-15_14-33-21

1.Version: rio-tiler2.0.0 2. API : cog.tile() 3. code: indexes = non_alpha_indexes(cog.dataset) # indexes = (1, 2, 3) nodata = 0 resampling="nearest" tile, mask = cog.tile(x, y, z, indexes=indexes, tilesize=tilesize, nodata=nodata, resampling_method=resampling) How can I solve this problem? Please help me.

vincentsarago commented 3 years ago

@githubhanjunjun because you are using jpeg compression with nodata. Fix: use internal mask or lossless compression

githubhanjunjun commented 3 years ago

@githubhanjunjun because you are using jpeg compression with nodata. Fix: use internal mask or lossless compression

Thank you very much for your answer.

  1. 'lossless compression' means set 'nodata=None', right?
  2. 'use internal mask' means use the mask in the code below, right? tile, mask = cog.tile(x, y, z, indexes=indexes, tilesize=tilesize, nodata=nodata, resampling_method=resampling)
kylebarron commented 3 years ago

@vincentsarago 's suggestion was to change your data not your code. I think the point is that there's nothing you can do about the black portions because the data was saved with lossy compression and without an internal mask.

vincentsarago commented 3 years ago
  1. 'lossless compression' means set 'nodata=None', right?

No, I mean: I'm assuming your data is compressed using JPEG. the back artefacts are created because of a nodata (0) being compressed using non-lossless compression (jpeg). So if you are asking if you should create your input file without nodata value set: Yes.

  1. 'use internal mask' means use the mask in the code below, right? tile, mask = cog.tile(x, y, z, indexes=indexes, tilesize=tilesize, nodata=nodata, resampling_method=resampling)

No I meant: create your input file using internal mask, not nodata value

githubhanjunjun commented 3 years ago
  1. 'lossless compression' means set 'nodata=None', right?

No, I mean: I'm assuming your data is compressed using JPEG. the back artefacts are created because of a nodata (0) being compressed using non-lossless compression (jpeg). So if you are asking if you should create your input file without nodata value set: Yes.

  1. 'use internal mask' means use the mask in the code below, right? tile, mask = cog.tile(x, y, z, indexes=indexes, tilesize=tilesize, nodata=nodata, resampling_method=resampling)

No I meant: create your input file using internal mask, not nodata value

I see what you mean. Thank you very much for your answer. Please forgive me that my English is not very good. I can get better results by setting 'noData =None' Snipaste_2021-03-16_09-39-06

githubhanjunjun commented 3 years ago

@vincentsarago 's suggestion was to change your data not your code. I think the point is that there's nothing you can do about the black portions because the data was saved with lossy compression and without an internal mask.

Thank you for your reply. My data is indeed JPEG compressed

vincentsarago commented 3 years ago

not sure where your input data is from but if you have access to the uncompressed data you could create a COG with JPEG compression and internal mask

using rio-cogeo

$ rio cogeo create myinput.tif mycog.tif -p jpeg --add-mask

if you want to use GDAL commands (with the new COG driver), I think you'll need to first translate the nodata value to a mask band

githubhanjunjun commented 3 years ago

not sure where your input data is from but if you have access to the data you could create a COG with JPEG compression and internal maskuncompressed

using rio-cogeo

$ rio cogeo create myinput.tif mycog.tif -p jpeg --add-mask

if you want to use GDAL commands (with the new COG driver), I think you'll need to first translate the nodata value to a mask band

My data was generated by ODM, and I compressed the results with JPEG. I can get rid of the compression code. Thank you very much for your advice