Ejemplo n.º 1
0
def test_mean_image_wrong_parameters_4():
    try:
        phm_img.mean_image([[]])
    except Exception as e:
        assert type(e) == TypeError
    else:
        assert False
Ejemplo n.º 2
0
def test_mean_image_wrong_parameters_2():
    try:
        phm_img.mean_image(list())
    except Exception as e:
        assert type(e) == ValueError
    else:
        assert False
Ejemplo n.º 3
0
def test_mean_image_wrong_parameters_6():
    try:
        image = numpy.zeros((25, 25, 3))
        phm_img.mean_image(image)
    except Exception as e:
        assert type(e) == TypeError
    else:
        assert False
Ejemplo n.º 4
0
def test_mean_image_wrong_parameters_7():
    images = list()
    images.append(numpy.ones((25, 25, 3)))
    images.append(numpy.zeros((15, 15, 3)))

    try:
        phm_img.mean_image(images)
    except Exception, e:
        assert type(e) == ValueError
Ejemplo n.º 5
0
def test_mean_image_1():
    images = list()
    for i in range(10):
        images.append(numpy.zeros((25, 25, 3)))

    image = phm_img.mean_image(images)
    assert numpy.count_nonzero(image) == 0
    assert image.ndim == 3
    assert image.shape == (25, 25, 3)
Ejemplo n.º 6
0
def test_threshold_meanshift_4():
    im1 = numpy.zeros((25, 25, 3), numpy.uint8)
    im2 = numpy.zeros((25, 25, 3), numpy.uint8)
    mask = numpy.zeros((25, 25), numpy.uint8)

    mean_im = phm_img.mean_image(list([im1, im2]))

    bin_img = phm_img.threshold_meanshift(im1, mean_im, mask=mask, reverse=True)
    assert bin_img.shape == (25, 25)
Ejemplo n.º 7
0
def test_threshold_meanshift_1():

    im1 = numpy.zeros((25, 25, 3), numpy.uint8)
    im2 = numpy.zeros((25, 25, 3), numpy.uint8)

    mean_im = phm_img.mean_image(list([im1, im2]))

    bin_img = phm_img.threshold_meanshift(im1, mean_im)

    assert bin_img.shape == (25, 25)
Ejemplo n.º 8
0
def test_mean_image_3():
    images = list()
    for i in range(0, 1):
        images.append(numpy.ones((25, 25, 3)))
    for i in range(1, 10):
        images.append(numpy.zeros((25, 25, 3)))

    image = phm_img.mean_image(images)
    assert (image == 0.1).all()
    assert image.ndim == 3
    assert image.shape == (25, 25, 3)
Ejemplo n.º 9
0
def test_threshold_meanshift_no_regression_1():

    plant_number = 6
    raw_side_images = phm_data.raw_images(plant_number=plant_number)['side']
    mask = phm_data.tutorial_data_binarization_mask()[1]
    mean_im = phm_img.mean_image(raw_side_images.values())

    im_bin = phm_img.threshold_meanshift(raw_side_images[0], mean_im, mask=mask)

    ref = 158482
    # Acceptation error of 0.01 %
    acceptation_error = ref * 0.001
    if abs(numpy.count_nonzero(im_bin) - ref) > acceptation_error:
        assert False
Ejemplo n.º 10
0
def binarize(raw_images):

    # Compute the mean image of the side view image
    mean_img = phm_img.mean_image(raw_images['side'].values())

    routine_binarization = {
        'side': lambda im: routine_side_binarization(im, mean_img),
        'top': lambda im: routine_top_binarization(im)
    }

    bin_images = collections.defaultdict(dict)
    for id_camera in raw_images:
        for angle in raw_images[id_camera]:
            bin_images[id_camera][angle] = routine_binarization[id_camera](
                raw_images[id_camera][angle])

    return bin_images
Ejemplo n.º 11
0
def test_mean_image_wrong_parameters_1():
    try:
        phm_img.mean_image(None)
    except Exception, e:
        assert type(e) == TypeError
    
    # 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

## binarize image
# Compute the mean image of the side view image
mean_img = phm_img.mean_image(raw_images['side'].values())

routine_binarization = {
    'side': lambda im : routine_side_binarization(im, mean_img),
    'top': lambda im : routine_top_binarization(im)}

bin_images = collections.defaultdict(dict)
for id_camera in raw_images:
    for angle in raw_images[id_camera]:
        bin_images[id_camera][angle] = routine_binarization[id_camera](raw_images[id_camera][angle])

## Display images binarize
id_camera, angle = 'side', 120
phm_display.show_images([raw_images[id_camera][angle], mean_img, bin_images[id_camera][angle]])

id_camera, angle = 'top', 0