潘通色号与rgb转换

您所在的位置:网站首页 rgb转潘通色号 潘通色号与rgb转换

潘通色号与rgb转换

#潘通色号与rgb转换| 来源: 网络整理| 查看: 265

3b666096a817d34fd470313c4a956b62.png

大数据文摘编辑组出品 技术实现: 宁静  中秋节, 直男送礼,首选口红。 毕竟李佳琦一句"OMG买它”,女朋友披头散发抢购,钱包就空了一半。 71dff87688cdca4eb8580d17696e7c03.gif 但是,口红色号千千万,选对了牌子才成功了一半。 快乐橙、伤心紫,姨妈红,鸡屎绿…直男眼里没什么区别的颜色,在女生眼里各种色调、质地细微的区别都能分析一清二楚。 3198753e82d440effc2b2fde6541ae2e.gif 那么,对于直男来说,怎么才能搞清楚如此多的口红色号呢? 文摘菌耗费一毫米发际线,琢磨了一下,做出了一个口红色号识别器,希望能帮大家在七夕把深刻的革命友谊再升华一下。 先来看看效果。 让我们假设,中秋前夕,小姐姐发来了一张美妆博主的美照,并暗示你,“人家也喜欢这个颜色。 ” 9d3c891279f6a0d4e826923d5c00f973.png 图片来自网络 这个时候,用我们的口红色号识别器,就能定位嘴唇,并迅速给出它的颜色隶属哪家品牌的哪个色号。 dbe25c6e46f5b03283891cbe85ebf34e.png OMG! 简直比李佳琦还准确! 44f80bf408585b35fddf0962e505b6e3.png 好啦,废话不多说,马上开始教学时间! 来自Github的口红色号宇宙 要想识别口红色号,先得让机器知道到底都有哪些颜色。 文摘菌听柜姐介绍,红色系有: “草莓红、铁锈红、枫叶红...”,其他还有“豆沙色、吃土色、番茄色...” 146c16cb54888d446ef698821dd1ffe0.gif 世界观还未建立完全就要开始土崩瓦解,这看着有区别吗? “豆沙色最为百搭,橘调的番茄色比较显白...” 眼前的黑不是黑,你说的红是什么红? 2e29c755bf5ba4a1d2794063164f6e12.png 还好,在万能的github上,文摘菌找到了一个宝藏数据库“口红颜色可视化”,这个数据库堪比口红的色号宇宙,不仅囊括了当前最主流品牌的各种系列色号,还很良心的在色盘上排列了出来。 这个数据集是一个嵌套的字典数据结构,存为json串的形式,里面记录了每个口红品牌系列下不同口红色号的颜色id、名称、和16进制颜色值。 直! 男! 救! 星! 有木有! 口红色号可视化链接:

https://github.com/Ovilia/lipstick

