Skip to content

Instantly share code, notes, and snippets.

@StevenPuttemans
Created October 4, 2019 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StevenPuttemans/8f073532f881a09eb172e789ffc2bcc7 to your computer and use it in GitHub Desktop.
Save StevenPuttemans/8f073532f881a09eb172e789ffc2bcc7 to your computer and use it in GitHub Desktop.
constraint
# Rule based filtering of skin pixels
# (RED>95) && (GREEN>40) && (BLUE>20) && ((max(RED,max(GREEN,BLUE)) - min(RED,min(GREEN,BLUE)))>15) && (abs(RED-GREEN)>15) && (RED>GREEN) && (RED>BLUE);
result = np.zeros(img_color.shape)
# Method 1 - naive with loops
# Remember BGR color space in OpenCV
for row in range(img_color.shape[0]):
for col in range(img_color.shape[1]):
if (img_color[row, col, 2] > 95): # Condition on RED channel
if (img_color[row, col, 1] > 40): # Condition on GREEN channel
if (img_color[row, col, 0] > 20): # Condition on BLUE channel
if ((np.maximum(img_color[row, col, 2], np.maximum(img_color[row, col, 1], img_color[row, col, 0])) - np.minimum(img_color[row, col, 2], np.minimum(img_color[row, col, 1], img_color[row, col, 0]))) > 15): # Condition on min max diff
if (np.absolute(img_color[row, col, 2] - img_color[row, col, 1]) > 15): # Condition on absolute values
if(img_color[row, col, 2] > img_color[row, col, 1]):
if(img_color[row, col, 2] > img_color[row, col, 0]):
# Now we can set the pixel value to 255
result[row, col, :] = 255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment