def top_binarization_hsv(image, configuration):
    """

    :param image:
    :param configuration:
    :return:
    """
    configuration.print_value()

    # c = configuration.cubicle_domain
    # image_cropped = image[c[0]:c[1], c[2]:c[3]]
    hsv_image = ocv2.bgr2hsv(image)

    #   =======================================================================
    #   Main area segmentation
    main_area_seg = cv2.medianBlur(hsv_image, ksize=9)
    main_area_seg = cv2.inRange(main_area_seg,
                                configuration.roi_main.hsv_min,
                                configuration.roi_main.hsv_max)

    main_area_seg = ocv2.dilate(main_area_seg, iterations=2)
    main_area_seg = ocv2.erode(main_area_seg, iterations=2)
    #
    # mask_cropped = configuration.roi_main.mask[c[0]:c[1], c[2]:c[3]]
    # main_area_seg = cv2.bitwise_and(main_area_seg,
    #                                 main_area_seg,
    #                                 mask=mask_cropped)

    # image_out = numpy.zeros([image.shape[0], image.shape[1]], 'uint8')
    # image_out[c[0]:c[1], c[2]:c[3]] = main_area_seg

    return main_area_seg
def side_binarization_hsv(image, configuration):
    """
    Binarization of side image for Lemnatech  cabin based on hsv segmentation.

    Based on Michael pipeline
    :param image: BGR image
    :param configuration: Object BinarizationConfig
    :return: Binary image
    """

    # elementMorph = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3))

    c = configuration.cubicle_domain
    image_cropped = image[c[0]:c[1], c[2]:c[3]]
    hsv_image = ocv2.bgr2hsv(image_cropped)

    #   =======================================================================
    #   Main area segmentation
    main_area_seg = cv2.medianBlur(hsv_image, ksize=9)
    main_area_seg = cv2.inRange(main_area_seg,
                                configuration.roi_main.hsv_min,
                                configuration.roi_main.hsv_max)

    main_area_seg = ocv2.dilate(main_area_seg, iterations=2)
    main_area_seg = ocv2.erode(main_area_seg, iterations=2)

    mask_cropped = configuration.roi_main.mask[c[0]:c[1], c[2]:c[3]]
    main_area_seg = cv2.bitwise_and(main_area_seg,
                                    main_area_seg,
                                    mask=mask_cropped)

    #   =======================================================================
    #   Band area segmentation
    background_cropped = configuration.background[c[0]:c[1], c[2]:c[3]]
    hsv_background = ocv2.bgr2hsv(background_cropped)
    grayscale_background = hsv_background[:, :, 0]

    grayscale_image = hsv_image[:, :, 0]

    band_area_seg = cv2.subtract(grayscale_image, grayscale_background)
    retval, band_area_seg = cv2.threshold(band_area_seg,
                                          122,
                                          255,
                                          cv2.THRESH_BINARY)

    mask_cropped = configuration.roi_orange_band.mask[c[0]:c[1], c[2]:c[3]]
    band_area_seg = cv2.bitwise_and(band_area_seg,
                                    band_area_seg,
                                    mask=mask_cropped)

    band_area_seg = ocv2.erode(band_area_seg, iterations=5)
    band_area_seg = ocv2.dilate(band_area_seg, iterations=5)

    #   =======================================================================
    #   Pot area segmentation
    pot_area_seg = cv2.inRange(hsv_image,
                               configuration.roi_pot.hsv_min,
                               configuration.roi_pot.hsv_max)

    mask_cropped = configuration.roi_pot.mask[c[0]:c[1], c[2]:c[3]]
    pot_area_seg = cv2.bitwise_and(pot_area_seg,
                                   pot_area_seg,
                                   mask=mask_cropped)

    #   =======================================================================
    #   Full segmented image
    image_seg = cv2.add(main_area_seg, band_area_seg)
    image_seg = cv2.add(image_seg, pot_area_seg)

    image_out = numpy.zeros([image.shape[0], image.shape[1]], 'uint8')
    image_out[c[0]:c[1], c[2]:c[3]] = image_seg

    return image_out