Created
February 18, 2017 15:52
-
-
Save nellaivijay/9bdf3fa7756737178c605db0770ea611 to your computer and use it in GitHub Desktop.
SCD T1 - Color selection
This file contains hidden or 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
import matplotlib.pyplot as plt | |
import matplotlib.image as mpimg | |
import numpy as np | |
# Read in the image | |
image = mpimg.imread('test.jpg') | |
# Grab the x and y size and make a copy of the image | |
ysize = image.shape[0] | |
xsize = image.shape[1] | |
color_select = np.copy(image) | |
# Define color selection criteria | |
###### MODIFY THESE VARIABLES TO MAKE YOUR COLOR SELECTION | |
red_threshold = 200 | |
green_threshold = 200 | |
blue_threshold = 200 | |
###### | |
rgb_threshold = [red_threshold, green_threshold, blue_threshold] | |
# Do a boolean or with the "|" character to identify | |
# pixels below the thresholds | |
thresholds = (image[:,:,0] < rgb_threshold[0]) \ | |
| (image[:,:,1] < rgb_threshold[1]) \ | |
| (image[:,:,2] < rgb_threshold[2]) | |
color_select[thresholds] = [0,0,0] | |
plt.imshow(color_select) | |
# Display the image | |
plt.imshow(color_select) | |
# Uncomment the following code if you are running the code locally and wish to save the image | |
# mpimg.imsave("test-after.jpg", color_select) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment