You are on page 1of 5

Proceedings of TENCON 2018 - 2018 IEEE Region 10 Conference (Jeju, Korea, 28-31 October 2018)

Design and Implementation of Reversible Logic


based RGB to Gray scale Color Space Converter

Sithara Raveendran, Pranose J Edavoor, Nithin Kumar Y. B., Vasantha M. H.


National Institute of Technology Goa, India
Email: (sithararaveendrann,pranose)@gmail.com, (nithin.shastri, vasanthmh)@nitgoa.ac.in

Abstract—Color space conversion is an age old technique used Efficient conversion in color space especially RGB to gray
to achieve ease in processing, feature extraction, compression and scale color space conversion plays a key role in reducing the
storage of image and video data. One such color space conversion computational complexity and cost for algorithms that find ap-
is RGB to gray scale conversion. Gray scale representation of plication in computer vision. The reduction in computations is
images aids in reducing storage space and increasing speed of achieved by reducing the color channels. The main challenges
operation. This paper presents a color space conversion scheme
using reversible logic gates. An RGB color space to gray scale
involve preservation of details of color, luminance and edge.
color space conversion using color channel averaging method Implementation of color space converter using reversible
and color space desaturation method is implemented in this logic nullifies the internal energy dissipation as it provides
paper. Reversible logic/computations have emerged as a major computations that does not result in information loss. An RGB
alternative to decrease the power dissipation in digital circuits.
to gray scale color space converter is presented in this paper
Reversible sub modules like 8-bit adder, comparator, shifter
etc are used to implement the color space conversion. The with two architectures - 1) color channel averaging and 2)
implementation of reversible logic circuits was done and the color space desaturation. Reversible circuit implementation has
functionality verification was done on Kintex 7 FPGA platform. been carried out and the efficiency of the circuit is measured
The results are projected in terms of gate count, ancilla input, in terms of quantum cost(QC), gate count(GC), number of
garbage output and quantum cost for reversible implementation ancilla inputs(AI) and the number of garbage outputs(GO). The
and in terms of hardware utilization and power for FPGA. The functional verification[4] is done on an FPGA using Verilog
proposed reversible circuit complies with the color conversion HDL. The PSNR for each method is analyzed to measure the
standards and can find application in any low power image and efficiency of the reversible color space conversion circuits.
video processing applications.
The paper is organized as follows. Section II introduces
Keywords—Reversible logic, Color space conversion, RGB to
Gray scale, Reversible logic gates, FPGA.
the basic concepts of reversible circuit design. The proposed
architectures namely Color channel averaging method and
Color space desaturation method along with reversible logic
I. I NTRODUCTION implementation is discussed in Section III. The results obtained
In the present era of power hungry devices, quantum are presented in Section IV followed by conclusion in Section
technology has emerged as a promising technology. The main V.
theory behind which the quantum logic is based on, is the
law of conservation of energy. Law of conservation of energy II. BASICS OF REVERSIBLE CIRCUIT DESIGN
states that energy can never be created nor destroyed; rather Design and implementation of reversible circuits has to
it can only be transformed from one form to another. The comply with a set of rules[5][6] that differentiates it from the
fundamental law of conservation of energy is incorporated in conventional combinational circuits.
the design of systems, to be precise, the circuits in quantum
logic/ quantum technology[1]. Quantum technology has shown ∗ Number of Inputs = Number of Outputs
promising results in power consumption of a circuit. Theoret- ∗ Circuit has to be logically reversible - unique mapping
ically it is proved that the quantum logic circuits does not between input and output.
consume any power for internal computations. ∗ Circuit has to be physically reversible - circuits are
backward deterministic.
R. Landauer[2] had stated in 1960s that irrespective of the ∗ Fan-out is not permissible in reversible circuits.
design technique, energy dissipation is incurred in irreversible
∗ Feedback paths should not exist in reversible circuits.
hardware circuits and this was due to the information loss. His
study showed that for each bit of information that is lost in The design parameters and constraints to be considered while
a computation in non reversible circuits, a minimum of kTln2 designing reversible circuits are :
joules of energy(heat), is dissipated; where k= 1.38065051023 1) Quantum cost - The number of elementary quantum
J per K is the Boltzmann constant and T is the absolute oper- gates required to implement a function.
ating temperature of the computation. With further studies in 2) Garbage Output - The output bits added to a re-
this area, Bennett established that circuits using reversible logic versible functional block to achieve reversibility.
gates can avoid the kT ln2 joules of energy dissipation[3]. With 3) Ancilla Input - The input bits added to a reversible
this ground breaking theory, quantum circuits was considered functional block to achieve reversibility.
to be information-lossless circuits with the ability to reduce 4) Gate Count - The number of reversible gates used in
the power dissipation in the form of heat. the reversible functional block.

Authorized licensed use limited to: VISVESVARAYA NATIONAL INSTITUTE OF TECHNOLOGY. Downloaded on April 15,2024 at 05:32:46 UTC from IEEE Xplore. Restrictions apply.
978-1-5386-5457-6/18/$31.00 ©2018 IEEE 1813
Proceedings of TENCON 2018 - 2018 IEEE Region 10 Conference (Jeju, Korea, 28-31 October 2018)

QUANTUM QUANTUM R G B
GATE DELAY
REPRESENTATION COST

Not A x A’ 1 1 REVERSIBLE
8-BIT ADDER
Feynman A A 1 1
Cy1 Sum
B A B

A A REVERSIBLE
Toffoli B B 5 5 8-BIT ADDER
C AB C Cy2 Sum
A A
Fredkin 5 REVERSIBLE
B B 5
FULL ADDER
C AB C

A A 3
REVERSIBLE 10-BIT DIVIDER
B A C 6 6
HNFG
C B
D B D
GRAY COMPONENT
A A
Peres 4 4 Fig. 2: Architecture of Reversible Color Channel Averaging
B A B
C AB C

Fig. 1: Architecture of Reversible Color Channel Averaging A Half Sum


Feynman
B Full Sum

Cin Toffoli Fredkin Cout

I1 g1
The constraints on the designer while designing a reversible I2
Feynman
g2
circuit[7][13] is to keep the QC, GC, AI and GO to the
minimum as it reduces the hardware cost and complexity. The
Fig. 3: Reversible Full Adder
basic gates[8][11] that are used in the paper are briefed in Fig.
1.

III. P ROPOSED RGB TO G RAY-S CALE CONVERSION . 8-bit reversible adder for calculating sum of R and G
CIRCUITS USING REVERSIBLE LOGIC components(result will be 9 bits)
Complex image processing algorithms like computer vision . 8-bit reversible adder to add B component to the sum
tasks, demands a high performance and low-power RGB to of R and G(result will be 9 bits)
gray-scale conversion circuits to reduce the computational . Reversible full adder to add the carry generated from
load on the channel. Several methods have been proposed two 8-bit adders
in the past for efficient color space conversion from RGB to . Reversible Divider circuit with 10 bit dividend and
gray-scale. Widely used methods include averaging the values divisor.
at each color channel, desaturation of color space, weighted
sum method and other color-to-gray approaches[9][10]. Two 1) Reversible Adder: The full adder circuit used, is the
main color-space conversion schemes for RGB to gray-scale reversible adder proposed by Aditya et. al.[14] which has
conversion are used to realize the reversible hardware in this minimum gates and depth. The full adder circuit is as shown
paper, namely: in Fig. 3.
1) Color channel averaging method 8-bit reversible adder is implemented using 8 reversible full
2) Color space desaturation method adders. A Full adder has a GC of 4, AI of 2, GO of 3 and QC
of 12
A. Color Channel Averaging Method Design Summary: An n-bit adder has a GC of 4n, AI of 2n,
GO of 3n and QC of 12n
Averaging is the most common gray-scale conversion tech-
nique. 2) Reversible Divider: A fixed point divider[15] is em-
R+G+B ployed in the proposed architecture as shown in Fig. 4. The
Gray Component = (1)
3 inputs to the divider are the 10-bit dividend(Dd ) and 10-bit
divisor(Dv ). Quotient(Qu ) and remainder(Rm ) are the outputs.
This method is considered to be the simplest method as it Dd can be expressed in terms of Dv , Qu and Rm as shown
is easy to implement and optimize the hardware. One of the in Eq. 2.
major drawbacks of this method is that the representation of Dd = Dv × Qu + Rm (2)
gray shades is not at par with the luminosity perception of
humans. Proposed reversible color channel averaging circuit Division operation is performed by right shifting Dv by k bits
is as shown in Fig. 2. at k th iteration. If the remainder in k th iteration Rmk <Dv 2−k ,
Hardware required: the Quk is set to 1. If this condition is not met, Quk is set to

Authorized licensed use limited to: VISVESVARAYA NATIONAL INSTITUTE OF TECHNOLOGY. Downloaded on April 15,2024 at 05:32:46 UTC from IEEE Xplore. Restrictions apply.
1814
Proceedings of TENCON 2018 - 2018 IEEE Region 10 Conference (Jeju, Korea, 28-31 October 2018)

S=0 a10 a1 a0 d9 d2 d1 d0
R G B

2-input 11-bit Multiplexer 2-input 10-bit Multiplexer FAN-OUT


SELECT SELECT
GENERATOR
1
CLK
CLK R G B B G R
10-bits Reversible S1 S0 10-bits Reversible E
E REVERSIBLE REVERSIBLE
Left-Shift Register Left-Shift Register
HOLD2
S1 S a10 a1 a0 q9 q2 q1 q0 HOLD1 MAX MIN
1 0 0 0 0 0 0 ESTIMATOR ESTIMATOR
Peres
FG FG FG FG FG FG FG

0
r10 r1 r0
q9 q2 q1 q0 REVERSIBLE
8-BIT ADDER
0 SIG Control CLK

FG SIG GRAY COMPONENT


V9 V1 V0
EXTRACTOR

Divisor GRAY COMPONENT


0

FG FG FG FG
Fig. 5: Architecture of Reversible Color Space Desaturation

0 0 R7 0 0 R6 0 0 R5 0 0 R4 0 0 R3 0 0 R2 0 0 R1 0 0 R0
Augend Augend Cin
11 - bit Adder
MSB Sum 11-bit LSB DFG DFG DFG DFG DFG DFG DFG DFG
1

FG R7 R7 R6 R6 R5 R5 R4 R4 R3 R3 R2 R2 R1R1 R0 R0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

DFG DFG DFG DFG DFG DFG DFG DFG

Fig. 4: Reversible Divider R7 R7 R6 R6 R5R5 R4 R4 R3R3 R2R2 R1R1 R0 R0


0 0 0 0 0 0 0 0

FG FG FG FG FG FG FG FG

th
0. The remainder for k + 1 iteration is estimated as in Eq. R7 R7 R6 R6 R5 R5 R4 R4 R3 R3 R2 R2 R1 R1 R0 R0
3.
Rk+1 = Rk − Dv × 2−k Quk (3) Fig. 6: 8-bit Fan-out Generator

Non restoring division is performed in this design. If Quk =


1, Rk+1 is estimated by subtraction and if Quk = 0, Rk+1 is
calculated by adding Dv to Rmk . . Fan-out generator to create copies of R, G and B.
Design Summary: An n-bit divider has a GC of 18n+17, GO . Reversible Max estimator to find maximum of R, G
of 11n+18 and QC of 61n+50. and B.
. Reversible Min estimator to find minimum of R, G
B. Color Space Desaturation Method and B.
. 8-bit reversible adder.
Saturation of a color refers to how vivid a color is. It is
also a representation of the percentage of existence of that . Gray component extractor to extract the significant
particular color in that shade. If the saturation is zero, then it gray component(8 bits) from 9 bit adder output from
will produce gray color. The brightness of a color refers to the 8-bit reversible adder.
lightness of a color. White has 100% lightness and black has 1) Reversible Fan-out Generator: The reversible fan-out
0% lightness. generator as shown in Fig. 6 consists of 8 individual fan-out
generation unit. Each unit consists of two Double Feynman
Gate(DFG) and a single Feynman Gate(FG). Each fan-out
M ax(R, G, B) + M in(R, G, B) generator generates 6 copies of each color component.
Gray Component = (4)
2 An n-bit adder has a GC of 3n, AI of 5n, GO of 0 and QC of
5n
Desaturation refers to taking a color and converting it to
its least-saturated variant. Desaturation of a pixel involves 2) Reversible Max/Min Estimator: The reversible Min/
calculating the midpoint of maximum of (R, G, B) and Max estimator is as shown in Fig. 7. In this stage, first R and
minimum of (R, G, B) as shown in Eq. 2. The end result G are compared and the maximum/ minimum is calculated.
is a softer, flatter gray-scale image. Proposed Reversible Color The output of Comparator acts as the select line for the 8 line
Space Desaturation circuit is as shown in Fig. 5. Min/Max Selector. The Max / Min value thus generated is
passed through a fan-out generator to obtain copy. This again
Hardware required: is passed through the second comparator to get the final Max/

Authorized licensed use limited to: VISVESVARAYA NATIONAL INSTITUTE OF TECHNOLOGY. Downloaded on April 15,2024 at 05:32:46 UTC from IEEE Xplore. Restrictions apply.
1815
Proceedings of TENCON 2018 - 2018 IEEE Region 10 Conference (Jeju, Korea, 28-31 October 2018)

TABLE I: Reversible logic parameters for individual blocks in color channel averaging and color space desaturation
Color Channel Averaging Color Space Desaturation
Design Block GC AI GO QC Design Block GC AI GO QC
Full Adder 4 2 2 12 Min/Max Selector 8 0 1 40
8-bit Adder 32 16 24 96 Fan-out Generator 24 40 0 40
Divider 197 115 128 660 Comparator 25 18 32 88
Complete color channel averaging module 265 149 178 768 Complete Color Space Desaturation module 138 146 66 376

TABLE II: FPGA implementation for individual blocks in color channel averaging and color space desaturation
Color Channel Averaging Color Space Desaturation
Total Power Total Power
Design Block Slice LUTs Design Block Slice LUTs
Dissipation Dissipation
Full Adder 2 2.131 Min/Max Selector 8 5.924
8-bit Adder 25 14.897 Fanout Generator 24 16.997
Divider 176 93.938 Comparator 24 12.708
Complete Color Channel Averaging Module 228 125.863 Complete Color Space Desaturation Module 149 82.955

Min value. The resultant Max/ Min value is selected using


another 8 bit Min/Max Selector.

R G

B R G R G B
Comparator
R >G
Min Max
Selector Selector (a) Pepper Original (b) Lena Original (c) Butterfly Original
SELECT
Min1 Max1
Fan out Generator B B Fan out Generator
Min1 Min1 Max1 Max1
Comparator Min Max Comparator
Min1 < B SELECT
Selector Selector SELECT Max1 > B

Min_Value Max_Value

Fig. 7: 8-bit Reversible Max/Min Estimator


(d) Pepper (e) Lena (f) Butterfly
Color Channel Color Channel Color Channel
Averaging Averaging Averaging
3) Reversible Min/Max Selector: The Max/Min selector
is as shown in Fig. 8.Maximum of the other two inputs will
directed to output named max. The SELECT input from the
comparator, decides the input to be directed.
An n-bit Max / Min Selector has a GC of 8n, AI of 0, GO of
n and QC of 5n

4) Reversible Adder and Gray component extractor: The


fuller adder circuit is as shown in Fig. 3. 8-bit reversible adder (g) Pepper (h) Lena (i) Butterfly
is used. Gray component extractor assigns the invalid bits as Color Space Color Space Color Space
garbage outputs and passes only the valid 8-bits as the gray Desaturation Desaturation Desaturation
equivalent for the pixel.
Fig. 9: Original and color space converted Images
SELECT SELECT SELECT SELECT_OUT
Fredkin

Fredkin

Fredkin

R0 max1 R1 max2 R7 max7


IV. R ESULTS
G0 min1 G1 min2 G7 min7
A. Reversible logic implementation Results

Fig. 8: Max / Min Selector Reversible logic implementation was done to extract the
delay and quantum cost of the proposed architectures.

Authorized licensed use limited to: VISVESVARAYA NATIONAL INSTITUTE OF TECHNOLOGY. Downloaded on April 15,2024 at 05:32:46 UTC from IEEE Xplore. Restrictions apply.
1816
Proceedings of TENCON 2018 - 2018 IEEE Region 10 Conference (Jeju, Korea, 28-31 October 2018)

The QC, AI count and GB count for individual blocks [9] Amy A. Gooch, Sven C. Olsen, Jack Tumblin, and Bruce Gooch,
and for complete color channel averaging and color space “Color2gray: salience-preserving color removal”,ACM Transactions on
Graphics (TOG). ACM, 2005, vol. 24, pp. 634639.
desaturation modules are given in Table I.
[10] Yongjin Kim, Cheolhun Jang, Julien Demouth, and Seungyong Lee, ,
“Robust color-to-gray via nonlinear global mapping,” ACM Transactions
B. FPGA Implementation Results on Graphics (TOG). ACM, 2009, vol. 28, p. 161.
[11] Ali, N.B., Sajjad, W., Nazir, H.: A new approach of presenting reversible
Functional verification of the proposed architectures for logic gate in nanoscale (SpringerPlus, 2015), vol. 4, p. 153
RGB to Gray scale color space conversion using reversible [12] Guowu, Y., Hung, W.N.N., Xiaoyu, S., et al.: Majority-based reversible
logic was done using Kintex 7 FPGA. The simulations logic gates, Theor. Comput. Sci., 2005, 334, (13), pp. 259274
were carried out on Vivado 2016.4 and the design was done [13] Lenin, G., Nor, S., Mohd, M., et al.: Design and synthesis of reversible
using Verilog Hardware Description Language. The hardware arithmetic and logic unit (ALU). IEEE Conf. Computer, Communications,
utilization for individual blocks are as show in Table II. and Control Technology (I4CT), 2014
[14] M. Aditya, Y. B. N. Kumar and M. H. Vasantha, “Reversible full/half
adder with optimum power dissipation”, 2016 10th International Con-
The hardware utilization and power consumption for pro- ference on Intelligent Systems and Control (ISCO), Coimbatore, 2016,
posed architectures namely color channel averaging method pp. 1-4.
and color space desaturation method is also tabulated in Table [15] N. M. Nayeem, A. Hossain, M. Haque, L. Jamal and H. M. H. Babu,
II. It can be see that the hardware utilization and power “Novel reversible division hardware,” 2009 52nd IEEE International
Midwest Symposium on Circuits and Systems, Cancun, 2009, pp. 1134-
consumption is more for color channel averaging module. The 1138.
color space converted images on FPGA platform for both is
as shown Fig. 9.

V. C ONCLUSION
This paper proposes the architecture for a reversible logic
based color space conversion unit for RGB to Gray scale
conversion. Two architectures are proposed mainly color chan-
nel averaging method and desaturation method. The accuracy
of functional block for conversion unit was tested by using
FPGA using Verilog Hardware description language. It is
seen the Quantum cost for color channel averaging method
is 104% more than color space desaturation method.GC of
color channel averaging is 92% more when compared to color
desaturation method.Color space desaturation shows a 34%
reduction in Slice LUT and dissipates 34.4% less power when
compared to color channel averaging method. For randomly
distributed R, G, B values, color channel averaging method
will give better results while conversion when compared to
color space desaturation method. Both the methods are verified
thoroughly and can be the starting blocks for image processing
blocks using reversible logic.

R EFERENCES
[1] Toffoli, T. “Reversible computing”, Technical Memo MIT/LCS/TM-151,
MIT Lab. for Computer Science, 1980 (unpublished)
[2] R. Landauer, “Irreversibility and heat generation in the computing
process”, IBM J. Research and Development, vol. 5(3), pp. 183191, 1961.
[3] C. H. Bennett, “Logical reversibility of computation”, IBM J. Research
and Development, vol. 17, pp. 525532, 1973.
[4] P. J. Edavoor, S. Raveendran and A. D. Rahulkar,“Implementation
of adaptive image compression algorithm using varying bit-length
daubechies wavelet coefficient with three-level encryption on Zynq
7000”, 2017 7th International Symposium on Embedded Computing and
System Design (ISED), Durgapur, 2017, pp. 1-6.
[5] M. A.Nielsen, I.L.Chuang,”Quantum Computation and Quantum Infor-
mation,”, Cambridge University Press,2000.
[6] Feynman, R.P.: Quantum mechanical computers, Opt. News, 1985, 11,
pp. 1120
[7] P. Gupta, A. Agrawal and N. K. Jha, “An Algorithm for Synthesis
of Reversible Logic Circuits”, IEEE Transactions on Computer-Aided
Design of Integrated Circuits and Systems, vol. 25, no. 11, pp. 2317-
2330, Nov. 2006.
[8] Moraga, C.: “Mixed polarity reversible peres gates”, IET Electron. Lett.,
2014,50, (14), pp. 987989.

Authorized licensed use limited to: VISVESVARAYA NATIONAL INSTITUTE OF TECHNOLOGY. Downloaded on April 15,2024 at 05:32:46 UTC from IEEE Xplore. Restrictions apply.
1817

You might also like