pyrsgis.ml.array_to_chips¶
- pyrsgis.ml.array_to_chips(data_arr, y_size=5, x_size=5)[source]¶
Image chips from raster array
This function generates images chips from single or multi band raster arrays. The image chips can be used as a direct input to deep learning models (eg. Convolutional Neural Network).
- Parameters
- data_arrarray
A 2D or 3D raster array from which image chips will be created. This should be similar as the one generated by
pyrsgis.raster.read
function.- y_sizeinteger
The height of the image chips. Ideally an odd number.
- x_sizeinteger
The width of the image chips. Ideally an odd number.
- Returns
- image_chipsarray
A 3D or 4D array containing stacked image chips. The first index represents each image chip and the size is equal to total number of cells in the input array. The 2nd and 3rd index represent the height and the width of the image chips. If the input array is a 3D array, then image_clips will be 4D where the 4th index will represent the number of bands.
Examples
>>> from pyrsgis import raster, ml >>> infile = r'E:/path_to_your_file/your_file.tif' >>> ds, data_arr = raster.read(infile) >>> image_chips = ml.array_to_chips(data_arr, y_size=7, x_size=7) >>> print('Shape of input array:', data_arr.shape) >>> print('Shape of generated image chips:', image_chips.shape) Shape of input array: (6, 2054, 2044) Shape of generated image chips: (4198376, 7, 7, 6)