geowatch.tasks.landcover.detector module¶
- geowatch.tasks.landcover.detector.normalize(image, invalid_mask, low=2, high=98)[source]¶
Example
>>> from geowatch.tasks.landcover.detector import * # NOQA >>> import kwimage >>> # orig_image = np.random.rand(32, 32, 3) >>> orig_image = kwimage.ensure_float01(kwimage.grab_test_image()) >>> image = kwimage.Polygon.random().scale(orig_image.shape[0]).fill(orig_image.copy(), np.nan) >>> invalid_mask = np.isnan(image) >>> output = normalize(image, invalid_mask) >>> assert np.isnan(image).sum() == np.isnan(output).sum() >>> # xdoctest: +REQUIRES(--show) >>> import kwplot >>> kwplot.autompl() >>> kwplot.imshow(image, pnum=(1, 2, 1), doclf=True) >>> kwplot.imshow(output, pnum=(1, 2, 2))
Example
>>> from geowatch.tasks.landcover.detector import * # NOQA >>> # Test 100% nan case >>> image = np.full((32, 32, 3), fill_value=np.nan) >>> invalid_mask = np.isnan(image) >>> import pytest >>> with pytest.raises(ValueError): >>> output = normalize(image, invalid_mask) >>> # Test 100% nan in a single band case >>> image = np.random.rand(32, 32, 3) >>> image[..., 1] = np.nan >>> invalid_mask = np.isnan(image) >>> with pytest.raises(ValueError): >>> output = normalize(image, invalid_mask)