View Streamed Image data on Simulink in Real-time
Two more months to go and it ends the final semester of final year at the University. All are rushing to finalise their final year projects, do simulations again and again, create test cases etc. Since our final year project is related to FPGA implementation of an image processing application, we used to work with images and they need to send as a data stream to the FPGA for processing. When performing simulations (Using MATLAB Simulink Xilinx Block set) we created the image in to data stream and sent it via Ethernet cable to the FPGA, so called Hardware co-simulation. The way we created the data stream is described in my previous article and I wish to add another article on Hardware Co-simulations in future.
However we had a small problem which the resulted image can only be viewed after performing the full simulation, which takes a lot of time, sometimes it takes hours. So finally by using a combination of MATLAB function block, unit delay block and video viewer block we were abled to design a model which reshapes the image stream back to its original image in real-time. From this article I will share my experience on creating the real-time image viewer for image streams.
As I described previously the model consists of three blocks. The video viewer is in the “Video/Image processing tool box” or in “Computer Vision System tool box” in Simulink depending on the MATLAB version you use. The unit delay block set can be found in “Simulink block” set under “Discrete” category. This block is used to stop creating an algebraic loop during the simulation.
The most important part of the model is the function inserted in the MATLAB function block is as follows.
function [image, imgout] = imageControl(data, index, eos, img) row_cnt = 130; col_cnt = 198; if (eos==0) if (index<2) frm = zeros(row_cnt,col_cnt); image = cast(frm,'uint8'); imgout = cast(frm, 'double'); else image = cast(img,'uint8'); end data = cast(data,'uint8'); x = 1 + rem(index,row_cnt); y = 1 + floor(index/row_cnt); image(x,y) = data; imgout = cast(image, 'double'); else imgout = cast(img, 'double'); image = cast(img,'uint8'); end
The variable “data” is used to send the processed pixel from the application. Index is simply a counter output which defines the pixel number. “eos” is the flag which goes up with the last pixel of the image comes out from the application which denotes that very last pixel of the image has also been processed. “img” is the feedback reference of last output image.
Since MATLAB function block does not have a storage kind of thing we store the image in delay block (since direct feedback is impossible) and update that image with new data. When using this model you need to update the variables “row_cnt” and ”col_cnt” by the number of rows and columns of the image. Block diagram which describes how to connect the model in to an application is as follow.
The blocks “step1” and “step2” is used to represent the flags of data out is ready and end of stream. With this block you can visualise the image processing simulations as follow using video viewer block.
From that I conclude this article and hope that I shared some useful information with you. Thank you very much for reading.