I have a .mif image that I want to encrypt in Verilog. To do so, I need to read the image into the program and store it in an array.

The image would be 160 by 120 and I would like to store it in an array of size 160*120*3 (It's multiplied by 3 since each pixel requires a 3 bit number to store its color). So ideally, I would be doing something like this:

wire [16] image = read ("myimage.mif")

So far, I've taken a look at initial blocks and they seem like they might help. I wasn't able to find a specific guide for reading in images though. Note that I have to do this in Verilog, not SystemVerilog.

Could someone please show me how to do this or at the very least tell me what kind of things I should be looking into in order to be able to do this? Thank you.


1 Answer 1


In this case, it might be a good idea to preprocess the image into an intermediate format with a different programming language that actually has image manipulation libraries, such as Python with PIL. You really don't want to have to deal with parsing the MIF format in Verilog. Once you've read in the image, then you can write out a 160x120 array in a format that you can read in easily in Verilog.

  • \$\begingroup\$ Thank you. This is for project and one of the requirements is we can't use programming languages. The image doesn't have to be in the .MIF format - I only assumed it should be since all my work with images in the past used .MIF images. What format do you suggest I use and how would I read in that format? \$\endgroup\$
    – dfg
    Commented Nov 9, 2014 at 23:04
  • \$\begingroup\$ The format you choose depends heavily on what you want to do with the image. For instance, if you want to display it on a TFT you might choose raw 565 (16-bit) format. \$\endgroup\$
    – Majenko
    Commented Nov 9, 2014 at 23:14
  • \$\begingroup\$ A ppm or a bmp would most likely be easier to parse than a MIF. \$\endgroup\$ Commented Nov 9, 2014 at 23:15
  • \$\begingroup\$ @alex.forencich Reading in a bmp would be perfect! How would I do this? \$\endgroup\$
    – dfg
    Commented Nov 9, 2014 at 23:17
  • \$\begingroup\$ @Majenko-notGoogle I would dividing the image into sub matrices, encrypting the sub matrices, recombining them into an image and then displaying that image via VGA. \$\endgroup\$
    – dfg
    Commented Nov 9, 2014 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.