In this notebook, we will explore how to invert colors in an image. Also known as a negative image, it is a total inversion, in which light areas appear dark and dark appears light. Additionally, these images are color-reversed, with red appearing as cyan, greens appearing magenta, and blues appearing yellow, and vice versa.
To obtain the inverted color value, you take the maximum value that the color can be. For example, if you have a 256 color scheme, 255 is the maximum color value possible (from 0 - 255). You subtract the actual color from the maximum color to get its inverse.
So if you have a yellow color that is R = 255, G = 255, and B = 0, and you subtract the values to get the inverse
you would result with R = 0, G = 0, and B = 255 which leaves you with just the color blue.
You can see this color inversion in the table below.
This notebook will use a video filter that inverts the input image.
In [1]:
from pynq.drivers.video import HDMI
from pynq import Bitstream_Part
from pynq.board import Register
from pynq import Overlay
Overlay("demo.bit").download()
In [11]:
hdmi_in = HDMI('in')
hdmi_out = HDMI('out', frame_list=hdmi_in.frame_list)
hdmi_out.mode(2) #2 is for camera
hdmi_out.start()
hdmi_in.start()
#Valid resolutions are:
#
# 0 : '640x480@60Hz'
# 1 : '800x600@60Hz'
# 2 : '1280x720@60Hz'
# 3 : '1280x1024@60Hz'
# 4 : '1920x1080@60Hz'
In [10]:
Bitstream_Part("invert_p.bit").download()
In [8]:
import ipywidgets as widgets
from ipywidgets import Button, HBox, VBox, Label
words = ['HDMI Reset']
items = [Button(description=w) for w in words]
def on_hdmi_clicked(b):
hdmi_out.stop()
hdmi_in.stop()
hdmi_out.start()
hdmi_in.start()
items[0].on_click(on_hdmi_clicked)
widgets.VBox([items[0]])
In [12]:
hdmi_out.stop()
hdmi_in.stop()
del hdmi_out
del hdmi_in