how to achieve img_update(hue_offset) function by changing the values of the hue channel by a dynamic hue_offset. To implement img_update(hue_offset) function, to achieve this Submission: 1.Change the values of the hue channel by a dynamic hue_offset.
import numpy as np
import cv2
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
def showImage(img, show_window_now = True):
# TODO: Convert the channel order of an image from BGR to RGB
#
# img = str(img)
img2 = cv2.imread(img)
img = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB)
plt_img = plt.imshow(img)
if show_window_now:
plt.show()
return plt_img
# Prepare to show the original image and keep a reference so that we can update the image plot later.
plt.figure(figsize=(4, 6))
img = "hummingbird_from_pixabay.png"
plt_img = showImage(img, False)
# TODO: Convert the original image to HSV color space.
#
img_hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
def img_update(hue_offset):
print("Set hue offset to " + str(hue_offset))
# TODO: Change the hue channel of the HSV image by `hue_offset`.
# Mind that hue values in OpenCV range from 0-179.
# ???
# TODO: Convert the modified HSV image back to RGB
# and update the image in the plot window using `plt_img.set_data(img_rgb)`.
#
# ???
#
# Create an interactive slider for the hue value offset.
ax_hue = plt.axes([0.1, 0.04, 0.8, 0.06]) # x, y, width, height
slider_hue = Slider(ax=ax_hue, label='Hue', valmin=0, valmax=180, valinit=0, valstep=1)
slider_hue.on_changed(img_update)
# Now actually show the plot window
plt.show()