-
-
Save amankharwal/fe45217247d3395d0dcd6566b39cbeb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def filter_color(L_val_min, A_val_min, A_val_max, B_val_min, B_val_max): | |
filtered_image = np.copy(cimage) | |
for xi in range(x): | |
for yi in range(y): | |
L_val = lab_img[xi,yi][0] | |
A_val = lab_img[xi,yi][1] | |
B_val = lab_img[xi,yi][2] | |
if L_val > L_val_min and A_val > A_val_min and A_val < A_val_max and B_val > B_val_min and B_val < B_val_max: | |
pass | |
else: | |
filtered_image[xi, yi] = [255,255,255] | |
return filtered_image | |
lab_img = color.rgb2lab(cimage) | |
yellow = filter_color(70, -50, 0, 30, 100) | |
red = filter_color(30, 25, 100, 0, 100) | |
green = filter_color(50, -128, -20, 0, 50) | |
blue = filter_color(50,-40, 30, -128, -20) | |
white = filter_color(93, -25, 25, -25, 25) | |
pink = filter_color(50, 20,128,-50,0) | |
fig, ax = plt.subplots(nrows=3, ncols=2, figsize=(20,20)) | |
ax[0][0].imshow(pink) | |
ax[0][0].set_title("pink Candies") | |
ax[0][0].axis('off') | |
ax[0][1].imshow(yellow) | |
ax[0][1].set_title("yellow Candies") | |
ax[0][1].axis('off') | |
ax[1][0].imshow(red) | |
ax[1][0].set_title("red Candies") | |
ax[1][0].axis('off') | |
ax[1][1].imshow(green) | |
ax[1][1].set_title("green Candies") | |
ax[1][1].axis('off') | |
ax[2][0].imshow(white) | |
ax[2][0].set_title("white Candies") | |
ax[2][0].axis('off') | |
ax[2][1].imshow(blue) | |
ax[2][1].set_title("blue Candies") | |
ax[2][1].axis('off') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment