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

Workaround to overcome JPEG 2000 issue #139

Closed
wants to merge 1 commit into from

Conversation

drnextgis
Copy link
Contributor

@drnextgis drnextgis commented Aug 30, 2018

Fix cropping for JPEG 2000 images.

@drnextgis drnextgis force-pushed the crop_mask branch 3 times, most recently from f764fc0 to 4eba751 Compare August 30, 2018 06:30
@codecov-io
Copy link

codecov-io commented Aug 30, 2018

Codecov Report

Merging #139 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #139      +/-   ##
==========================================
+ Coverage   89.41%   89.43%   +0.01%     
==========================================
  Files          30       30              
  Lines        4279     4287       +8     
==========================================
+ Hits         3826     3834       +8     
  Misses        453      453
Impacted Files Coverage Δ
telluric/georaster.py 92.57% <100%> (+0.01%) ⬆️
tests/test_georaster.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d5743a...274442f. Read the comment docs.

@drnextgis drnextgis changed the title New masked_value parameter for cropping Workaround to overcome JPEG 2000 issue Aug 31, 2018

# HACK: We have to overcome https://github.com/mapbox/rasterio/issues/1449 here
if self._filename.endswith('.jp2'):
masked = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if mask is false, and in the orginal there existed a mask, we are not supporting this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.jp2 doesn't support internal mask, so one of the possible way to mask all pixels that extend beyond the dataset's extent is overwriting masked to False: in this case crop returns np.core.ndarray and GeoRaster constructor converts it to masked array here. The drawback of this approach is that we masks legitimate 0 value pixels as well. The same issue you can observe while cropping GeoTIFF which doesn't contain any mask (internal, alpha or nodata).

@astrojuanlu
Copy link
Contributor

This looks good to me: short and isolates the upstream issue. However, there's also the problem of the nodata=0 in GeoRaster2.__init__ which was highlighted here and in other places (see for instance #118 (comment)). I think it deserves discussion, but the fix here can be merged in my opinion.

@astrojuanlu
Copy link
Contributor

However, if I understand correctly your comment in rasterio/rasterio#1449 (comment), this isn't a JPEG2000-specific issue, is it?

@drnextgis
Copy link
Contributor Author

Yes, this isn't a JPEG2000-specific issue. Close this PR in favour of #141.

@drnextgis drnextgis closed this Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants