<jupyter_start><jupyter_text>HSV Color Space, Balloons  Import resources and display image<jupyter_code># import numpy as np
# import matplotlib.pyplot as plt
# import cv2

####################################

import numpy as np
import matplotlib.pyplot as plt
import cv2
# %matplotlib inline

# # Read in the image
# image = cv2.imread('images/water_balloons.jpg')

# # Change color to RGB (from BGR)
# image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# plt.imshow(image)

####################################

%matplotlib inline

image = cv2.imread('images/water_balloons.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

plt.imshow(image)<jupyter_output><empty_output><jupyter_text>Plot color channels<jupyter_code># # RGB channels
# r = image[:,:,0]
# g = image[:,:,1]
# b = image[:,:,2]

# f, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20,10))

# ax1.set_title('Red')
# ax1.imshow(r, cmap='gray')

# ax2.set_title('Green')
# ax2.imshow(g, cmap='gray')

# ax3.set_title('Blue')
# ax3.imshow(b, cmap='gray')

################################################################

# RGB Channels
r = image[:,:,0]
g = image[:,:,1]
b = image[:,:,2]

f, (ax1,ax2,ax3) = plt.subplots(1,3, figsize=(20,10))

ax1.set_title('Red')
ax1.imshow(r, cmap = 'gray')

ax2.set_title('Green')
ax2.imshow(g, cmap = 'gray')

ax3.set_title('Blue')
ax3.imshow(b, cmap = 'gray')

# yang punya warna merah tinggi adalah yang punya pixel value lebih tinggi
# # Convert from RGB to HSV
# hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)

# # HSV channels
# h = hsv[:,:,0]
# s = hsv[:,:,1]
# v = hsv[:,:,2]

# f, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20,10))

# ax1.set_title('Hue')
# ax1.imshow(h, cmap='gray')

# ax2.set_title('Saturation')
# ax2.imshow(s, cmap='gray')

# ax3.set_title('Value')
# ax3.imshow(v, cmap='gray')

##############################################################

hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)

h = hsv[:,:,0]
s = hsv[:,:,1]
v = hsv[:,:,2]

f, (ax1,ax2,ax3) = plt.subplots(1,3, figsize = (20,10))

ax1.set_title('Hue')
ax1.imshow(h, cmap = 'gray')

ax2.set_title('Saturation')
ax2.imshow(s, cmap = 'gray')

ax3.set_title('Value')
ax3.imshow(v, cmap = 'gray')<jupyter_output><empty_output><jupyter_text>Define pink and hue selection thresholds<jupyter_code># # Define our color selection criteria in HSV values
# lower_hue = np.array([160,0,0]) 
# upper_hue = np.array([180,255,255])

####################################################

# range of Hue is only between 0-180
lower_hue = np.array([160,0,0])
upper_hue = np.array([180,255,255])
# # Define our color selection criteria in RGB values
# lower_pink = np.array([180,0,100]) 
# upper_pink = np.array([255,255,230])

###################################################

lower_pink = np.array([180,0,100])
upper_pink = np.array([255,255,230])<jupyter_output><empty_output><jupyter_text>Mask the image<jupyter_code># # Define the masked area in RGB space
# mask_rgb = cv2.inRange(image, lower_pink, upper_pink)

# # mask the image
# masked_image = np.copy(image)
# masked_image[mask_rgb==0] = [0,0,0]

# # Vizualize the mask
# plt.imshow(masked_image)

#########################################################

mask_rgb = cv2.inRange(image, lower_pink, upper_pink)

masked_image_rgb = np.copy(image)
masked_image_rgb[mask_rgb == 0] = [0,0,0]

plt.imshow(masked_image_rgb)
# # Now try HSV!

# # Define the masked area in HSV space
# mask_hsv = cv2.inRange(hsv, lower_hue, upper_hue)

# # mask the image
# masked_image = np.copy(image)
# masked_image[mask_hsv==0] = [0,0,0]

# # Vizualize the mask
# plt.imshow(masked_image)

#####################################################

mask_hsv = cv2.inRange(hsv, lower_hue, upper_hue)

masked_image_hsv = np.copy(image)
masked_image_hsv[mask_hsv == 0] = [0,0,0]

plt.imshow(masked_image_hsv)
f, (ax1,ax2,ax3) = plt.subplots(1,3,figsize = (20,10))

ax1.set_title('pink_RGB')
ax1.imshow(masked_image_rgb)

ax2.set_title('The Original')
ax2.imshow(image)

ax3.set_title('pink_HUE')
ax3.imshow(masked_image_hsv)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.25836614173228345, 'fraction_numerical': 0.04601377952755906, 'mean_word_length': 6.311151079136691, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '432733', 'license': 'Apache-2.0', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1670, 'n_words': 299, 'path': '05-HSV Color Space, Balloons.ipynb', 'repo_name': 'brdx88/cv_udacity_notebook', 'size': '4064'}