Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement