import math
from random import randint
from rasterio.enums import Resampling
import numpy as np
import imagebox.io as io
import imagebox.processor as proc
import imagebox.indices as indices
from imagebox.config import FIRST, LAST, BAND_ORDERING, BANDS_FIRST
#
# CONSTANTS
#
INPUT_DTYPE=np.float
TARGET_DTYPE=np.int64
DEFAULT_SIZE=256
DEFAULT_OVERLAP=0
TO_CATEGORICAL_ERROR='imagebox.handler: nb_categories required for to_categorical'
INPUT_RESAMPLING=Resampling.bilinear
TARGET_RESAMPLING=Resampling.mode
#
# InputTargetHandler
#
class InputTargetHandler(object):
"""
A handler for processing multiple input/target pairs in the
same way.
This is especially useful for constructing data loader/generators
Args:
input_bands<list|None>: list of bands to select from image
means,stdevs<list|np.array>:
- means/stdevs for all bands in input image (before selecting input_bands)
- if means and not stdevs: center input around means
- if means and stdevs normalize inputs
band_indices<list>:
- list of arguments for imagebox.indices.index
- adds band_index bands to image
indices_dict<dict>:
- preset indices from which to select band_indices
value_map<dict>:
- target value map.
- keys: new values
- values: list of values to map to new value
default_mapped_value<'image'|int|float>:
- only used if value_name is not None
- if 'image' keep all unmapped values
- otherwise value for all unmapped values
to_categorical<bool>: one-hot target image
nb_categories<int>:
- number of target categories
- required for to_categorical
augment<bool>: augment image
flip_target/input<bool>:
- flip target/input image before any additional augmentation
- for use when target and input pairs have opposite y-axis orientation
- set only one of these to be true
target/input_resolution: rescale input or target with input/target resampling method
input/target_resampling: resampling method for input or target
padding|input/target_padding<int|None>:
- amount to pad images|input/target-image after processing the image
- will be ignored if there is cropping
cropping<int|None>:
- amount to crop both input and target image when reading the image
input/target_cropping<int|None>:
- amount to crop input/target image after processing the image
float_cropping<int|None>:
remove pixels from h/w of input and target starting at random i,j
width<int|None>: image width (required if float cropping and not tiller)
height<int|None>: image height (required if float cropping and not tiller)
tiller<Tiller|True|None>:
tile the image then read in a specific tile
tiller_config<dict>:
if tiller is True create tiller=Tiller(**tiller_config)
input_dtype<str>: input data type
target_dtype<str>: target data type
"""
def __init__(self,
input_bands=None,
means=None,
stdevs=None,
band_indices=None,
indices_dict=None,
value_map=None,
default_mapped_value=proc.DEFAULT_VMAP_VALUE,
to_categorical=False,
nb_categories=None,
augment=True,
flip_target=False,
flip_input=False,
input_resolution=None,
target_resolution=None,
input_bounds=None,
input_resampling=INPUT_RESAMPLING,
target_resampling=TARGET_RESAMPLING,
padding=None,
input_padding=None,
target_padding=None,
input_padding_value=0,
target_padding_value=0,
float_cropping=None,
cropping=None,
input_cropping=None,
target_cropping=None,
window_index=None,
size=None,
width=None,
height=None,
example_path=None,
tiller=None,
tiller_config={},
target_expand_axis=None,
input_preprocess=None,
target_preprocess=None,
target_squeeze=True,
input_dtype=INPUT_DTYPE,
target_dtype=TARGET_DTYPE ):
if tiller is True:
self.tiller=Tiller(**tiller_config)
else:
self.tiller=tiller
self.input_bands=input_bands
self.band_indices=band_indices
self.indices_dict=indices_dict
self.value_map=value_map
self.default_mapped_value=default_mapped_value
self.means=means
self.stdevs=stdevs
if to_categorical and (not nb_categories):
raise ValueError(TO_CATEGORICAL_ERROR)
self.to_categorical=to_categorical
self.nb_categories=nb_categories
self.augment=augment
self.flip_target=flip_target
self.flip_input=flip_input
self.input_resolution=input_resolution
self.target_resolution=target_resolution
self.input_bounds=input_bounds
self.input_resampling=input_resampling
self.target_resampling=target_resampling
self.set_augmentation()
self.input_padding=input_padding or padding
self.target_padding=target_padding or padding
self.input_padding_value=input_padding_value
self.target_padding_value=target_padding_value
self.cropping=cropping or 0
self.input_cropping=input_cropping
self.target_cropping=target_cropping
self.float_cropping=float_cropping
if size:
self.width=size
self.height=size
else:
self.width=width
self.height=height
self.set_window(
window_index=window_index,
example_path=example_path)
self.target_expand_axis=target_expand_axis
self.input_preprocess=input_preprocess
self.target_preprocess=target_preprocess
self.target_squeeze=target_squeeze
self.input_dtype=input_dtype
self.target_dtype=target_dtype
def input(self,path,window=None,return_profile=False):
self.input_path=path
im,profile=self._read(
path,
self.input_resolution,
self.target_resampling,
window )
im=process_input(
im,
preprocess=self.input_preprocess,
flip=self.flip_input,
input_bands=self.input_bands,
band_indices=self.band_indices,
indices_dict=self.indices_dict,
padding=self.input_padding,
padding_value=self.input_padding_value,
cropping=self.input_cropping,
bounds=self.input_bounds,
means=self.means,
stdevs=self.stdevs,
dtype=self.input_dtype )
return self._return_data(
im,
profile,
return_profile )
def target(self,path,window=None,return_profile=False):
self.target_path=path
im,profile=self._read(
path,
self.target_resolution,
self.target_resampling,
window )
im=process_target(
im,
preprocess=self.target_preprocess,
flip=self.flip_target,
value_map=self.value_map,
default_mapped_value=self.default_mapped_value,
categorical=self.to_categorical,
nb_categories=self.nb_categories,
padding=self.target_padding,
padding_value=self.target_padding_value,
cropping=self.target_cropping,
expand_axis=self.target_expand_axis,
squeeze=self.target_squeeze,
dtype=self.target_dtype )
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共10个文件
py:8个
pkg-info:1个
cfg:1个
资源分类:Python库 所属语言:Python 资源全名:imagebox-0.0.0.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源详情
资源评论
资源推荐
收起资源包目录
imagebox-0.0.0.2.tar.gz (10个子文件)
imagebox-0.0.0.2
PKG-INFO 412B
imagebox
utils.py 2KB
io.py 5KB
processor.py 9KB
__init__.py 13B
indices.py 5KB
config.py 656B
handler.py 16KB
setup.cfg 39B
setup.py 613B
共 10 条
- 1
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0