[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48223] trunk/blender/source/blender: Keying node: assume overexposured pixels as foreground

Sergey Sharybin sergey.vfx at gmail.com
Sat Jun 23 20:04:54 CEST 2012


Revision: 48223
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48223
Author:   nazgul
Date:     2012-06-23 18:04:41 +0000 (Sat, 23 Jun 2012)
Log Message:
-----------
Keying node: assume overexposured pixels as foreground

Screens are usually doesn't have overexposured pixels and all
saturation / gradient math was written assuming that all channels
are withing 0 .. 1 range and in cases when some channel exceeds
this range matte could be completely wrong.

Added special check for overesposure and assume such pixels as
definitely foreground.

Also fixed minimal value for edge kernel size.

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/operations/COM_KeyingOperation.cpp
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c

Modified: trunk/blender/source/blender/compositor/operations/COM_KeyingOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_KeyingOperation.cpp	2012-06-23 17:44:28 UTC (rev 48222)
+++ trunk/blender/source/blender/compositor/operations/COM_KeyingOperation.cpp	2012-06-23 18:04:41 UTC (rev 48223)
@@ -98,23 +98,42 @@
 
 	int primary_channel = get_pixel_primary_channel(screenColor);
 
-	float saturation = get_pixel_saturation(pixelColor, this->screenBalance, primary_channel);
-	float screen_saturation = get_pixel_saturation(screenColor, this->screenBalance, primary_channel);
-
-	if (saturation < 0) {
+	if (pixelColor[primary_channel] > 1.0f) {
+		/* overexposure doesn't happen on screen itself and usually happens
+		 * on light sources in the shot, this need to be checked separately
+		 * because saturation and falloff calculation is based on the fact
+		 * that pixels are not overexposured
+		 */
 		color[0] = 1.0f;
 	}
-	else if (saturation >= screen_saturation) {
-		color[0] = 0.0f;
-	}
 	else {
-		float distance = 1.0f - saturation / screen_saturation;
+		float saturation = get_pixel_saturation(pixelColor, this->screenBalance, primary_channel);
+		float screen_saturation = get_pixel_saturation(screenColor, this->screenBalance, primary_channel);
 
-		color[0] = distance;
+		if (saturation < 0) {
+			/* means main channel of pixel is different from screen,
+			 * assume this is completely a foreground
+			 */
+			color[0] = 1.0f;
+		}
+		else if (saturation >= screen_saturation) {
+			/* matched main channels and higher saturation on pixel
+			 * is treated as completely background
+			 */
+			color[0] = 0.0f;
+		}
+		else {
+			/* nice alpha falloff on edges */
+			float distance = 1.0f - saturation / screen_saturation;
+
+			color[0] = distance;
+		}
 	}
 
-	color[0] *= (1.0f - garbageValue[0]);
+	/* apply garbage matte */
+	color[0] = MIN2(color[0], 1.0f - garbageValue[0]);
 
+	/* apply core matte */
 	color[0] = MAX2(color[0], coreValue[0]);
 }
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2012-06-23 17:44:28 UTC (rev 48222)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2012-06-23 18:04:41 UTC (rev 48223)
@@ -3611,7 +3611,7 @@
 
 	prop = RNA_def_property(srna, "edge_kernel_radius", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "edge_kernel_radius");
-	RNA_def_property_range(prop, -100, 100);
+	RNA_def_property_range(prop, 0, 100);
 	RNA_def_property_ui_text(prop, "Edge Kernel Radius", "Radius of kernel used to detect whether pixel belongs to edge");
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 




More information about the Bf-blender-cvs mailing list