kwcoco.util.lazy_frame_backends
¶
Ducktyped interfaces for loading subregions of images with standard slice syntax
Module Contents¶
Classes¶
Potentially faster than GDAL for HDR formats. |
|
fpath = '/home/joncrall/.cache/kwcoco/demo/large_hyperspectral/big_img_128.bsq' |
|
Functions¶
Example |
|
|
|
|
Test to see if the image is all black. |
|
USAGE: hdr = _read_envi_header(file) |
Attributes¶
- class kwcoco.util.lazy_frame_backends.LazySpectralFrameFile(fpath)[source]¶
Bases:
ubelt.NiceRepr
Potentially faster than GDAL for HDR formats.
- class kwcoco.util.lazy_frame_backends.LazyRasterIOFrameFile(fpath)[source]¶
Bases:
ubelt.NiceRepr
fpath = ‘/home/joncrall/.cache/kwcoco/demo/large_hyperspectral/big_img_128.bsq’ lazy_rio = LazyRasterIOFrameFile(fpath) ds = lazy_rio._ds
- kwcoco.util.lazy_frame_backends._demo_geoimg_with_nodata()[source]¶
Example
from kwcoco.util.lazy_frame_backends import * # NOQA fpath = _demo_geoimg_with_nodata() self = LazyGDalFrameFile.demo()
- class kwcoco.util.lazy_frame_backends.LazyGDalFrameFile(fpath, nodata=None)[source]¶
Bases:
ubelt.NiceRepr
Todo
[ ] Move to its own backend module
- [ ] When used with COCO, allow the image metadata to populate the
height, width, and channels if possible.
Example
>>> # xdoctest: +REQUIRES(module:osgeo) >>> self = LazyGDalFrameFile.demo() >>> print('self = {!r}'.format(self)) >>> self[0:3, 0:3] >>> self[:, :, 0] >>> self[0] >>> self[0, 3]
>>> # import kwplot >>> # kwplot.imshow(self[:])
- Parameters
nodata
masking_method
Example
>>> # See if we can reproduce the INTERLEAVE bug
data = np.random.rand(128, 128, 64) import kwimage import ubelt as ub from os.path import join dpath = ub.ensure_app_cache_dir(‘kwcoco/tests/reader’) fpath = join(dpath, ‘foo.tiff’) kwimage.imwrite(fpath, data, backend=’skimage’) recon1 = kwimage.imread(fpath) recon1.shape
self = LazyGDalFrameFile(fpath) self.shape self[:]
- __getitem__(self, index)[source]¶
References
https://gis.stackexchange.com/questions/162095/gdal-driver-create-typeerror
Example
>>> # Test nodata works correctly >>> # xdoctest: +REQUIRES(module:osgeo) >>> from kwcoco.util.lazy_frame_backends import * # NOQA >>> from kwcoco.util.lazy_frame_backends import _demo_geoimg_with_nodata >>> fpath = _demo_geoimg_with_nodata() >>> self = LazyGDalFrameFile(fpath, nodata='auto') >>> imdata = self[:] >>> # xdoctest: +REQUIRES(--show) >>> import kwplot >>> import kwarray >>> kwplot.autompl() >>> imdata = kwimage.normalize_intensity(imdata) >>> imdata = np.nan_to_num(imdata) >>> kwplot.imshow(imdata)
- kwcoco.util.lazy_frame_backends._validate_nonzero_data(file)[source]¶
Test to see if the image is all black.
May fail on all-black images
Example
>>> # xdoctest: +REQUIRES(module:osgeo) >>> import kwimage >>> gpath = kwimage.grab_test_image_fpath() >>> file = LazyGDalFrameFile(gpath) >>> _validate_nonzero_data(file)
- kwcoco.util.lazy_frame_backends._read_envi_header(file)[source]¶
USAGE: hdr = _read_envi_header(file)
Reads an ENVI “.hdr” file header and returns the parameters in a dictionary as strings. Header field names are treated as case insensitive and all keys in the dictionary are lowercase.
Modified from spectral/io/envi.py
References