不过看这这密密麻麻的颜色,真心佩服各大口红品牌的文案高手,是怎么样区别每一个看不出区别的颜色,并且还要分别取名字的。 17930360a391c7cb38233669b588b80b.png 傻傻分不清的文摘菌对5个品牌的不同系列做了一下统计和色号录入,于是,剩下的就交给计算机啦。 先用番茄做个实验? 既然有了如此完备的色号数据库,那么文摘菌就有了一个讨巧的方法: 要想找到合适的色号,可以直接截取颜色,然后在数据库中进行比对。 这个方法非常好操作,在上唇色之前,我们不如先拿别的红色物品来练手。 比如,这里有一只番茄图片。 你看这个番茄它又大又圆: c043fa836d4c78912944436f7c59343d.png 文摘菌在其中截取了成色均匀、无高亮的矩形图片:         58b06949af9ae91bf89acc0a476aa573.png       提取这张纯色图片的RGB值在技术上是可行的,getcolor.py代码如下: import colorsysimport PIL.Image as Image def get_dominant_color(image): max_score = 0.0001 dominant_color = None for count,(r,g,b) in image.getcolors(image.size[0]*image.size[1]): # 转为HSV标准 saturation = colorsys.rgb_to_hsv(r/255.0, g/255.0, b/255.0)[1] y = min(abs(r*2104+g*4130+b*802+4096+131072)>>13,235) y = (y-16.0)/(235-16) #忽略高亮色 if y > 0.9: continue score = (saturation+0.1)*count if score > max_score: max_score = score dominant_color = (r,g,b) return dominant_color 为了减少误差,需要裁剪多个不同位置的图片,保存在本地的一个文件夹中,读取文件,提取颜色,求平均值,得到的番茄最终的RGB颜色,代码如下: import osimport getcolorfrom os.path import join as pjoinfrom scipy import miscdef load_color(color_dir,list): count = 0 for dir in os.listdir(color_dir): img_dir = pjoin(color_dir, dir) image = getcolor.Image.open(img_dir) image = image.convert('RGB') get=getcolor.get_dominant_color(image) list.append(get) count = count+1 #print(person_dir) #print(count) return countdef Mean_color(count,list): Mean_R=Mean_G=Mean_B=0 for i in range(count): tuple=list[i] Mean_R+=tuple[0] Mean_G+=tuple[1] Mean_B+=tuple[2] MeanC=((int)(Mean_R/count),(int)(Mean_G/count),(int)(Mean_B/count)) return Me 番茄的颜色提取到了,那么和什么做比对呢? 当然是口红的数据,文摘菌这儿用到了5个品牌,分别是圣罗兰、香奈儿可可小姐、迪奥、美宝莲、纪梵希,共17个系列,271个口红色号,数据集是一个嵌套的字典数据结构,存为json串的形式,里面记录了每个口红品牌系列下不同口红色号的颜色id、名称、和16进制颜色值,lipstick.json部分数据集展示如下: {"brands":[{"name":"圣罗兰","series":[{"name":"莹亮纯魅唇膏","lipsticks":[{"color":"#D62352","id":"49","name":"撩骚"},{"color":"#DC4B41","id":"14","name":"一见倾心"},{"color":"#B22146","id":"05","name":"浮生若梦"}, 数据集中存储的RGB颜色是16进制的字符串形式,需要将其转换成RGB值,比较两个颜色相近与否,实际上是比较RGB三个分量维度上的误差,最小的口红输出对应的品牌、系列、色号和id,代码如下: import jsonimport getcolorimport numpy as npimport lipcolor#filename = 'temp.txt'##write the temp data to file##def WtoFile(filename,RGB_temp): num=len(RGB_temp) with open(filename,'w') as f: for i in range(num): s = str(RGB_temp[i]).replace('[','').replace(']','') f.write(s) f.write("\n") #operate the data ###save the brand&series&color id&color name to sum_list####covert the color #D62352 to RGB_array####caculate the RGB difference to RGB_temp and write the value to file##def data_operate(): with open('lipstick.json', 'r', encoding='utf-8') as f: ret_dic = json.load(f) #print(ret_dic['brands']) #print(type(ret_dic)) # #print(ret_dic['brands'][0]['name']) b_num=len(ret_dic['brands']) #print(b_num)#brands number s_list=[] #series brands# for i in range(len(ret_dic['brands'])): s_num=len(ret_dic['brands'][i]['series']) s_list.append(s_num) #print("{0} has {1} series".format((ret_dic['brands'][i]['name']),(s_list[i]))) #the lipstick color of every brands every series# #the first loop calculate the total color numbers sum=0 for b1 in range(b_num): for s1 in range(s_list[b1]): brand_name=ret_dic['brands'][b1]['name'] lip_name=ret_dic['brands'][b1]['series'][s1]['name'] color_num=len(ret_dic['brands'][b1]['series'][s1]['lipsticks']) sum+=color_num#calculate the total color numbers #the second loop save the message to a list# sum_list=np.zeros((sum,4), dtype=(str,8)) value_array=np.zeros((sum,6), dtype=int) i=0 for b2 in range(b_num): for s2 in range(s_list[b2]): brand_name=ret_dic['brands'][b2]['name'] #print(type(brand_name)) lip_name=ret_dic['brands'][b2]['series'][s2]['name'] color_num=len(ret_dic['brands'][b2]['series'][s2]['lipsticks']) for c in range(color_num): color_value=ret_dic['brands'][b2]['series'][s2]['lipsticks'][c]['color'] color_name=ret_dic['brands'][b2]['series'][s2]['lipsticks'][c]['name'] color_id=ret_dic['brands'][b2]['series'][s2]['lipsticks'][c]['id'] #print("{0} series {1} has {2} colors,color {3}:{4}".format(brand_name,lip_name,color_num,c+1,color_name)) sum_list[i][0]=brand_name sum_list[i][1]=lip_name sum_list[i][2]=color_id sum_list[i][3]=color_name #value_array[i]=value_array[i][1] #convert "#D62352" to [13 6 2 3 5 2]# for l in range(6): temp=color_value[l+1] if(temp>='A'and temp


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3