image algo to vhdl conversion

3 views (last 30 days)
Gaurav
Gaurav on 11 Oct 2013
Edited: Walter Roberson on 15 Oct 2013
I am unable to convert a simple image code into vhdl using hdl coder. Please help
FUNCTION:
%#codegen
function[a,b]=imate2vhdl(x)
a=imread(x);
b=im2bw(a);
TESTBENCH:
x = 'v.jpg';
[a,b]= imate2vhdl(x);
imshow(b);
is there any problem with the code?

Accepted Answer

Tim McBrayer
Tim McBrayer on 11 Oct 2013
The function you wish to generate HDL for contains two function calls (imread and im2bw), and neither function is supported for HDL code generation. imread reads a file from disk and decodes the binary format; in this case, JPEG. I'm not sure what hardware you expect HDL Coder to build for such a function call; in any case, HDL coder does not support it.
The reason that HDL Coder does not support im2bw is that it operates on a frame buffer. The entire image is processed at once, as an image. As written, HDL Coder has no idea even how large the image is.
In general, hardware processing of images or video needs to be performed in a streaming fashion. I could envision remodeling this design so that:
  • The image size is fixed and defined
  • The image is streamed, one pixel at a time, into the hardware design
  • The incoming data stream is processed, pixel by pixel, performing the transform
  • The transformed data is streamed out of the hardware portion back into an image buffer
This of course is one approach. It is so simple because the filter you wish to use is a simple pixel-level filter. The HDL Coder examples contain more complex examples of image processing code. For more information about generating HDL for image processing, see one or more of these published examples. They are a standard part of the HDL Coder documentation.
  • Sobel Edge Detection
  • 2D FIR Filter
  • Corner Detection
  • Adaptive Median Filter
  • Contrast Adjustment
  • Image Enhancement by Histogram Equalization
  • Image Format Conversion: RGB to YUV
  • High Dynamic Range Imaging
  2 Comments
Gaurav
Gaurav on 11 Oct 2013
Sir, then how would I be able to perform the above mentioned operations if I am not able to read the image in vhdl code form?
Tim McBrayer
Tim McBrayer on 15 Oct 2013
Your testbench is what reads the file. Since you want to implement such a simple filter, you can read the image into the TB, and serialize it one pixel at a time into your design. Your design will apply the filter to the pixel and produce the output, delivering it back to the TB. The TB will receive the pixel stream and reassemble it into an image.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!