from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from pynq import allocate, Overlay
i4filters = Overlay("./i4filters.bit")
dma = i4filters.axi_dma_0
median = i4filters.median_axis_RGB24_0
sobel = i4filters.sobel_axis_RGB24_0
gaussian = i4filters.gaussian_axis_RGB24_0
color_conv = i4filters.color_converter_RGB24_0
image_path = "./test2.jpg"
#image_path = "./blue.bmp"
#image_path = "./green.bmp"
#image_path = "./red.bmp"
original_image = Image.open(image_path)
canvas = plt.gcf()
size = canvas.get_size_inches()
canvas.set_size_inches(size*2)
width, height = original_image.size
print("Image size: {}x{} pixels.".format(width, height))
plt.figure(figsize=(12, 10));
_ = plt.imshow(original_image)
in_buffer = allocate(shape=(height, width, 3),
dtype=np.uint8, cacheable=1)
out_buffer = allocate(shape=(height, width, 3),
in_buffer[:] = np.array(original_image)
def run_kernel():
dma.sendchannel.transfer(in_buffer)
dma.recvchannel.transfer(out_buffer)
gaussian.write(0x00,0x01) # start
median.write(0x00,0x01) # start
color_conv.write(0x00,0x01) #start
sobel.write(0x00,0x01) # start
dma.sendchannel.wait()
dma.recvchannel.wait()
print(height)
print(width)
gaussian.register_map.row_size = height
gaussian.register_map.col_size = width
gaussian.register_map.function_r = 2 # ORG_IMGwAxiDma
#gaussian.register_map.function_r = 3 # GAUSSIANwAxiDma
median.register_map.row_size = height
median.register_map.col_size = width
#median.register_map.function_r = 2 # ORG_IMGwAxiDma
median.register_map.function_r = 3 # MEDIANwAxiDma
color_conv.register_map.row_size = height
color_conv.register_map.col_size = width
#color_conv.register_map.function_r = 2 # ORG_IMGwAxiDma
color_conv.register_map.function_r = 3 # COLOR_CONVwAxiDma
color_conv.register_map.red_mag = 0x2000 # 32.0, ap_ufixed<16, 8, AP_TRN_ZERO, AP_SAT>
color_conv.register_map.green_mag = 0x0100 # 1.0, ap_ufixed<16, 8, AP_TRN_ZERO, AP_SAT>
color_conv.register_map.blue_mag = 0x0100 # 1.0, ap_ufixed<16, 8, AP_TRN_ZERO, AP_SAT>
sobel.register_map.row_size = height
sobel.register_map.col_size = width
sobel.register_map.function_r = 2 # ORG_IMGwAxiDma
#sobel.register_map.function_r = 3 # SOBELwAxiDma
run_kernel()
sobel_image = Image.fromarray(out_buffer)
print("Image size: {}x{} pixels.".format(width, height))
plt.figure(figsize=(12, 10));
_ = plt.imshow(sobel_image)
del in_buffer
del out_buffer
日 | 月 | 火 | 水 | 木 | 金 | 土 |
---|---|---|---|---|---|---|
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |