from scipy.ndimage import measurements
im = array(...)
labels, num_features = measurements.label(im)
set_printoptions(threshold=nan, linewidth=nan)
print(str(labels[0:100,0:100]))
# includes 0 count
counts = bincount(ravel(labels))
print(counts)
r = rgb[:, :, 0]
g = rgb[:, :, 1]
b = rgb[:, :, 2]
# do something
rgb2 = np.dstack((r, g, b))
def filter_blah(rgb, thresh, tolerance=70):
rgb_int = rgb.astype(np.int)
(r_thresh, g_thresh, b_thresh) = thresh
r = (abs(rgb_int[:, :, 0] - r_thresh) <= tolerance)
g = (abs(rgb_int[:, :, 1] - g_thresh) <= tolerance)
b = (abs(rgb_int[:, :, 2] - b_thresh) <= tolerance)
result = (r & g & b)
return result
# result = filter_blah(rgb, (230, 230, 250)) | \
# filter_blah(rgb, (216, 191, 216)) | \ Y
# filter_blah(rgb, (221, 160, 221)) | \
# filter_blah(rgb, (238, 130, 238)) | \
# filter_blah(rgb, (218, 112, 214)) | \
# filter_blah(rgb, (255, 0, 255)) | \
# filter_blah(rgb, (186, 85, 211)) | \
# filter_blah(rgb, (147, 112, 219)) | \
# filter_blah(rgb, (138, 43, 226)) | \
# filter_blah(rgb, (148, 0, 211)) | \
# filter_blah(rgb, (153, 50, 204)) | \
# filter_blah(rgb, (139, 0, 139)) | \
# filter_blah(rgb, (128, 0, 128)) | \
# filter_blah(rgb, (75, 0, 130))
result = filter_blah(rgb, (218, 112, 214))
add_text_and_display(mask_rgb(rgb, result), "Color Threshold")
a = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25]])
print(str(a))
b = np.arange(1,26).reshape(5,5)
print(str(b))
gives
[[ 1 2 3 4 5]
[ 6 7 8 9 10]
[11 12 13 14 15]
[16 17 18 19 20]
[21 22 23 24 25]]
[[ 1 2 3 4 5]
[ 6 7 8 9 10]
[11 12 13 14 15]
[16 17 18 19 20]
[21 22 23 24 25]]