Beispiel #1
0
def basic_hsv_mask(image):
    """
    Mask based on low saturation and value (gray-black colors)
    :param image: RGB numpy image
    :return: image mask, True pixels are gray-black.
    """
    hsv_image = rgb2hsv(image)
    return np.bitwise_or(hsv_image[:, :, HSV_SAT_CHANNEL] <= MIN_SAT,
                         hsv_image[:, :, HSV_VAL_CHANNEL] <= MIN_VAL)
Beispiel #2
0
def hue_range_mask(image, min_hue, max_hue, sat_min=0.05):
    hsv_image = rgb2hsv(image)
    h_channel = gaussian(hsv_image[:, :, HSV_HUE_CHANNEL])
    above_min = h_channel > min_hue
    below_max = h_channel < max_hue

    s_channel = gaussian(hsv_image[:, :, HSV_SAT_CHANNEL])
    above_sat = s_channel > sat_min
    return np.logical_and(np.logical_and(above_min, below_max), above_sat)
Beispiel #3
0
def test_overlay_custom_saturation():
    rgb_img = np.random.uniform(size=(10, 10, 3))
    labels = np.ones((10, 10), dtype=np.int64)
    labels[5:, 5:] = 2
    labels[:3, :3] = 0
    alpha = 0.3
    saturation = 0.3
    rgb = label2rgb(labels,
                    image=rgb_img,
                    alpha=alpha,
                    bg_label=0,
                    saturation=saturation)

    hsv = rgb2hsv(rgb_img)
    hsv[..., 1] *= saturation
    saturaded_img = hsv2rgb(hsv)

    # check that rgb part of input image is saturated, where labels=0
    assert_array_almost_equal(saturaded_img[:3, :3] * (1 - alpha), rgb[:3, :3])
Beispiel #4
0
                 color="white" if cm[i, j] > thresh else "black")
    plt.tight_layout()
    plt.ylabel('True label')
    plt.xlabel('Predicted label')
    plt.show()


#################### TRAINING ####################
# open training image
img_train = imread("img_train.png")

# remove unnecessary transparency column
img_train = img_train[:, :, :-1]

# convert to lab
img_train = rgb2hsv(img_train)

# normalize colors
#img_train = np.array(img_train, dtype=np.float64) / 255

# reshape image as list
w, h, d = tuple(img_train.shape)
train_array = np.reshape(img_train, (w * h, d))

# create train target for fitting the MLP classifier
train_target = np.empty((train_array.shape[0], ), dtype=int)
color_list = []
for i in range(len(train_target)):
    if find_in_color_list(train_array[i], color_list) == -1:
        color_list.append(train_array[i])
    train_target[i] = find_in_color_list(train_array[i], color_list)