<jupyter_start><jupyter_text>Exercise 5<jupyter_code># Import libraries
import cv2
import numpy as np
import matplotlib.pyplot as plt<jupyter_output>/home/viniciuscampos/miniconda3/envs/dip/lib/python3.7/site-packages/matplotlib/font_manager.py:232: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  'Matplotlib is building the font cache using fc-list. '<jupyter_text>Loading image<jupyter_code>original = cv2.imread('images/oranges.jpg')
original = cv2.cvtColor(original, cv2.COLOR_BGR2RGB)
hsv = cv2.cvtColor(original, cv2.COLOR_RGB2HSV)

plt.figure(figsize=(15,10))
ax1 = plt.subplot(121)
ax1.imshow(original)
ax2 = plt.subplot(122)
ax2.imshow(hsv, cmap='hsv')

ax1.axis('off')
ax2.axis('off')

ax1.text(0.5,-0.1, "original", ha="center", transform=ax1.transAxes)
ax2.text(0.5,-0.1, "hsv", ha="center", transform=ax2.transAxes)

plt.show()<jupyter_output><empty_output><jupyter_text>Filtering the oranges<jupyter_code>oranges = cv2.inRange(hsv, (0, 154, 130), (35, 255, 255))
oranges = cv2.bitwise_and(original, original, mask=oranges)

plt.figure(figsize=(10, 5))
plt.imshow(oranges)
plt.axis('off')

plt.show()<jupyter_output><empty_output><jupyter_text>Filtering the leaves<jupyter_code>leaves = cv2.inRange(hsv, (15, 110, 0), (70, 255, 85))
leaves = cv2.bitwise_and(original, original, mask=leaves)

plt.figure(figsize=(10, 5))
plt.imshow(leaves)
plt.axis('off')

plt.show()<jupyter_output><empty_output><jupyter_text>Filtering the door<jupyter_code>door = cv2.inRange(hsv, (0, 40, 30), (25, 105, 160))
door = cv2.bitwise_and(original, original, mask=door)

plt.figure(figsize=(10, 5))
plt.imshow(door)
plt.axis('off')

plt.show()<jupyter_output><empty_output><jupyter_text>Filtering the background<jupyter_code>background = cv2.inRange(hsv, (0, 0, 180), (115, 70, 255))
background = cv2.bitwise_and(original, original, mask=background)

plt.figure(figsize=(10, 5))
plt.imshow(background)
plt.axis('off')

plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup