EEC180 Tutorial: Creating verilog-ready bitmaps from image files

EEC180, Digital Systems II


For some labs you may need to display an image from a file such as a jpeg, png, etc. onto the VGA monitor. This tutorial describes the process and provides two scripts to process an RGB color image from a file into a verilog case statement suitable for use in a ROM which stores the image's bitmap.

1. Python script (for Linux and macOS systems, root/admin privileges needed)

  1. This script requires opencv-python module (cv2 module). To install cv2 on Linux/OSX, type 'pip install opencv-python' in terminal.

    For Windows, please consult this helpful installation procedure for Anaconda, written by Ning Miao.

  2. Download the python script img2v.py

  3. Choose OUT_MODE to select an output format:

    For M9K ROMs:
    OUT_MODE = True        →       output: mem[0] = 12'brrrr_gggg_bbbb;

    For case statement ROM tables:
    OUT_MODE = False       →       output: 8'b0000_0000: begin mem = 12'brrrr_gggg_bbbb; end

  4. To view the image in python, uncomment the four indicated lines in the script and press q to exit the imshow window

  5. Usage:
       python img2v.py OUT_MODE SIZE_X SIZE_Y IMAGE_FILENAME > OUT_FILENAME.v
       OUT_MODE=0      For use in a case statement
       OUT_MODE=1      For use in an initial block
       SIZE_X, SIZE_Y  Image will be scaled to this size in pixels
       Example: python img2v.py 0 16 16 mario.jpg > rom.v
    
    Acceptable image format types include jpeg, png, tiff. pbm, pgm, and ppm. The code determines the type of an image by the content, not by the file extension. The formats bmp, dib, jpeg2000, jpeg2000, are likely to work; these notes explain details.

2. Matlab script

3. Miscellaneous files



EEC 181 | B. Baas | ECE Dept. | UC Davis
2019/06/01  Written
2019/06/04  Added details and reference for acceptable image file types.
Written by Bevan Baas and Arthur Hlaing