FPGA-based RGB and HSV color space conversion algorithm

Actual background: In our daily life, the display screen usually uses the RGB color space. However, because the color attributes are not independent in the RGB color space, it is extremely inconvenient to process the image, while the HSV color space This problem can be solved very well. It separates the characteristics of the image's hue, saturation, and brightness, so that it will not cause us to modify one attribute of the image color and affect other attributes.

Conversion formula: RGB color space to HSV color space

Conversion formula of h: Conversion formula of

s:
Insert picture description here

Conversion formula of V:

Insert picture description here
These formulas are of course very simple in mathematics, but here contains a lot of floating-point number multiplication and division operations, and this is precisely what FPGA is not good at, so we need to hardwareize the above formulas. According to the basic idea of ​​avoiding floating-point operations in FPGA, we can first amplify a number to a certain part to eliminate the decimal part, and then divide by a certain multiple to make the number we get as equal as possible to the original number. . For example, to implement 5*0.299 on FPGA, we can first multiply 0.299 by 2^16, and get the actual result as 19595.264. Here we can approximate 19595, and then we can convert the original floating point operation 5 0.299 is converted to the current 5 19595/(2 to the 16th power). Dividing by the 16th power of 2 in the FPGA only needs to discard the last 26 bits of the data, which greatly simplifies the workload of the FPGA.

Therefore, for the above three components of HSV, we need to carry out the hardware transformation of the formula to facilitate its implementation on the FPGA and draw the corresponding hardware flowchart. The following figure gives a reference flow chart for converting RGB to HSV.
Insert picture description here
After we get the corresponding HSV data, we can easily modify the three attributes of hue, saturation, and brightness at will. But HSV is only a color space used for intermediate calculations. This color space cannot be displayed on the display. So in order for us to better see the effect of the change, we need to adjust the hue or saturation or brightness. HSV data is converted to RGB data again.

The formula for converting HSV color space to RGB color space: the
Insert picture description here
same here, we also need to adjust the formula by hardware before it can be realized on FPGA.
In order to see the changes after image adjustment more intuitively, you can use MATLAB to imitate it first. The following effect (the code here has been adjusted, that is, the floating point operation is adjusted to integer operation), the comparison chart after adjusting the brightness is as follows:
Note: You can leave a message if you need the code

Original image:
Insert picture description here

Brightness saturation enhancement
Insert picture description here

Guess you like

Origin blog.csdn.net/jiyishizhe/article/details/103149462