International Journal of Engineering & Science Research
Total Page:16
File Type:pdf, Size:1020Kb
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 computer graphics, each pixel has three channels of colour information red, green, and blue and sometimes a fourth called the alpha channel. Alpha channel is generally useful for controlling transparency 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 semi-transparent. 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 32-bit 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 compositing of digital images. In visualization we utilize these alpha-blending techniques in ray-tracing 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 matte 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 (non-premultiplied) 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 operation . 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)] Image editing 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.