Average method:
Luminosity Method:
The above given formulae can be implemented in 2 ways in Verilog – one using the RTL division technique, and the other using basic shift operation, and hence dividing in powers of 2.
Verilog Code for implementation with divisionWe can see a delay of one clock cycle before we get the result for luminosity method because the RTL division (implemented by Vivado) needs one clock cycle to provide the output. To avoid this delay and get the output in the next clock cycle, we can further optimize the logic and remove the RTL division and insert a shift operator instead and use only multipliers, as division is usually more expensive than multiplication in terms of logic and cycle count.
Reframing the formulae to use “<<” in place of division, where we divide in powers of 2.
Both the equations given above “divide by 256” can be replaced by >> 8
Verilog Code for implementation with shift operationBut the test fails, as this logic cannot give accurate results, we can observe that the actual is a little more than the expected result, by 1 in binary. Yet this does not degrade the quality of the generated Grayscale image.
Integrating the Custom logic into the system by interfacing with PSThe logic is added as an AXI peripheral which can be easily connected to the Zynq via the AXI interconnect. There are other ways of connecting it such as interfacing via a GPIO peripheral or using AXI stream for faster data transfer by using a DMA. But for this exercise, since the image size is quite small, we can store it in PS and then transfer it to the logic via the AXI interface through memory mapped register.
Given below is the memory map of the implemented system, there are:
The peripheral registers for the IP are shown below:
Shift method
Division method
We can clearly see that the division uses more LUTs than the shift method, which is relatively time consuming, but it still does not affect the performance so much in non-real-time-based systems. But it does give more accurate grayscale images.
The design is implemented in MicroZed System on Module (SoM), and Xilinx SDK is used to build the software
A Python code is written to generate random RGB values for testing the implementation
Example Image generated from Python
Captured via the SDK Terminal for 4 × 4 image
RGB Image Input:
Grayscale Image:
The Luminosity method proves to be more accurate than the average method in converting RGB to Grayscale images, as it preserves more details. The images shown above demonstrate this.
The Division method produces more accurate results than the average method, while the luminosity method has the penalty of one extra clock cycle. The shift method is faster and can be used for real-time systems where timing is more important than accuracy.
Comments
Please log in or sign up to comment.