pyrsgis.ml.array2d_to_chips¶
- pyrsgis.ml.array2d_to_chips(data_arr, y_size=5, x_size=5)[source]¶
Image chips from 2D array
This function generates images chips from single band arrays. The image chips can be used as a direct input to deep learning models (eg. Convolutional Neural Network).
- Parameters
- data_arrarray
A 2D array from which image chips will be created.
- 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 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.
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.array2d_to_chips(data_arr, y_size=5, x_size=5) >>> print('Shape of input array:', data_arr.shape) >>> print('Shape of generated image chips:', image_chips.shape) Shape of input array: (2054, 2044) Shape of generated image chips: (4198376, 5, 5)