API Reference
rsimg_io
readTiff (class):
writeTiff: write out the .tiff formated remote sensing image.
- readTiff(path_in)
Description: Write out the .tiff formated remote sensing image
- Param:
path_in
- Returns:
img(np.array), extent(tuple), projection(str), dimentions(tuple)
- writeTiff(im_data, im_geotrans, im_geosrs, path_out)
Write out the .tiff formated remote sensing image
- Param:
im_data, im_geotrans, im_geosrs, path_out
- Retrun:
None
geo_imgxy
- get_utm_zone(lon)
Description: Get utm zone from the given wgs84 coordinates.
- Param:
lon: the given longitute, should be in the range of [-180, 180]
- Retrun:
utm_zone_number
- coor2coor(srs_from, srs_to, x, y)
Description: Transform coordinates from srs_from to srs_to
- Param:
srs_from: EPSG number (e.g., 4326, 3031)
srs_to: EPSG number (e.g., 4326, 3031)
x: x-coord corresponding to srs_from
y: y-coord corresponding to srs_from
- Retrun:
(x, y): x-coord and y-coord corresponding to srs_to
- geo2imagexy(x, y, gdal_trans, integer=True)
Description: from georeferenced location (i.e., lon, lat) to image location(col,row).
Note: the coordinate system should be same between x/y and gdal_trans.
- Param:
gdal_proj: obtained by gdal.Open() and .GetGeoTransform(), or by geotif_io.readTiff()[‘geotrans’]
x: project or georeferenced x, i.e.,lon
y: project or georeferenced y, i.e., lat
- Retrun:
utm_zone_number
- imagexy2geo(row, col, gdal_trans)
Description: from image location(col,row) to georeferenced location (i.e., lon, lat).
- Param:
img_gdal: GDAL data (read by gdal.Open()
row: row of the input image (dataset)
col: col of the input image (dataset)
- Retrun:
x: geographical coordinates at x-axis (left up of pixel)
y: geographical coordinates at y-axis (left up of pixel)
img_normalize
- img_normalize(img, max_bands, min_bands)
Description: image normalization.
- Param:
max_bands: list, max value of each the band of image.
min_bands: list, min values of each the band of image.
image: np.array.
- Retrun:
image_nor: the normalized image.
img2patch
- class img2patch(img, patch_size, edge_overlay)
Description: Conversion between the remote sensing image and patches
- Param:
img: np.array()
patch_size: size of the patch
edge_overlay: an even number, single-side overlay of the neighboring images.
- Method:
.toPatch():
Description: convert img to patches.
- param:
None
- retrun:
patch_list: contains all generated patches.
start_list: contains all start positions(row, col) of the generated patches.
- Method:
.higher_patch_crop(higher_patch_size)
Description: crop the higher-scale patch
- param:
higher_patch_size: int, the lager patch size compared the low-scale patch size.
- retrun:
higher_patch_list: list, contains higher-scale patches corresponding to the lower-scale patches.
- Method:
.toImage(patch_list)
Description: merge patches into one image.
- param:
patch_list: list of the all patches.
- retrun:
img_array: the merged image by patches
- class crop2size(img, channel_first=False)
Description: randomly crop corresponding to specific size.
- Param:
img: np.array().
channel_first: True or False.
- Method:
.toSize(size=(256, 256))
Descrition: randomly crop corresponding to specific size
- param:
size: tuble/list, (height, width)
- retrun:
patch, the cropped patch from the image.
- Method:
.toScales(scales=(2048, 512, 256))
Description: randomly crop multiple-scale patches (from high to low) from remote sensing image.
- param:
scales: tuple or list (high scale -> low scale)
- return:
patches_group_down: list of multiscale patches.
- class crop2extent(extent, size_target=None)
Description: Crop image with specific geographical extent.
- Method:
.img2extent(path_img, path_save=None)
- param:
path_img: string, the image path to be croped.
size_target: size to which image should be croped list/tuple, (row, col)
path_save: string, the path for output saving.
- retrun:
img_croped: the croped image, np.array()
imgShow
- imgShow(img, ax=None, extent=None, color_bands=(2, 1, 0), clip_percent=2, per_band_clip=False, focus_per=None, focus_pix=None)
Description: show the single image.
- Param:
img: (row, col, band) or (row, col), DN range should be in [0,1]
extent: list, the coordinates of the extent.
num_bands: a list/tuple, [red_band,green_band,blue_band]
clip_percent: for linear strech, value within the range of 0-100.
per_band_clip: if True, the band values will be clipped by each band respectively.
focus_per: list, [up_start_percent,down_end_percent,left_start_percent, right_end_percent]; 0 < value < 1
focus_pix: list, [up_start_pixel,down_end_pixel,left_start_pixel, right_end_pixel]; 0 < value < (width or height) of the image
- Retrun:
None
- imsShow(img_list, img_name_list, clip_list=None, color_bands_list=None, axis=True, row=None, col=None)
Description: show the multiple images.
- Param:
img_list: containes all images
img_names_list: image names corresponding to the images
clip_list: percent clips (histogram) corresponding to the images
color_bands_list: color bands combination corresponding to the images
row, col: the row and col of the figure
axis: True or False
- Retrun:
None
lay_stack
- lay_stack(path_imgs, path_out, union=True, res=None)
Description: layer stacking of the multiple bands of image.
- Param:
path_imgs: list, contains the paths of bands/imgs to be stacked
path_out: str, the output path of the layer stacked image
union: bool, if true, the output extent is the extents union of input images. Otherwise, the output extent is the extents intersection of input images.
res: resolution of the layer stacked image.
- Retrun:
imgs_stacked: np.array(), the stacked image.
metric_proc
- smooth(y, window=31, num_sam=None)
Description: smooth the sequential data.
- Param:
y: the sequential data.
window: the smooth window used for averating y.
num_sam: the number of sampled data.
- Retrun:
x: the smoothed sequential data of x-axis.
y: the smoothed sequential data of y-axis.
metric
- acc_matrix(cla_map, truth_map=None, sam_pixel=None, id_label=None)
Description: calculate the accuracy matrix.
- Param:
cla_map: classification result of the full image.
truth_map: truth image (either truth_map or sam_pixel should be given).
sam_pixel: np.array, (num_samples,3), col 1,2,3 are the row,col and label.
id_label: 0/1/2/…, Calculating producer’s or user’s accuracy for target class.
- Retrun:
acc_oa: overall accuracy
confus_mat: confusion matrix
- acc_miou(cla_map, truth_map, labels=None)
Description: calculate the miou metric.
- Param:
cla_map: classification result of the full image
truth_map: truth image (either truth_map or sam_pixel should be given)
labels: a list, the class id for calculating. e.g., [0,1,2]
- Retrun:
miou: MIoU metric
- oa_binary(pred, truth)
Description: calculate overall accuracy (2-class classification) for each batch.
- Param:
pred: 4D tensor
truth: 4D tensor
- Retrun:
oa: overall accuracy
- miou_binary(pred, truth)
Description: calculate miou (2-class classification) for each batch.
- Param:
pred: 4D tensor
truth: 4D tensor
- Retrun:
miou: miou metric
raster_vec
- raster2vec(raster_path, output_path, dn_values)
Description: Read input band with Rasterio.
- Param:
raster_path: raster path
output_path: ouput vector path
dn_values: list, consist of the raster value to be vectorization
- Retrun:
miou: miou metric
- vec2mask(path_vec, path_raster, path_save=None)
Description: generate/save mask file using the vector file(e.g.,.shp,.gpkg).
- Param:
path_vec: str, path of the vector data.
path_raster: str, path of the raster data.
path_save: str, path to save.
- Retrun:
mask: np.array().
transform_time
- date2doy(year, month, day, hour=0, minute=0)
Description: convert year-month-day-hour-minute to doy (day-of-year)
- Param:
year month: 0~12 day: 0~31 hour minute
- Retrun:
doy: day of the year.
- doy2date(year, doy)
Description: Convert doy(day-of-year) to year-month-day-hour-minute formate the function returns the month and the day of the month.
- Param:
year
doy
- Retrun:
month
day: the day of the month
- dt64_to_dyr(dt64)
Description: Convert datetime64 to decimal year format. e.g., ‘2020-05-23T03:25:22.959373696’ -> 2020.3907103825136.
- Param:
dt64: np.datetime64 format time
- Retrun:
dt_float: float, the decimal date.
- second_to_dyr(time_second, time_start='2000-01-01 00:00:00.0')
Description: convert time (second format) to decimal year. This function suitable for the jason data, sentinel-3 data, and the cryosat2 data for time conversion.
- Param:
time_second: seconds from the time start.
- Retrun:
time_second_dyr: decimal date.