IJESR/April 2013/ Vol-3/Issue-4/2871-2876 ISSN 2277-2685 International Journal of Engineering & Science Research

ALPHA BLENDING ALGORITHM Dudhagara Kulddep P*1, Keyur Shah 2 1PG student, VLSI , U.V.Patel College of Engineering and Technology, Ahmedabad, India. 2Technical Assistant, Einfochips training and research academy, Ahmedabad, India. ABSTRACT In , each pixel has three channels of colour information red, green, and blue and sometimes a fourth called the alpha . Alpha channel is generally useful for controlling level of image. Alpha blending is generally used for this type of control, and it is used to simulate effects such as placing a piece of glass in front of an object so that the object is completely visible behind the glass, unviewable, or semitransparent. Alpha blending is combination of two images allowing for transparency effects in computer graphics. The value of alpha in the colour code ranges from 0.0 to 1.0, where 0.0 represents a fully transparent colour, and 1.0 represents a fully opaque colour, where values between 0 to 1 represents semitransparent images. 1. INTRODUCTION In Windows GDI+, a colour is a 32bit value with 8 bits each for red, green, blue and alpha. The alpha value describes the transparency of the colour the extent to which the colour is blended with the background colour. Alpha values range from 0 through 255, where 0 represents a fully transparent colour and 255 represents a fully opaque colour. Alpha blending is a pixel by pixel blending of source and background colour data. Each of the three components (red, green, blue) of a given source colour is blended with the corresponding component of the background colour according to the following formula: Result Colour (Display) = source Colour × alpha / 255 + background Colour × (255 – alpha) / 255 For example, suppose the red component of the source colour is 200 and the red component of the background colour is 100. If the alpha value is 200, the red component of the resultant colour is calculated as follows: 200 × 200 / 255 + 100 × (255 – 200) / 255 = 178 Alpha blending is a common technique in computer graphics and visualization. It is utilized to approximate illumination calculations through transparent or translucent objects. The technique was initially developed by Tom Porter and Tom Duff at Pixar to do simple of digital images. In visualization we utilize these alphablending techniques in raytracing and splitting applications to build up the visibility of image features. The techniques are straightforward and can be used in a number of applications. It's a way of mixing the colors of two images together to form a resultant image. An example of alpha blending is natural occurring rainbow over a waterfall. If you imagine of the rainbow as a foreground image while waterfall as background image then result of the final image can be formed by combining these two images. It means result image will be

*Corresponding Author www.ijesr.org 2871

IJESR/April 2013/ Vol-3/Issue-4/2871-2876 ISSN 2277-2685

combination of the rainbow and waterfall, where rainbow image will be semitransparent. We can also call alpha blending "translucency" it is the same thing. Also, when the blending factor changes dynamically over time, alpha blending is called "cross fade" or "dissolve." 2. BASING TRANSPARENCY ON A SINGLE VALUE Consider an object in space. We associate with this object an “alpha value” or “opacity value” that will represent the probability that light energy will be blocked by the object. An alpha value of 1 represents an opaque object, and an alpha value of 0 represents a transparent object. It means that alpha value 1 represents fully opaque image, in which background image will not be visible while alpha value 0 represents fully transparent image in which foreground image will be fully transparent and we can see only background image. The following illustration shows several green rectangles with common red background. The five rectangles have different alpha values of 0.1, 0.3, 0.5, 0.7 and 0.9 in order, from left to right as shown in fig.1.

Fig1: Five Green rectangles as foreground and common Red background According to above figure, we can see that when we give alpha value of 0.1 image is almost transparent and we cannot see foreground image (Green colour) and background (Red colour) is fully visible. Respectively when we move from left to right values of alpha is increasing and we can clearly see foreground image and background slightly. So at alpha value 0 images will be fully transparent while at alpha value 1 image will be fully opaque image. The colours resulting from a translucent object with an opaque background are easy to calculate. If we let represent the “opacity” of a rectangle in the illustration, then the colour that the viewer sees when looking at the rectangle is αc + (1α) b Where c is the colour of the rectangle and b is the colour of the background. One can see that if α=1, none of the background will be seen, and if α=0 none of the rectangle will be visible. 3. ALPHA COMPOSITING In computer graphics, alpha compositing is the process of combining an image with a background to create the appearance of partial or full transparency of final image. It is mostly needful to convert different image elements, and then combine that pixels of images and display final single image, we can also call that process as composite. For example, compositing is used extensively when combining computer rendered image elements with live footage. In order to combine these image elements correctly, there is need of associated for each element.

Copyright © 2013 Published by IJESR. All rights reserved 2872

IJESR/April 2013/ Vol-3/Issue-4/2871 -2876 ISSN 2277 -2685

4. DESCRIPTION In the late 1970s the concept of alpha channel was introduced by alvy Ray Smith to store matte information which was fully developed by Thomas Porter and Tom Duff in a 1984. In a 2D image element, which stores each pixels of color and alpha value which stores additional data which ranges from 0 to 1. A value 0 means pixel does not have any coverage information and it is fully transparent while value 1 means pixel c ompletely overlapped the other pixel and pixel is opaque. If an alpha value used in any image, it is obvious to multiply RGB with alpha value to store additional multiplication while compositing, which is usually referred to as premultiplied alpha with RGB . Assuming that the pixel colour is expressed using straight (nonpremultiplied) RGBA tuples, a pixel value of (0.0, 0.4, 0.0, 0.6) implies a pixel which has 40% of the maximum green intensity and 60% opacity. If the colour were fully red, its RGBA would b e (1, 0, 0, 0.5). However, if this pixel uses premultiplied alpha, all of the RGB values (0, 1, 0) are multiplied by 0.5 and then the alpha is appended to the end to yield (0, 0.5, 0, 0.5). In this case, the 0.5 value for the G channel actually indicates 1 00% green intensity (with 50% opacity). For this reason, we need to know whether file uses premultiplied alpha or straight alpha to correctly process or composite it. Premultiplied alpha has some practical advantages over normal alpha blending because prem ultiplied alpha blending is associative and linear interpolation gives better results, although premultiplication can cause a loss of precision and, in extreme cases, a noticeable loss of quality. With the existence of an alpha channel, it is possible to e xpress compositing image operations, using compositing algebra . For example, consider two image elements A and B; the most common alpha blending operation is to merge both images such that image A appears as foreground image and image B appears as backgrou nd image. We can also call this compositing as A over B which is shown in figure.2, where we also shown in and out compositing operators which was defined by porter and Duff in addition to over operator.

Fig 2: Compositing images A and B( over, in, out) The over operator is, in effect, the normal painting operati on . The in operator is the alpha compositing equivalent of clipping. As an example, the over operator can be accomplished by applying the following for mula to each pixel value:

Co = caαa + c bαb (1αa) where C o is the result of the operation, ca is the colour of the pixel in element A, cb is the colour of the pixel in element B, and αa and αb are the alpha of the pixe ls in elements A and B respectively.

Copyright © 2013 Published by IJESR. All rights reserved 2873

IJESR/April 2013/ Vol-3/Issue-4/2871-2876 ISSN 2277-2685

If it is assumed that all colour values are premultiplied by their alpha values(c i = α ici) , we can rewrite the equation for output colour as:

Co = ca + c b (1αa) and resulting alpha channel value is:

αo = c 0/C o = α a + αb (1 αa) However, this operation may not be appropriate for all applications, since it is not associative. The associative version of this operation is very similar; simply take the newly computed colour value and divide it by its new alpha value, as follows:

Co = 1/α o [c aαa + c bαb (1αa)] applications that allow merging of layers generally prefer this second approach. 5. IMPLEMENTATION Matlab provides a powerful image library and what is illustrated here is a simplistic method of alpha blending images in Matlab. Images visibly are 2dimensional rectangles, to understand images and if one needs ever work with them in relation to image processing then images are in fact a 2×3 dimensional matrix. Images are comprised of pixels, mainly a pixel is broken down into three colour attributes which is known as red, green and blue commonly abbreviated as RGB. The three RGB dimensions values are ranges from 0 to 255 because there are 256 states per byte. Most of the bytes are comprised of 8 binary digits abbreviated as bits so highest decimal which can be represent are 255. So we can confirm it using converting 255 decimal numbers into binary number and vice versa. Now these RGB channels when combined represent the true colour of the pixel and all the pixels within the 2dimensional plane represent the actual image that is visible to the end user. Alpha blending or blending imagery is the concept of merging two or more images into one so one can see multiple imagery detail through just one image. This is achieved through the use of percentiles within the range of [0.0,... ,1.0] … a normalised percentage. Let us for this demonstration consider the following two images:

Fig 3: Foreground image Fig 4: Background image

Copyright © 2013 Published by IJESR. All rights reserved 2874

IJESR/April 2013/ Vol-3/Issue-4/2871-2876 ISSN 2277-2685

Consider first image as foreground image and second image as background image. Fig.3 is rescaled and placed on the top of the second image. Here, i have used alpha value of 127.5 so foreground image is partially transparent. Let us consider the first image (above left), let us denote this image 3 and the second image (above right) of which we denote image 4. close all; clear all; clc; a = imread ('3.jpg'); b = imread ('4.jpg'); Using matlab, we can read image into matrix form, then will perform RGB calculation of both images and find final RGB value of resultant pixel using alpha blending equation. Now the above code is taking the 2×3 matrix integers and magnifying them by a percentile, note that the integers will in fact lose their strength because in the best case, the decimal 255 * 1.0 will merely output 255.This is exactly what one wants because we cannot allow any pixel channel integer to possess a value greater than 255 otherwise there would exist an overflow. To achieve the alpha blended result we sum up two original images a(image 3) and b(image 4) divide by number of inputs to the arithmetic mean like so: y = (a+ b) / 2; Fig.5 is an output which is produced in MATLAB using alpha blending equation in which Fig.3 is rescaled and overlapping pixels of Fig.4. So that we can see both images at a time, which is shown in Figure.5:

Fig 5: Alpha blended image obtain in MATLAB 6. CONCLUSION This paper shows implementation of alpha blending algorithm in which we can combine two images and display it as a single image, in which we resize one image and pixels of that image will be overlapping pixels of our background image. Transparency level of pixels will be based on value of alpha which ranges from 0 to 255 where 0 represents fully transparent image while 255 represents fully opaque image. As a future scope, we can also implement this algorithm on FPGA.

Copyright © 2013 Published by IJESR. All rights reserved 2875

IJESR/April 2013/ Vol-3/Issue-4/2871-2876 ISSN 2277-2685

REFERENCES 1) Alpha Blending Lines and Fills http://msdn.microsoft.com/enus/library/windows/desktop/ms533803(v=vs.85).aspx, date: 22/02/2012 2) Alpha_compositing http://en.wikipedia.org/wiki/Alpha_compositing, date: 16/02/2012 3) HighDefinition video deinterlacing using FPGAs white paper by ALTERA www.altera.co.jp/literature/wp/wp01117hdvideodeinterlacing. , date:03/03/2012 4) Picture in Picture http://en.wikipedia.org/wiki/Pictureinpicture, date: 24/01/2013 5) Matlab Tutorial http://www.cyclismo.org/tutorial/matlab, date: 12/01/2012

Copyright © 2013 Published by IJESR. All rights reserved 2876