Abstract:
A single-site color image, such as a Bayer CCD image, is converted to a color space image using the resource of a Graphics Processing Unit (GPU). The Bayer image is loaded into the GPU along with commands to cause the texture engine in the GPU to use the Bayer image as a source texture and to compute, for each pixel in a destination image having same dimensions as the single-site color camera image, interpolated neighbor pixel values from the single-site color camera image for the remainder of said colors. A code image can be used to provide, for each pixel in the destination image, a value for each combination of color space image color and each Bayer image color. Each pixel is then computed as a sum of a product of each code image. value and a corresponding value selected from the corresponding source texture pixels and an interpolation of neighboring source texture pixels.

Description:
The present application includes a computer program listing appendix in accordance with 37CFR§1.52(e), the content of which is hereby incorporated by reference. The copyright owner of the said listing has no objection to the facsimile reproduction by anyone of the patent document or disclosure, as it appears in the Patent and Trademark Office patent file or records, but reserves all other copyright rights. 
     TECHNICAL FIELD 
     The present invention relates in general to image processing. More specifically it relates to a method and apparatus for transforming a single-site color camera image (Bayer image) into a color space image. 
     BACKGROUND OF THE INVENTION 
     Color image acquisition systems are widespread nowadays. Several systems and methods are used to capture scenes and display images in color spaces. The cheapest color imaging sensors are those using a “single imaging site” (as described in the Bayer&#39;s patent, “Color imaging array” U.S. Pat. No. 3,971,065). A popular example of a single-site sensor is a Bayer sensor. 
     A Bayer acquisition system is a sensor system that captures scene information in the form of a color pattern. An image output by such a sensor is stored in a particular pattern format. This pattern is characterized by including on a first row of an image, alternating pixels of Red and Green, and then on a next row alternating pixels of Blue and Green. The pattern shown in  FIG. 1  is repeated to fill the image. 
     An example of the Bayer pattern for the first 4 rows of pixels is shown in  FIG. 2 . 
     In this case, each pixel location contains a value for a single color only. It is to be mentioned that this pattern is an example of possible Bayer patterns. It is known in the art that several patterns can be used to capture scenes using a Bayer acquisition system, although the one described above is the most widespread. 
     This type of sensor is increasingly popular for the simple reason that they are cheap and extremely simple to construct and use. 
     However, with a Bayer acquisition system the image obtained is not in a friendly format to be processed or to be displayed. Classical image processing algorithms and display methods are applied to color space images. The image needs to be transformed from a Bayer image to a RGB, YUV or any other color space image. 
     The Bayer transformation consists of finding the missing information for each pixel according to the information provided by the Bayer image. A well-known method to get a color space image from a Bayer image is “near neighbor averaging” or “linear filtering”. In this method, for each pixel location the missing color component is determined by averaging neighboring pixels that are associated with that missing color. For example, P i,j  represents the value of the Green_ 2  pixel at position (i,j) as shown in  FIG. 3 . Values of red, green and blue colors need to be computed at this pixel position. 
     The three color values are computed as follows: 
                   {             R     i   ,   j       =       (       P     i   ,     j   -   1         +     P     i   ,     j   +   1           )     /   2                   G     i   ,   j       =     P     i   ,   j                     B     i   ,   j       =       (       P       i   -   1     ,   j       +     P       i   +   1     ,   j         )     /   2                     Equation   ⁢           ⁢   1               
Where X i,j  is the value of color X at position (i,j).
 
     Similarly, if the pixel color is different the equations are different. 
     The case where at position (i,j) the color is Green_ 1 : 
     
       
         
           
             
               
                 
                   { 
                   
                     
                       
                         
                           R 
                           = 
                           
                             
                               ( 
                               
                                 
                                   P 
                                   
                                     
                                       i 
                                       - 
                                       1 
                                     
                                     , 
                                     j 
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       + 
                                       1 
                                     
                                     , 
                                     j 
                                   
                                 
                               
                               ) 
                             
                             / 
                             2 
                           
                         
                       
                     
                     
                       
                         
                           G 
                           = 
                           
                             P 
                             
                               i 
                               , 
                               j 
                             
                           
                         
                       
                     
                     
                       
                         
                           B 
                           = 
                           
                             
                               ( 
                               
                                 
                                   P 
                                   
                                     i 
                                     , 
                                     
                                       j 
                                       - 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     i 
                                     , 
                                     
                                       j 
                                       + 
                                       1 
                                     
                                   
                                 
                               
                               ) 
                             
                             / 
                             2 
                           
                         
                       
                     
                   
                 
               
               
                 
                   Equation 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   2 
                 
               
             
           
         
       
     
     The case where at position (i,j) the color is Red: 
     
       
         
           
             
               
                 
                   { 
                   
                     
                       
                         
                           R 
                           = 
                           
                             P 
                             
                               i 
                               , 
                               j 
                             
                           
                         
                       
                     
                     
                       
                         
                           G 
                           = 
                           
                             
                               ( 
                               
                                 
                                   P 
                                   
                                     i 
                                     , 
                                     
                                       j 
                                       - 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     i 
                                     , 
                                     
                                       j 
                                       + 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       - 
                                       1 
                                     
                                     , 
                                     j 
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       + 
                                       1 
                                     
                                     , 
                                     j 
                                   
                                 
                               
                               ) 
                             
                             / 
                             4 
                           
                         
                       
                     
                     
                       
                         
                           B 
                           = 
                           
                             
                               ( 
                               
                                 
                                   P 
                                   
                                     
                                       i 
                                       - 
                                       1 
                                     
                                     , 
                                     
                                       j 
                                       - 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       + 
                                       1 
                                     
                                     , 
                                     
                                       j 
                                       - 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       - 
                                       1 
                                     
                                     , 
                                     
                                       j 
                                       + 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       + 
                                       1 
                                     
                                     , 
                                     
                                       j 
                                       + 
                                       1 
                                     
                                   
                                 
                               
                               ) 
                             
                             / 
                             4 
                           
                         
                       
                     
                   
                 
               
               
                 
                   Equation 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   3 
                 
               
             
           
         
       
     
     The case where at position (i,j) the color is Blue: 
     
       
         
           
             
               
                 
                   { 
                   
                     
                       
                         
                           R 
                           = 
                           
                             
                               ( 
                               
                                 
                                   P 
                                   
                                     
                                       i 
                                       - 
                                       1 
                                     
                                     , 
                                     
                                       j 
                                       - 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       + 
                                       1 
                                     
                                     , 
                                     
                                       j 
                                       - 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       - 
                                       1 
                                     
                                     , 
                                     
                                       j 
                                       + 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       + 
                                       1 
                                     
                                     , 
                                     
                                       j 
                                       + 
                                       1 
                                     
                                   
                                 
                               
                               ) 
                             
                             / 
                             4 
                           
                         
                       
                     
                     
                       
                         
                           G 
                           = 
                           
                             
                               ( 
                               
                                 
                                   P 
                                   
                                     i 
                                     , 
                                     
                                       j 
                                       - 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     i 
                                     , 
                                     
                                       j 
                                       + 
                                       1 
                                     
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       - 
                                       1 
                                     
                                     , 
                                     j 
                                   
                                 
                                 + 
                                 
                                   P 
                                   
                                     
                                       i 
                                       + 
                                       1 
                                     
                                     , 
                                     j 
                                   
                                 
                               
                               ) 
                             
                             / 
                             4 
                           
                         
                       
                     
                     
                       
                         
                           B 
                           = 
                           
                             P 
                             
                               i 
                               , 
                               j 
                             
                           
                         
                       
                     
                   
                 
               
               
                 
                   Equation 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   4 
                 
               
             
           
         
       
     
     The Bayer transformation is an essential operation, which cannot be avoided. It is often performed directly in camera systems or on boards containing dedicated hardware elements specifically designed for that purpose. These specialized hardware element are expensive and cannot be used for anything else than a Bayer transform. Other methods use the CPU to perform this transformation. However, in spite of its essential character, the Bayer transform is only a preprocessing operation and its result is often used to do more complex computations. It would be interesting then, to off-load the CPU and use it for other computations. 
     SUMMARY OF THE INVENTION 
     The invention disclosed herein is a method for transforming a Bayer image into a color space image without using any dedicated hardware and by off-loading the CPU. The invention uses a GPU to perform a Bayer transformation in order to obtain rapidly an image ready to be processed or displayed. 
     The invention provides a method for loading an image and instructions in a GPU local memory and performing a Bayer transformation using the GPU texture mapping capabilities to output an image in a desired color space. By using the GPU, the invention permits the user to exploit the advantages of Bayer systems without their inconveniences. In fact, the CPU is off-loaded and can be used to do more complex processing with the output image (edge extraction, pattern matching . . . ), and there is no need for any specialized hardware. 
     According to the invention, there is provided a method for converting a single-site color camera image to a color space image. A single-site color camera image has a plurality of colors with each pixel corresponding to a photosite of one of the colors and a remainder of the colors located at neighboring photosites. The method according to the invention comprises loading the single-site color camera image into a graphics processing unit (GPU) having a texture engine, and loading into the GPU commands to cause the texture engine to use the single-site color camera image as a source texture and to compute, for each pixel in a destination image having same dimensions as the single-site color camera image, interpolated neighbor pixel values from the single-site color camera image for the remainder of the colors. The destination image is then the color space image. 
     In the case that the GPU texture engine does not have branching capabilities or a modulo operator, the invention provides for the use of a code image (or code images, if required) so that differences in computation as a function of source pixel position are provided. In one embodiment, intermediate images for each source color are generated. In another embodiment, the interpolated neighbor pixel values are calculated and stored in registers for use in determining the current destination image pixel value. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
       The invention will be better understood by way of the following detailed description of a preferred embodiment with reference to the appended drawings, in which: 
         FIG. 1  is a diagram of a Bayer pattern; 
         FIG. 2  is a diagram of a Bayer image; 
         FIG. 3  is a diagram of pixel addressing in (i,j) coordinates; 
         FIG. 4  is a schematic diagram of illustrating texture mapping; 
         FIG. 5  is a schematic diagram of a GPU having a texture engine; 
         FIG. 6  is a diagram of a conventional Bayer image having Green 1  and Green 2  source colors; 
         FIG. 7  is a diagram of a conventional RGB color space image; 
         FIG. 8  is a diagram illustrating generation of intermediate images of half-dimensions for each source color component, namely Green 1 , Blue, Red and Green 2  according to a first preferred embodiment; 
         FIG. 9  is a diagram illustrating fetches used for the destination R,G,B pixels of a Green 2  source texture pixel according to a first preferred embodiment; 
         FIG. 10  is a diagram illustrating fetches used for the destination R,G,B pixels of a Blue source texture pixel according to a first preferred embodiment; 
         FIG. 11  is a diagram illustrating fetches used for the destination R,G,B pixels of a Red source texture pixel according to a first preferred embodiment; 
         FIG. 12  is a diagram illustrating fetches used for the destination R,G,B pixels of a Green 1  source texture pixel according to a first preferred embodiment; 
         FIG. 13  is a diagram illustrating the generation of a code data array or image for one destination color component; and 
         FIG. 14  is a diagram illustrating a code image used in a second preferred embodiment. 
     
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
     Introduction 
     The invention provides a solution to the problem of using expensive dedicated hardware or CPU to perform a basic operation, the Bayer transform. This solution is to use a GPU. 
     A GPU (graphical processing unit) is an image array processor with texture mapping capabilities. A texture map associates a destination data array with one or more source data array by computing each destination array element according to destination array element position and source arrays elements.  FIG. 4  illustrates an example where a destination array element Y i,j  is computed according to corresponding source array element X i,j  and its neighboring source elements. The function that calculates a destination element can include basic mathematic functions like interpolation, addition, multiplication, minimum, maximum, etc. 
     The GPU was originally designed as an alternative to the CPU to process 3D graphics transformations. It is a single-chip processor associated with memory that creates lighting effects and transforms objects in 3D scenes. Traditionally GPUs are used essentially in the video game industry, the movie industry, three-dimensional video, and sophisticated scientific/engineering graphics programs. GPU&#39;s are constructed to perform rapidly “expensive” operations on 3D objects. In fact, a GPU is provided with parallel processing units, which allow it to perform complex computations in a short amount of time. 
       FIG. 5  shows a typical design of a GPU as will be familiar to a person skilled in the art. Components  21 , 22 , 25 , 26 , 27  are parts of the GPU integrated circuit. The GPU contains a memory element  27 , which is used to store input data and output data after processing. AGP is a computer interface that allows fast access to RAM. 
     The main component of the GPU is the texture engine  21 . This component contains pixel and vertex shader. 
     The vertex shader  23  is a programmable component. It can execute a series of arithmetic operations on data primitives. The user defines these instructions (arithmetical operations as multiplications and additions, loads and writings from internal registers). Typically data primitives are triangles, line segments or points. 
     The pixel shader is also a programmable component. It executes on pixels a series of arithmetic operations, defined by the user. These pixels result from the rasterization operation of the transformed data primitives, output by the vertex shader. The rasterization is performed either in the pixel shader or by a separate GPU component (not shown) the rasterizer. Here we assume that this component is part of the pixel shader. It is used to transform the primitives output by the vertex shader to a pixel representation, which will allow the display of the image. 
     The GPU contains a display engine  25 . It processes the data in the GPU memory to convert it to a digital or analog signal that can be displayed on TV screens and computer monitors. 
     The GPU also includes, in the preferred embodiment, an acquisition device  26 , which allows the GPU to obtain images directly from a camera without using the CPU or the AGP. 
     The invention provides a method for transforming a Bayer image into a color space image using the image processing capabilities of the GPU. 
     The method involves loading a Bayer image and instructions in GPU local memory and performing a Bayer transformation using the GPU texture mapping capabilities to output an image in a desired color space. 
     In what follows, two preferred embodiments of the invention are described. These examples are provided to illustrate the invention and should not be considered as limiting its scope. In both embodiments of the invention the Bayer pattern is the classical “G_ 1 -R-B-G_ 2 ” as shown in  FIG. 6  and the color space is RGB space as shown in  FIG. 7 . However this should not be seen as a limitation to the invention but only an example, which illustrates it clearly. 
     A First Method: 
     In a preferred embodiment of the invention the Bayer image and instructions are first loaded in GPU local memory. 
     A Bayer image is stored as a data array (source data array) and intermediate data arrays are generated by performing simple GPU operations on the source data array. Then for each array element of a destination data array a color space representation is computed using the GPU texture mapping abilities and the five intermediate data arrays described below. 
     First a Bayer image and instructions are loaded in GPU local memory. The instructions loaded provide GPU commands to perform a Bayer transform on the input image. Then five intermediate data arrays are computed using simple functionality of the GPU. Four of them are sub-sampled arrays of the source data array, namely arrayR, arrayB, arrayG_ 1 , and arrayG_ 2 . Each one contains all source array elements of the same color. Such sub-sampling is a simple scaling function normally used to scale down images, and is performed using the texture engine. 
     The GPU is programmed to create data arrays with dimensions half the size of the source data array. The sub-sampling method is set to “nearest point” and with texture mapping coordinates associating the “leftmost topmost” array element of the sub-sampled data array to the “leftmost topmost” array element of the selected color in the source data array.  FIG. 8  illustrates the transformation performed to generate these intermediate data arrays. 
     In this preferred embodiment, to create each intermediate data array, texture mapping is performed. First, a texture is allocated in the GPU memory. Its width (W inter ) and height (H inter ) dimensions (expressed in array elements) are set to half the associated dimensions of the source data array (W source  and H source ). 
     Then, the source data array is set as the source texture for texture mapping and the newly allocated texture is set as the render target of the texturing operation. 
     The next step is to create a vertex buffer containing the vertices V i (x i , y i ) for two triangles that together will fill the render target. For each vertex, destination and source addresses must be determined. The transformed vertices coordinates (i.e. destination addresses in render target pixel units) are set to V 0 (x 0 =−0.5, y 0 =−0.5), V 1 (x 1 =W inter −0.5, y 1 =−0.5), V 2 (x 2 =W inter −0.5, y 2 =H inter −0.5) V 3 (x 3 =−0.5, y 3 =H inter −0.5). In order to prevent any depth clipping in the GPU, for each vertex, the required z position is set to +0.5 and the reciprocal homogeneous w to +1.0. 
     Moreover for each vertex position (x i ,y i ) the addresses of the element that will be fetched by the texture engine must be defined. A texture address associated with each vertex indicates the address of the source element to be fetched by the GPU texture engine. These texture addresses are the following: V 0 (tu=0+Δu, tv=0+Δv), V 1 (tu=1+Δu, tv=0+Δv), V 2 (tu=1+Δu, tv=1+Δv), V 3 (tu=0+Δu, tv=1+Δv). These values are in accordance with the convention that a 2D texture addressing uses an address range of [0,1] in each dimension. The values of Δu and Δv depend of the type of pixel selected. In case where the pixel types are located in the original Bayer image according to  FIG. 6  (G 1 ,R,G 2 ,B), the following values are used. 
     
       
         
               
               
               
             
           
               
                   
                   
               
             
             
               
                   
                 Red 
                 Δu = −0.5/W source , Δv = +0.5/H source   
               
               
                   
                 Green_1 
                 Δu = −0.5/W source , Δv = −0.5/H source   
               
               
                   
                 Green_2 
                 Δu = +0.5/W source , Δv = +0.5/H source   
               
               
                   
                 Blue 
                 Δu = +0.5/W source , Δv = −0.5/H source   
               
               
                   
                   
               
             
          
         
       
     
     In this preferred embodiment, in order to create the desired intermediate data array the texture mapping engine of the GPU is set to do nearest point filtering when fetching data from the source texture. 
     At this step, if a correction is required (a color gain and/or a gamma correction) for the extracted color, a palette is filled with the gain and the alpha correction results for each possible value in the source image. And the GPU is programmed to use this palette. 
     Then, a command is sent to the GPU to draw the two triangles defined in the vertex buffer. This operation will fill intermediate data arrays with the elements of the desired Red, Blue, Green_ 1  or Green_ 2  type. 
     These steps are repeated for each color and at the end of these preprocessing steps four color texture are generated. 
     Once these preprocessing steps are performed, data array elements are processed. For each destination array element we look for the three color values R, G and B. These values are an interpolation of well-chosen neighbors. As it was shown previously according to the color of the source array element the values of R, G and B are a different combination of specified neighbors (equations 1,2,3,4). 
     Intermediate data arrays are used to extract R, G and B values for each destination array element.  FIG. 9  illustrates for an array element at position (i,j) in source data array the positions in intermediate data arrays of Red, Blue and Green components sampled. In this figure, when the sampling position is between two elements of the array, an interpolation is done between the two elements. In this example the source array element is Green_ 2 . We recall that for a data array element Green_ 2 , the following averages needs to be computed: 
     
       
         
           
             
               ( 
               
                 i 
                 , 
                 j 
               
               ) 
             
             ⁢ 
             
                 
             
             ⁢ 
             
               { 
               
                 
                   
                     
                       R 
                       = 
                       
                         
                           ( 
                           
                             
                               P 
                               
                                 i 
                                 , 
                                 
                                   j 
                                   - 
                                   1 
                                 
                               
                             
                             + 
                             
                               P 
                               
                                 i 
                                 , 
                                 
                                   j 
                                   + 
                                   1 
                                 
                               
                             
                           
                           ) 
                         
                         / 
                         2 
                       
                     
                   
                 
                 
                   
                     
                       G 
                       = 
                       
                         P 
                         
                           i 
                           , 
                           j 
                         
                       
                     
                   
                 
                 
                   
                     
                       B 
                       = 
                       
                         
                           ( 
                           
                             
                               P 
                               
                                 
                                   i 
                                   - 
                                   1 
                                 
                                 , 
                                 j 
                               
                             
                             + 
                             
                               P 
                               
                                 
                                   i 
                                   + 
                                   1 
                                 
                                 , 
                                 j 
                               
                             
                           
                           ) 
                         
                         / 
                         2 
                       
                     
                   
                 
               
             
           
         
       
     
     Then, for the first Green_ 2  element of the output image, the value of the red component is the average of the two first elements of the first column of the Red intermediate data array. The value of the blue component is the average of the first two elements of the first row of the Blue intermediate data array. And the green value is the first element of the Green_ 2  intermediate data array.  FIG. 10 ,  FIG. 11  and  FIG. 12 , show the corresponding values for Green_ 1 , Red, and Blue. 
     In this preferred embodiment, this step involves in combining the data from all the arrays to form the final color image. The GPU is programmed to fetch data from the four textures containing the separate color types (arrayR, arrayB, arrayG_ 1 , and arrayG_ 2 ). To obtain the color values for each array element, the GPU does a fetch in the intermediate data arrays at positions computed using the position of the array element in the final color data array and using a supplied constant offset for each intermediate array. The GPU is configured such that it performs the appropriate interpolation in case the fetching position in the intermediate array falls between many array elements. 
     The fetched values from the Red and Blue intermediate data arrays can be used directly to fill the associated components of the final color data array. However, the GPU should distinguish three cases to fill the green component, according to the type of this array element in the source Bayer array: 
     If the source array element is Green_ 1  then the GPU chooses the value fetched from the Green_ 1  array. 
     If the source array element is Green_ 2  then the GPU chooses the value fetched from the Green_ 2  array. 
     If the source array element is Red or Blue then the GPU uses the average between the fetched values from Green_ 1  and Green_ 2  arrays. 
     To help the GPU to differentiate between these three cases, it is fed with another intermediate data array named Bayer code data array. In this array, each element contains information about the array element color at the associated position in the source data array. 
     In this preferred embodiment several steps are followed to perform the color combining operation. In a first step, the Bayer code data array is created. An 8-bit texture is allocated in the GPU memory. Its width and height dimensions (expressed in array elements) are set to the same dimension as the source Bayer data array (W source H   source ). 
     This texture is filled with the following values: 255 if the associated array element in the source array is of type Red or Blue, 0 if the associated array element is of type Green_ 1  and 160 if the associated array element is of type Green_ 2 .  FIG. 13  illustrates this transformation. The same process as described previously is used to compute the result array: texture mapping. A destination data array is allocated as a surface in the GPU memory. Its width and height dimensions (expressed in array elements) are set to the same dimension as the source Bayer data array (W source  and H source ). Then this surface is set as the render target of the texturing operation. 
     In this case the four intermediate data textures and the Bayer code data array are set as source textures for texture mapping. 
     A vertex buffer is created; it contains the vertices V i (x i ,y 1 ) of two triangles that will fill the render target. For each vertex, destination and source addresses must be determined. The transformed vertices coordinates (i.e. the addresses of target elements in render target pixel units) should be V 0 (x=−0.5, y=−0.5) V 1 (x=W source −0.5, y=−0.5), V 2 (x=W source −0.5, y=H source −0.5) V 3 (x=−0.5, y=H source −0.5). For each vertex, the required z position is set to +0.5 and the reciprocal homogeneous w to +1.0 in order to prevent any depth clipping in the GPU. 
     Moreover for each vertex position (x i ,y i ) the addresses of the element that will be fetched by the texture engine must be defined. At this step, for each rendered array element of the destination surface the texture engine will fetch a value from each intermediate data array (arrayR, arrayB,) arrayG_ 1 , and arrayG_ 2 ) and from the Bayer code data array (BC). These texture addresses are the following, (ΔU=1/W source , Δv=1/H source ): 
     
       
         
               
               
               
               
               
             
           
               
                   
               
               
                   
                 V 0   
                 V 1   
                 V 2   
                 V 3   
               
               
                   
               
             
             
               
                 R 
                 (0 + Δu, 0 − Δv) 
                 (1 + Δu, 0 − Δv) 
                 (1 + Δu, 1 − Δv) 
                 (0 + Δu, 1 − Δv) 
               
               
                 G1 
                 (0 + Δu, 0 + Δv) 
                 (1 + Δu, 0 + Δv) 
                 (1 + Δu, 1 + Δv) 
                 (0 + Δu, 1 + Δv) 
               
               
                 G2 
                 (0 − Δu, 0 − Δv) 
                 (1 − Δu, 0 − Δv) 
                 (1 − Δu, 1 − Δv) 
                 (0 − Δu, 1 − Δv) 
               
               
                 B 
                 (0 − Δu, 0 + Δv) 
                 (1 − Δu, 0 + Δv) 
                 (1 − Δu, 1 + Δv) 
                 (0 − Δu, 1 + Δv) 
               
               
                 BC 
                 (0, 0) 
                 (1, 0) 
                 (1, 1) 
                 (0, 1) 
               
               
                   
               
             
          
         
       
     
     This texture addressing will map each pixel of the destination data array (destination surface) to positions in the intermediate data arrays that will either correspond directly to the needed data or that will fall between the values that need to be averaged according to the equations 1, 2, 3 and 4. 
     In order to fetch the right values for each destination position the texture mapping engine of the GPU needs to be programmed to do bilinear filtering. This will ensure that the appropriate average will be done when fetching a value at a position located between many pixels of the intermediate data arrays. 
     Moreover, texture mapping engine must be set to perform mirror address overscan when the fetching position corresponds to a position outside an intermediate data texture. This will insure the correctness of the result at the border of the destination image. 
     Once the fetch addresses are set, the pixel shader is programmed to compute for each destination array element, its color components R, G and B. In fact for each destination array the pixel shader fetches the values from the four intermediate data arrays and from the Bayer code array. Then, it computes the average of fetched values from Green_ 1  and Green_ 2  arrays and chooses the appropriate value for Green component according to the Bayer code. This code has been translated and scaled from the [0,255] range to [−1,1]. The pixel shader chooses the value of Green  1  if the scaled code&lt;0, the value of Green_ 2  if 0&lt;=scaled code&lt;0.5, and the average of Green_ 1  and Green  2  if the scaled code&gt;=0.5. Finally the pixel shader assigns the Red and Blue components output values directly from the values fetched from the associated intermediate data arrays. 
     The last step is to send a command to the GPU to draw the two triangles defined in the vertex buffer. This operation will fill the destination data array with the desired R,G and B values for each array element. 
     This preferred embodiment method is fast and easy to implement using a DirectX 8.1 API. It uses GPU characteristics such as texture engine and texture mapping. The C++ code in the listing appended hereto can be executed to perform the above method as well as the below second method. 
     A Second Method: 
     In another preferred embodiment, the same primary steps are performed. A Bayer image and instructions are loaded in the GPU local memory. Image is processed and a color space image is output. 
     The Bayer image is loaded in a 2D source data array in GPU local memory. An intermediate Bayer code data array is generated according to the source data array. As in the previous embodiment of the invention this data array contains information about the source array elements&#39; type. though, this information is not coded in the same manner. In this embodiment a distinction between the four possible cases needs to be done. 
     A texture mapping operation is performed to generate the Bayer code data array. The source texture is the Bayer image and the destination texture is the Bayer code data array. In this embodiment, each Bayer code array element&#39;s value is either (1,0,0,0) if the source element is Red, (0,1,0,0) if the source element is Green_ 1 , (0,0,0,1) if the source element is Green_ 2  or (0,0,1,0) if the source element is Blue as shown in  FIG. 14 . 
     In the next step, the color data array is computed. The source data array and the Bayer code data array are set as source textures of the GPU and a surface is allocated in GPU local memory to hold the output color data array. This surface has the same width and height dimensions (expressed in array elements) as the source Bayer data array (W source  and H source ). 
     The allocated destination surface is set as the render target of the texture engine of the GPU. Then, a vertex buffer is created containing the vertices V i (x i , y i ) for two triangles that together will fill the render target. And as in the previous method the destination addresses must be defined. The transformed vertices coordinates (i.e. in render target pixel units) are set to V 0 (x 0 =−0.5, y 0 =−0.5), V 1 (x 1 =W source −0.5, y 1 −0.5) V 2 (x 2 =W source −0.5, y 2 =H source −0.5), V 3 (x 3 =−0.5, y 3 =H source −0.5). In order to prevent any depth clipping in the GPU, for each vertex, the required z position is set to +0.5 and the reciprocal homogeneous w to +1.0. 
     For each vertex, texture addresses are also defined. Texture addresses are the addresses of the source and Bayer code element that must be fetched to compute the desired R,G and B value for each destination array element. The texture addresses are: V 0 (tu=0, tv=0), V 1 (tu=1, tv=0), V 2 (tu=1, tv=1), V 3 (tu=0, tv=1). 
     The GPU uses this vertex buffer for its rendering operation and it is programmed to use nearest point filtering when fetching values from input textures. 
     As in the first embodiment of the invention it is essential to note that each array element&#39;s color value searched is a combination of appropriate source array elements&#39; values. Let P i,j  be the color value at pixel position (i,j). Once the Bayer code array is generated the texture engine computes for each destination array element the following averages: 
     
       
         
           
             { 
             
               
                 
                   
                     
                       right 
                       ⁢ 
                       
                         - 
                       
                       ⁢ 
                       left 
                     
                     = 
                     
                       
                         
                           P 
                           
                             
                               i 
                               - 
                               1 
                             
                             , 
                             j 
                           
                         
                         + 
                         
                           P 
                           
                             
                               i 
                               + 
                               1 
                             
                             , 
                             j 
                           
                         
                       
                       2 
                     
                   
                 
               
               
                 
                   
                     
                       up 
                       ⁢ 
                       
                         - 
                       
                       ⁢ 
                       down 
                     
                     = 
                     
                       
                         
                           P 
                           
                             i 
                             , 
                             
                               j 
                               - 
                               1 
                             
                           
                         
                         + 
                         
                           P 
                           
                             i 
                             , 
                             
                               j 
                               + 
                               1 
                             
                           
                         
                       
                       2 
                     
                   
                 
               
               
                 
                   
                     diagonal 
                     = 
                     
                       
                         
                           P 
                           
                             
                               i 
                               - 
                               1 
                             
                             , 
                             
                               j 
                               - 
                               1 
                             
                           
                         
                         + 
                         
                           P 
                           
                             
                               i 
                               + 
                               1 
                             
                             , 
                             
                               j 
                               - 
                               1 
                             
                           
                         
                         + 
                         
                           P 
                           
                             
                               i 
                               - 
                               1 
                             
                             , 
                             
                               j 
                               + 
                               1 
                             
                           
                         
                         + 
                         
                           P 
                           
                             
                               i 
                               + 
                               1 
                             
                             , 
                             
                               j 
                               + 
                               1 
                             
                           
                         
                       
                       4 
                     
                   
                 
               
               
                 
                   
                     cross 
                     = 
                     
                       
                         
                           P 
                           
                             i 
                             , 
                             
                               j 
                               - 
                               1 
                             
                           
                         
                         + 
                         
                           P 
                           
                             
                               i 
                               + 
                               1 
                             
                             , 
                             j 
                           
                         
                         + 
                         
                           P 
                           
                             i 
                             , 
                             
                               j 
                               + 
                               1 
                             
                           
                         
                         + 
                         
                           P 
                           
                             
                               i 
                               - 
                               1 
                             
                             , 
                             j 
                           
                         
                       
                       4 
                     
                   
                 
               
               
                 
                   
                     center 
                     = 
                     
                       P 
                       
                         i 
                         , 
                         j 
                       
                     
                   
                 
               
             
           
         
       
     
     We note that if the color is red at pixel location (i,j), we would like to associate to each color Red, Blue, Green the following values: 
                     (     i   ,   j     )     ⁢           ⁢     {           Red   =     center   .                 Green   =   cross               Blue   =   diagonal                     Combination   ⁢           ⁢   1               
If the color is Blue:
 
                     (     i   ,   j     )     ⁢           ⁢     {           Red   =   diagonal               Green   =   cross               Blue   =   center                     Combination   ⁢           ⁢   2               
If the color is Green_ 1 :
 
                     (     i   ,   j     )     ⁢           ⁢     {           Red   =     left   ⁢     -     ⁢   right                 Green   =   center               Blue   =     up   ⁢     -     ⁢   down                       Combination   ⁢           ⁢   3               
If the color is Green_ 2 :
 
     
       
         
           
             
               
                 
                   
                     ( 
                     
                       i 
                       , 
                       j 
                     
                     ) 
                   
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   
                     { 
                     
                       
                         
                           
                             Red 
                             = 
                             
                               up 
                               ⁢ 
                               
                                 - 
                               
                               ⁢ 
                               down 
                             
                           
                         
                       
                       
                         
                           
                             Green 
                             = 
                             center 
                           
                         
                       
                       
                         
                           
                             Blue 
                             = 
                             
                               left 
                               ⁢ 
                               
                                 - 
                               
                               ⁢ 
                               right 
                             
                           
                         
                       
                     
                   
                 
               
               
                 
                   Combination 
                   ⁢ 
                   
                       
                   
                   ⁢ 
                   4 
                 
               
             
           
         
       
     
     In this preferred embodiment, the pixel shader is programmed such that it performs the following operations for each array element of the destination surface. 
     First, it fetches the Bayer code from the Bayer code data array at the position corresponding to the destination array element position and stores this code in an internal register of the pixel shader. 
     Then, it fetches the value from the source data array at the same position and stores it in an internal register of the pixel shader. 
     In the next step, the texture fetching position is modified by adding offsets corresponding to the distance between pixels and the values of the 8 neighbor array elements are fetched. All these values are stored in internal registers of the pixel shader: 
     The pixel shader computes the average values left-right, up-down, diagonal, cross, center and stores the four possible averages combinations (1,2,3,4). 
     However, only one of these combinations is the right one. To select it, each combination is multiplied by one element of the corresponding Bayer code and the results are added. Since only one component of this code is 1 and the others are 0, the result of the sum of these multiplications is immediately the right combination. 
     A command is sent to the GPU to draw the two triangles defined in the vertex buffer using the instructions stored in its pixel shader. This operation will fill the color data array. 
     At this step the three values R, G and B are determined for the destination array element at position (i,j). 
     This embodiment uses less GPU local memory but does more computation for each array element. Both embodiments off-load the CPU, which can be dedicated to more complex tasks. 
     It will be appreciated that if the GPU has a modulo operator, .it is possible to use the current pixel index, e.g. i,j, in combination with such an operator to effectively create the code “on the fly” and thus avoid the need to provide the code. For example, (i MOD 2) will be zero for even values of i and one for odd values of i, while ((i+1) MOD 2) will have the opposite values. Equivalently, if a GPU has the ability to perform a bitwise logical AND, it will be appreciated that (i AND 1) will yield a value of one for all odd values of i and zero for all even values, while ((i+1) AND 1) will yield one for all even values of i and zero for all odd values. The code is essentially a product of such an odd/even function of both the i and j indices, since there are the four position in the Bayer pattern as illustrated in  FIG. 1 . Conventional GPU&#39;s today do not include such modulo operators. Similarly, when a GPU is able to perform a branch operation, the need to use a code or such an operator can be avoided.