<jupyter_start><jupyter_text>__From last week__- DRaw- Create masks__From this week__- Blurring- Thresholding  Laod image<jupyter_code>fname = os.path.join("..", "data", "img", "trex.png")
image = cv2.imread(fname)
jimshow(image)<jupyter_output><empty_output><jupyter_text>Drawing cv2.rectangle( image, start_point, end_pont, color, thickness)<jupyter_code>cv2.rectangle(image, (50,200), (200, 225), (255, 0, 0), 1)
jimshow(image)
image = cv2.imread(fname)
jimshow(image)<jupyter_output><empty_output><jupyter_text>__Draw circle__<jupyter_code>#cv2.circle(image, center_cordinates, radius, color, thickness)
image.shape
(centerX, centerY) =image.shape[1] // 2, image.shape[0] // 2
cv2.circle(image, (centerX, centerY), 50, (0,255,0), 1)
jimshow(image)
cv2.circle(image, (200, 20), 30, (140,255,60), 3)
jimshow(image)<jupyter_output><empty_output><jupyter_text>Creating and using masks<jupyter_code>image = cv2.imread(fname)
mask = np.zeros(image.shape[:2], dtype="uint8")
cv2.rectangle(mask, (100,100), (200, 200), 255, -1)
masked = cv2.bitwise_and(image, image, mask = mask)
jimshow_channel(mask)<jupyter_output><empty_output><jupyter_text>` cv2.bitwise_and(input_image, output_image, mask)<jupyter_code>jimshow(cv2.bitwise_and(image, image, mask = mask))
cv2.bitwise_and(image, image, mask)
jimshow_channel(mask)<jupyter_output><empty_output><jupyter_text>Group taskWe've seen rectangle masksHow would we do a circular mask<jupyter_code>image = cv2.imread(fname)
mask = np.zeros(image.shape[:2], dtype="uint8")
cv2.circle(image, (200, 200), 30, (140,255,60), -1)
jimshow_channel(mask)
mask = np.zeros(image.shape[:2], dtype="uint8")
#cv2.circle(image, center_cordinates, radius, color, thickness)
cv2.circle(mask, (250, 250), 100, (255,0,0), 1)
jimshow_channel(mask)
mask = np.zeros(image.shape[:2], dtype="uint8")
(centerX, centerY) = image.shape[1] // 2, image.shape [0] // 2
#cv2.circle(image, center_cordinates, radius, color, thickness)
cv2.circle(mask, (centerX, centerY), 100, (255,0,0), -1)
jimshow_channel(mask)
image = cv2.imread(fname)
mask = np.zeros(image.shape[:2], dtype="uint8")
(centerX, centerY) = image.shape[1] // 2, image.shape [0] // 2
#cv2.circle(image, center_cordinates, radius, color, thickness)
cv2.circle(mask, (centerX, centerY), 100, (255,0,0), -1)
jimshow(cv2.bitwise_and(image, image, mask = mask))<jupyter_output><empty_output><jupyter_text>Blurring __Average blur__<jupyter_code>#parameters image and kernel
blurred = cv2.blur(image, (3,3))
jimshow(blurred, "3x3 averaging blur")
stacked = np.hstack([
    cv2.blur(image, (3,3)),
    cv2.blur(image, (5,5)),
    cv2.blur(image, (7,7))
])
jimshow(stacked)<jupyter_output><empty_output><jupyter_text>Thresholding<jupyter_code>image = cv2.imread(fname)
grey_image =cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
jimshow_channel(grey_image)
plt.hist(grey_image.flatten(), 256, [0, 256])
plt.show()
blurred = cv2.blur(grey_image, (5,5))
jimshow_channel(blurred)<jupyter_output><empty_output><jupyter_text>cv2.threshold(image, threshold_value, color, method)<jupyter_code>(T_value, threshold)= cv2.threshold(blurred, 200, 255, cv2.THRESH_BINARY)
jimshow_channel(threshold)
print(T_value)
(T_value, thresh_inverted)= cv2.threshold(blurred, 200, 255, cv2.THRESH_BINARY_INV)
jimshow_channel(thres_inverted)
jimshow(cv2.bitwise_and(image, image, mask = thresh_inverted))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16562778272484416, 'fraction_numerical': 0.058771148708815675, 'mean_word_length': 8.439775910364146, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '371506', 'license': 'MIT', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1366, 'n_words': 232, 'path': 'notebooks/Session4-akr.ipynb', 'repo_name': 'aksroa/Visual-portfolio', 'size': '3369'}