Droste
Droste is a Hong Kong-based Data Science Consultancy
import cv2
cv2.imread('cerealbox.png')
img = cv2.imread('../img/img_042_gmbooberry.jpg', 0)
ret,thresh1 = cv2.threshold(img,33,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img,33,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img,33,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(img,33,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(img,33,255,cv2.THRESH_TOZERO_INV)
thresh = ['img','thresh1','thresh2','thresh3','thresh4','thresh5']
for i in xrange(6):
plt.subplot(2,3,i+1),plt.imshow(eval(thresh[i]),'gray')
plt.title(thresh[i])
plt.show()
img = cv2.imread('../img/img_042_gmbooberry.jpg')
imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 180,255,cv2.THRESH_BINARY_INV)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, contours, -1, (0,0,255), 2)
plt.figure(figsize=(20,10))
plt.axis("off")
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB));
>>> img.shape
(500,700)
>>> img.size
350000
(Interstellar can't touch this)
array([ 181.12238527, 199.1831504 ,
206.51429651, 80.67819854,
65.41130384, 77.77899992])
Newborns are nearly color-blind. For the first few months they can see only the brightest colors. Everything else is just shades of gray. By age three their vision is pretty normal, but by then they may have been spoiled on brightly-colored things because those things are often designed specifically for children. Almost as if young children inhabit a separate universe, color-coded so they know what's for them.
cv2.cvtColor(img, BGR2HSV)
# Simplified Code
img_hsv = cv2.cvtColor(img, BGR2HSV)
# Extract the Hue values
s = img_hsv[:,:,1]
v = img_hsv[:,:,2]
# Intensity metric
i = s * v
# Simplified Code
img_hsv = cv2.cvtColor(img, BGR2HSV)
# Extract the Hue values
h = img_hsv[:,:,0]
# Distance from Primary colours
primary = h % 40
secondary = abs(primary - 40)
blend = max(primary,secondary)
Most Frequent Colour vs Dominant Colour Cluster
def closest_colour(requested_colour):
pri_color = ['Red', 'Orange', 'Yellow', 'Green', 'Blue',
'Violet', 'Brown', 'Black', 'Grey', 'White']
pri_color = [x.lower() for x in pri_color]
min_colours = {}
#for key, name in webcolors.css3_hex_to_names.items():
for key, name in [x for x in itertools.ifilter(lambda x: x[1] in pri_color,
webcolors.css3_hex_to_names.items())]:
r_c, g_c, b_c = webcolors.hex_to_rgb(key)
rd = (r_c - requested_colour[0]) ** 2
gd = (g_c - requested_colour[1]) ** 2
bd = (b_c - requested_colour[2]) ** 2
min_colours[(rd + gd + bd)] = name
return min_colours[min(min_colours.keys())]
closest_colour([123, 134, 255])
>>> 'violet'
even a 24x24 window results
over 160 000 features
Sorry, Leprechauns, with those marshmallows,
it probably isn’t good for you
cereals.cf_score.hist(bins=25)
sns.barplot(x="has_character", y="cf_score",
hue='cf_target_market', data=cereals)
sns.stripplot(x="cf_target_market", y="cf_score", data=cereals)
sns.barplot(x="has_white_bg", y="cf_score", data=cereals)
sns.barplot(x="has_character", y="cf_score", data=cereals)
sns.barplot(x="has_downard_gaze", y="cf_score", data=cereals)
sns.barplot(x="most_dominant_colour", y="cf_score", data=cereals);
cf_score | dominant_colour | has_character |
---|---|---|
82 | grey | no |
cf_score | dominant_colour | has_downward_gaze |
---|---|---|
46 | yellow | yes |
cf_score | dominant_colour | has_downward_gaze |
---|---|---|
64 | grey | yes |
cf_score | dominant_colour | has_character |
---|---|---|
36 | white | no |
m@droste.hk
gh : @tijptjik
mart van de ven
By Droste