def test_threshold_hsv_wrong_parameters_13(): image = numpy.zeros((25, 25, 3), dtype=numpy.uint8) hsv_min = (42, 75, 28) hsv_max = (80, 250, 134) mask = numpy.zeros((25, 26), dtype=numpy.uint8) try: phm_img.threshold_hsv(image, hsv_min, hsv_max, mask=mask) except Exception, e: assert type(e) == ValueError
def test_threshold_hsv_wrong_parameters_6(): image = numpy.zeros((25, 25, 3), dtype=numpy.uint8) hsv_min = (42, 75, 28) hsv_max = None mask = numpy.zeros((25, 25), dtype=numpy.uint8) try: phm_img.threshold_hsv(image, hsv_min, hsv_max, mask=mask) except Exception, e: assert type(e) == TypeError
def test_threshold_hsv_wrong_parameters_5(): image = numpy.zeros((25, 25, 3), dtype=numpy.uint8) hsv_min = (80.6, 250.0, 56.9) hsv_max = (80, 250, 134) mask = numpy.zeros((25, 25), dtype=numpy.uint8) try: phm_img.threshold_hsv(image, hsv_min, hsv_max, mask=mask) except Exception as e: assert type(e) == ValueError else: assert False
def test_threshold_hsv_wrong_parameters_1(): image = None hsv_min = (42, 75, 28) hsv_max = (80, 250, 134) mask = numpy.zeros((25, 25), dtype=numpy.uint8) try: phm_img.threshold_hsv(image, hsv_min, hsv_max, mask=mask) except Exception as e: assert type(e) == TypeError else: assert False
def routine_side_binarization(image, mean_img): maks = phm_data.tutorial_data_binarization_mask() threshold = 0.3 dark_background = False hsv_min = (30, 11, 0) hsv_max = (129, 254, 141) # Convert image on HSV representation hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # Threshold the image with HSV min and max value binary_hsv_image = phm_img.threshold_hsv(hsv_image, hsv_min, hsv_max, maks[0]) # Threshold the image with difference between image and mean_image binary_mean_shift_image = phm_img.threshold_meanshift( image, mean_img, threshold, dark_background, maks[1]) # Add the two image result = cv2.add(binary_hsv_image, binary_mean_shift_image) # Erode and dilate the image to remove possible noise result = cv2.medianBlur(result, 3) return result
def test_threshold_hsv_1(): image = numpy.zeros((25, 25, 3), dtype=numpy.uint8) hsv_min = (42, 75, 28) hsv_max = (80, 250, 134) mask = numpy.zeros((25, 25), dtype=numpy.uint8) img_bin = phm_img.threshold_hsv(image, hsv_min, hsv_max, mask=mask) assert img_bin.ndim == 2 assert numpy.count_nonzero(img_bin) == 0
def routine_top_binarization(image): hsv_min = (42, 75, 28) hsv_max = (80, 250, 134) median_blur_size=9 iterations=5 # Convert image on HSV representation hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # Apply a median blur on the image hsv_image = cv2.medianBlur(hsv_image, ksize=median_blur_size) # Threshold the image with HSV min and max value bin_img = phm_img.threshold_hsv(hsv_image, hsv_min, hsv_max) # dilate and erode the image to remove possible noise bin_img = phm_img.dilate_erode(bin_img, kernel_shape=(3, 3),iterations=iterations) return bin_img