easyidp.cvtools.imarray_crop#

easyidp.cvtools.imarray_crop(imarray, polygon_hv, outside_value=0)#

crop a given ndarray image by given polygon pixel positions

Parameters:
  • imarray (ndarray) –

    the image data in numpy ndarray
    if the shape is (height, width), view it as DSM data, the data type should be float.
    if the shape is (height, width, dimen), view it as RGB DOM data (dimen=3 means RGB and dimen=4 means RGBA).
    the data type for this case should be either 0-1 float, or 0-255 int.

    Caution

    Currently, the EasyIDP package does not have the ability to handle multi-spectral image data directly. If you really want to use this function to crop multi-spectral image with multiple layers, please send each layer one by one.

    For example, you have a multi-spectral imarray with 6 bands:

    >>> multi_spect_imarray.shape
    (1028, 800, 6)
    

    Then using the following for loops to iteratively process each band (please modify it by yourself, can not guarantee it works directly)

    >>> band_container = []
    >>> for i in range(0, 6):
    >>>     band = multi_spect_imarray[:,:,i]
    >>>     out, offset = idp.cvtools.imarray_crop(band, polygon_hv, outside_value=your_geotiff.header['nodata'])
    >>>     band_container.append(out)
    >>> final_out = np.dstack(band_container)
    

  • polygon_hv (2D ndarray) –

    pixel position of boundary point, the order is (horizontal, vertical)

    Caution

    it is reverted to the numpy imarray axis. horzontal = numpy axis 1, vertical = numpy axis 0.

  • outside_value (int | float) –

    specify exact value outside the polgyon, default 0.
    But for some DSM geotiff, it could be -10000.0, depends on the geotiff meta infomation

Returns:

  • imarray_out (ndarray) – the (m,n,d) ndrray to store pixel info

  • roi_top_left_offset (ndarray) – the (h, v) pixel index that represent the polygon bbox left top corner