Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
isp:hsl-_rgb [2019/05/27 23:07] – [Detailed algorithm] Igor Yefmov | isp:hsl-_rgb [2019/05/31 03:52] – [Division-less division] Igor Yefmov | ||
---|---|---|---|
Line 2: | Line 2: | ||
The text below is based on an Excel workbook attached to this page: {{ : | The text below is based on an Excel workbook attached to this page: {{ : | ||
===== Preface ===== | ===== Preface ===== | ||
- | Much is written and is available on the color space conversion from HSL to RGB (for example this [[https:// | + | Much is written and is available on the color space conversion from HSL to RGB (for example this [[https:// |
The below article details the way to perform this conversion without the use of division operations with high enough precision as to satisfy the imaging pipeline quality requirements for the SUB2r camera based on Artix-7 100T FPGA. | The below article details the way to perform this conversion without the use of division operations with high enough precision as to satisfy the imaging pipeline quality requirements for the SUB2r camera based on Artix-7 100T FPGA. | ||
Line 10: | Line 10: | ||
* \(H\) (hue) is a signed '' | * \(H\) (hue) is a signed '' | ||
* \(S\) (saturation) is an '' | * \(S\) (saturation) is an '' | ||
- | * \(L\) (luminosity) is a '' | + | * \(L\) (luminosity) is a '' |
The output of this conversion is an \(RGB\) triplet '' | The output of this conversion is an \(RGB\) triplet '' | ||
Line 20: | Line 20: | ||
\[\frac{1}{x} = \frac{1*N}{x*N}\] | \[\frac{1}{x} = \frac{1*N}{x*N}\] | ||
and choosing \(N\) such that \(x*N\) is a whole power of \(2\) we have an optimization where a division is replaced by a pair of a multiplication followed by a (super cheap!) bit-shift operation by \(Z\) bits: | and choosing \(N\) such that \(x*N\) is a whole power of \(2\) we have an optimization where a division is replaced by a pair of a multiplication followed by a (super cheap!) bit-shift operation by \(Z\) bits: | ||
- | \[\frac{C}{x} = C*\frac{1}{x} = C*\frac{1*N}{x*N} = C*\frac{N}{2^Z} = [(C*N)>>Z]\] | + | \[\frac{C}{x} = C*\frac{1}{x} = C*\frac{1*N}{x*N} = C*\frac{N}{2^Z} = [(C*N) |
The value \(Z\) depends on the needed precision and, of course, the higher the \(Z\) the less precision loss there will be in the end. | The value \(Z\) depends on the needed precision and, of course, the higher the \(Z\) the less precision loss there will be in the end. | ||
Line 28: | Line 28: | ||
The last part, losing the 14 LSB, doesn' | The last part, losing the 14 LSB, doesn' | ||
- | ===== Step-by-step algorithm ===== | ||
- | ==== Precise calculations ==== | + | ===== Precise calculations |
As a refresher this is how [[https:// | As a refresher this is how [[https:// | ||
Line 59: | Line 58: | ||
\[(R, | \[(R, | ||
- | ==== Detailed | + | ===== Step-by-step |
Armed with the above information we can now compile the necessary sequence of calculations and format it into an easy-to-use table: | Armed with the above information we can now compile the necessary sequence of calculations and format it into an easy-to-use table: | ||
Line 66: | Line 65: | ||
| 2 | \[s\] | \[sat(pixel)\] | '' | | 2 | \[s\] | \[sat(pixel)\] | '' | ||
| 3 | \[l\] | \[luma(pixel)\] | '' | | 3 | \[l\] | \[luma(pixel)\] | '' | ||
- | | 4 | \[H\] | \[(H+360^\circ) \bmod 360^\circ\] | '' | + | | 4 | \[H\] | \[(H+360^\circ) \bmod 360^\circ\] | '' |
- | H = (h1 > 0 ? h1 : h1 + 4096);</ | + | H = (h1 > 0 ? h1 : h1 + 4096);</ |
| | \(S\)((not needed for calculations)) | \[\frac{S}{255}\] | | \[0..1\] | | | | | | \(S\)((not needed for calculations)) | \[\frac{S}{255}\] | | \[0..1\] | | | | ||
| | \(L\)((not needed for calculations)) | \[\frac{S}{511}\] | | \[0..1\] | | | | | | \(L\)((not needed for calculations)) | \[\frac{S}{511}\] | | \[0..1\] | | | | ||
| 5 | \[L^\prime\] | \[1-|2L-1|\] | '' | | 5 | \[L^\prime\] | \[1-|2L-1|\] | '' | ||
- | | 6 | \[C\] | \[L^\prime \times S\] | '' | + | | 6 | \[C\] | \[L^\prime \times S\] | '' |
- | | 7 | \[H^\prime\] | \[\frac{H}{60^\circ}\] | '' | + | | 7 | \[H^\prime\] | \[\frac{H}{60^\circ}\] | '' |
| 8 | \[H^\prime_2\] | \[H^\prime \bmod 2\] | '' | | 8 | \[H^\prime_2\] | \[H^\prime \bmod 2\] | '' | ||
- | | 9 | \[\] | \[\] | '''' | + | | 9 | \[H^\prime_{2-1}\] | \[H^\prime \bmod 2 - 1\] | '' |
- | | 10 | \[\] | \[\] | '''' | + | | 11 | \[H^\prime_{final}\] | \[1-|H^\prime \bmod 2 - 1|\] | '' |
+ | | 12 | \[X\] | \[C \times H^\prime_{final}\] | '' | ||
+ | | 13 | \[(R_1, | ||
+ | / | ||
+ | }else if(Hp < 364*2){ | ||
+ | / | ||
+ | }// | ||
+ | | 14 | \[m\] | \[L - C/2\] | '' | ||
+ | | 15 | \[(R,G,B)\] | \[(R_1+m, | ||