[opengtl-commits] [376] add a pixel grouping demosaicing algorithm ( Pass2 is disabled for now since I first need to fix the structure memory leak )

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 376
Author:   cyrille
Date:     2008-09-07 10:58:56 +0200 (Sun, 07 Sep 2008)

Log Message:
-----------
add a pixel grouping demosaicing algorithm (Pass2 is disabled for now since I first need to fix the structure memory leak)

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/tests/raw/CMakeLists.txt

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass1.shiva
    trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass1.shiva.png
    trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass2.shiva
    trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass2.shiva.png


Modified: trunk/OpenGTL/OpenShiva/tests/raw/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/raw/CMakeLists.txt	2008-09-07 08:52:14 UTC (rev 375)
+++ trunk/OpenGTL/OpenShiva/tests/raw/CMakeLists.txt	2008-09-07 08:58:56 UTC (rev 376)
@@ -4,9 +4,11 @@
   RawToGray.shiva
   SimpleDemosaicing.shiva
   LinearDemosaicing.shiva
+  PixelGroupingPass1.shiva
   )
 
 FOREACH( TEST_FILE ${TESTS_FILES} )
   ADD_TEST(${TEST_FILE} ${SHIVATESTER} -c ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/../data/dsc_0006-23-07-2008.nef ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE}.png)
 ENDFOREACH( TEST_FILE )
 
+# ADD_TEST(PixelGroupingPass2.shiva ${SHIVATESTER} -c ${CMAKE_CURRENT_SOURCE_DIR}/PixelGroupingPass2.shiva ${CMAKE_CURRENT_SOURCE_DIR}/PixelGroupingPass1.png ${CMAKE_CURRENT_SOURCE_DIR}/PixelGroupingPass2.shiva.png)

Added: trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass1.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass1.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass1.shiva	2008-09-07 08:58:56 UTC (rev 376)
@@ -0,0 +1,78 @@
+/**
+ * http://web.cecs.pdx.edu/~cklin/demosaic/
+ */
+
+kernel PixelGroupingPass1
+{
+  float2 coordAdj( float2 v, float h, int idx )
+  {
+    v[idx] = v[ idx ] + h;
+    return v;
+  }
+  float fabs( float v )
+  {
+    if( v < 0.0 ) return -v;
+    return v;
+  }
+  float computeGreen( float2 coord, image1 img )
+  {
+    float g8 = img.sampleNearest( coordAdj( coord, -1, 1 ) );
+    float g18 = img.sampleNearest( coordAdj( coord, 1, 1 ) );
+    float gV = fabs(  g8 - g18 );
+    float g12 = img.sampleNearest( coordAdj( coord, -1, 0 ) );
+    float g14 = img.sampleNearest( coordAdj( coord, 1, 0 ) );
+    float gH = fabs( g12 - g14 );
+    float v13 = img.sampleNearest( coord );
+    float v3 = img.sampleNearest( coordAdj( coord, -2, 1 ) );
+    float v23 = img.sampleNearest( coordAdj( coord, 2, 1 ) );
+    float v11 = img.sampleNearest( coordAdj( coord, -2, 0 ) );
+    float v15 = img.sampleNearest( coordAdj( coord, 2, 0 ) );
+    float dN = fabs(  v3 - v13 ) * 2.0 + gV;
+    float dS = fabs( v15 - v13 ) * 2.0 + gV;
+    float dW = fabs( v11 - v13 ) * 2.0 + gH;
+    float dE = fabs( v23 - v13 ) * 2.0 + gH;
+    if( dN < dS and dN < dE and dN < dW )
+    {
+      return 0.25 * ( 3 * g8 +v13 + g18 - v3 );
+    } else if( dE < dS and dE < dW )
+    {
+      return 0.25 * ( 3 * g14 + v13 + g12 - v15 );
+    } else if( dW < dS )
+    {
+      return 0.25 * ( 3 * g12 + v13 + g14 - v11 );
+    }
+    return 0.25 * ( 4 * g18 + v13 + g8 - v23 );
+    
+  }
+  void evaluatePixel(image1 img, out pixel4 result)
+  {
+    int x = result.coord[0];
+    int y = result.coord[1];
+    result.data = 0.0;
+    if( x & 1 )
+    {
+      if( y & 1 )
+      {
+        result.data[1] = img.sampleNearest( result.coord );
+      } else {
+        result.data[1] = computeGreen( result.coord, img );
+        result.data[2] = img.sampleNearest( result.coord );
+      }
+    } else {
+      if( y & 1 )
+      {
+        result.data[0] = img.sampleNearest( result.coord );
+        result.data[1] = computeGreen( result.coord, img );
+      } else {
+        result.data[1] = img.sampleNearest( result.coord );
+      }
+    }
+    
+    result.data[3] = 1.0;
+  }
+  region changed(region changed_input_region, int input_index, region input_DOD[])
+  {
+    return changed_input_region;
+  }
+
+}

Added: trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass1.shiva.png
===================================================================
(Binary files differ)


Property changes on: trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass1.shiva.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass2.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass2.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass2.shiva	2008-09-07 08:58:56 UTC (rev 376)
@@ -0,0 +1,103 @@
+kernel PixelGroupingPass2
+{
+  float2 coordAdj( float2 v, float h, int idx )
+  {
+    v[idx] = v[ idx ] + h;
+    return v;
+  }
+  float hue_transit( float l1, float l2, float l3, float v1, float v3)
+  {
+   if( (l1 < l2 and l2<l3) or (l1 > l2 and l2 > l3) )
+   {
+    return v1 + (v3-v1) * (l2-l1)/(l3-l1);
+   }
+   return (v1+v3)/2 + (l2 * 2-l1-l3)/4;
+  }
+  float fabs( float v )
+  {
+    if( v < 0.0 ) return -v;
+    return v;
+  }
+  float clamp( float v)
+  {
+    if( v > 1.0 )
+    {
+      return 1.0;
+    }
+    if( v < 0.0 )
+    {
+      return 0.0;
+    }
+    return v;
+  }
+  /**
+   * @param idx1 index of the channel we are atrying to cestimate
+   * @param idx2 index of the channel for which we know the value
+   */
+  float computeBlueRed( float2 coord, image4 img, pixel4 p13, int idx1, int idx2 )
+  {
+    float2 u_ne = { 1, -1 };
+    float2 u_nw = { 1, 1 };
+    pixel4 p9 = img.sampleNearest( coord + u_ne );
+    pixel4 p17 = img.sampleNearest( coord - u_ne );
+    pixel4 p5 = img.sampleNearest( coord + 2 * u_ne );
+    pixel4 p21 = img.sampleNearest( coord - 2 * u_ne );
+    pixel4 p7 = img.sampleNearest( coord - u_nw );
+    pixel4 p19 = img.sampleNearest( coord + u_nw );
+    pixel4 p1 = img.sampleNearest( coord - 2 * u_nw );
+    pixel4 p25 = img.sampleNearest( coord + 2 * u_nw );
+    float dne = fabs( p9[ idx1 ] - p17[ idx1 ] ) + fabs( p5[ idx2 ] - p13[ idx2 ] ) + fabs( p13[ idx2 ] - p21[ idx2 ] ) + fabs( p9[ 1 ] - p13[ 1 ] ) + fabs( p13[ 1 ] - p17[ 1 ] );
+    float dnw = fabs( p7[ idx1 ] - p19[ idx1 ] ) + fabs( p1[ idx2 ] - p13[ idx2 ] ) + fabs( p13[ idx2 ] - p25[ idx2 ] ) + fabs( p7[ 1 ] - p13[ 1 ] ) + fabs( p13[ 1 ] - p19[ 1 ] );
+    if( dne <= dnw )
+    {
+      return hue_transit( p9[ 1 ], p13[ 1 ], p17[ 1 ], p9[ idx1 ], p17[ idx1 ] );
+    }
+    return hue_transit( p7[ 1 ], p13[ 1 ], p19[ 1 ], p7[ idx1 ], p19[ idx1 ] );
+  }
+  
+  void evaluatePixel(image4 img, out pixel4 result)
+  {
+    int x = result.coord[0];
+    int y = result.coord[1];
+    result.data = 0.0;
+    pixel4 p = img.sampleNearest( result.coord );
+    float g = p[1];
+    result.data[1] = g;
+    if( x & 1 )
+    {
+      if( y & 1 )
+      {
+        pixel4 p7 = img.sampleNearest( coordAdj( result.coord, -1, 0 ) );
+        pixel4 p9 = img.sampleNearest( coordAdj( result.coord, 1, 0 ) );
+        pixel4 p3 = img.sampleNearest( coordAdj( result.coord, -1, 1 ) );
+        pixel4 p13 = img.sampleNearest( coordAdj( result.coord, 1, 1 ) );
+        result.data[0] = clamp(hue_transit( p7[1], g, p9[1], p7[0], p9[0] ));
+        result.data[2] = clamp(hue_transit( p3[1], g, p13[1], p3[2], p13[2] ));
+      } else {
+        result.data[0] = clamp(computeBlueRed( result.coord, img, p, 0, 2 )); // FIXME clamp when copying data back
+        result.data[2] = p[2];
+      }
+    } else {
+      if( y & 1 )
+      {
+        result.data[0] = p[0];
+        result.data[2] = clamp(computeBlueRed( result.coord, img, p, 2, 0 ));
+      } else {
+        pixel4 p7 = img.sampleNearest( coordAdj( result.coord, -1, 0 ) );
+        pixel4 p9 = img.sampleNearest( coordAdj( result.coord, 1, 0 ) );
+        pixel4 p3 = img.sampleNearest( coordAdj( result.coord, -1, 1 ) );
+        pixel4 p13 = img.sampleNearest( coordAdj( result.coord, 1, 1 ) );
+        result.data[0] = clamp(hue_transit( p3[1], g, p13[1], p3[0], p13[0] ));
+        result.data[2] = clamp(hue_transit( p7[1], g, p9[1], p7[2], p9[2] ));
+      }
+    }
+    
+    result.data[3] = 1.0;
+  }
+  region changed(region changed_input_region, int input_index, region input_DOD[])
+  {
+    return changed_input_region;
+  }
+
+  
+}
\ No newline at end of file

Added: trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass2.shiva.png
===================================================================
(Binary files differ)


Property changes on: trunk/OpenGTL/OpenShiva/tests/raw/PixelGroupingPass2.shiva.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/