為了給女朋友獨(dú)特的七夕驚喜,我學(xué)會(huì)了人像美膚算法!
點(diǎn)擊上方“小白學(xué)視覺”,選擇加"星標(biāo)"或“置頂”
重磅干貨,第一時(shí)間送達(dá)

在人像美顏中,美膚是一個(gè)非常重要的組成部分,健康的膚色,可以凸顯一個(gè)人整體的氣質(zhì)。搞定一套人像美膚算法,從根源解決你不會(huì)P圖的煩惱,從此的你指哪磨哪,讓女票對(duì)你刮目相看!你看,奪好


皮膚美白算法
皮膚調(diào)色算法


皮膚美白算法







/**************************************************************************函數(shù): 膚色美白*參數(shù):*srcData:32BGRA 位圖像數(shù)據(jù)*width: 圖像寬度*height: 圖像高度*stride: 圖像 Stride*skinMask: 皮膚蒙版*lutData: 32BGRA LUT 圖像數(shù)據(jù)*ratio: 美白程度,范圍[0,100]*返回值: 0-成功,其他失敗**************************************************************************/int f_SkinWhite(unsigned char* srcData, int width, int height, int stride,unsigned char* lutData, int ratio){int ret = 0;int length = height * stride;unsigned char* tempData = (unsigned char*)malloc(sizeof(unsigned char) *length);memcpy(tempData, srcData, sizeof(unsigned char) * length);unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) *length);memcpy(skinPDF, srcData, sizeof(unsigned char) * length);ret = f_SkinPDF(skinPDF, width, height, stride);int maskSmoothRadius = 3;ret = f_FastGaussFilter(skinPDF, width, height, stride,maskSmoothRadius);ret = f_LUTFilter(tempData, width, height, stride, lutData);unsigned char* pSrc = srcData;unsigned char* pLut = tempData;unsigned char* pSkin = skinPDF;for(int j = 0; j < height; j++){for(int i = 0; i < width; i++){int r, g, b, a;b = CLIP3((pSrc[0] * (100 - ratio) + pLut[0] * ratio) / 100, 0, 255);g = CLIP3((pSrc[1] * (100 - ratio) + pLut[1] * ratio) / 100, 0, 255);r = CLIP3((pSrc[2] * (100 - ratio) + pLut[2] * ratio) / 100, 0, 255);a = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;pSrc[0] = CLIP3((b * a + pSrc[0] * (255 - a)) / 255, 0, 255);pSrc[1] = CLIP3((g * a + pSrc[1] * (255 - a)) / 255, 0, 255);pSrc[2] = CLIP3((r * a + pSrc[2] * (255 - a)) / 255, 0, 255);pSrc += 4;pLut += 4;pSkin += 4;}}free(tempData);free(skinPDF);return ret;};/**************************************************************************函數(shù): 膚色美白曲線法*參數(shù):*srcData:32BGRA 圖像數(shù)據(jù)*width: 圖像寬度*height: 圖像高度*stride: 圖像 Stride*belta: 曲線參數(shù) belta,范圍[2,10],默認(rèn):2*ratio: 磨皮程度,范圍 [0,100]*返回值: 0-成功,其他失敗*參考資料: "A Two-Stage Contrast Enhancement Algorithm for Digital Images"**************************************************************************/int f_SkinWhiteCurve(unsigned char* srcData, int width, int height, intstride, int belta, int ratio){int ret = 0;int length = height * stride;unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) *length);memcpy(skinPDF, srcData, sizeof(unsigned char) * length);ret = f_SkinPDF(skinPDF, width, height, stride);int maskSmoothRadius = 3;ret = f_FastGaussFilter(skinPDF, width, height, stride,maskSmoothRadius);unsigned char* pSrc = srcData;unsigned char* pSkin = skinPDF;for(int j = 0; j < height; j++){for(int i = 0; i < width; i++){int r, g, b, a;//skin white curveb = CLIP3(log((float)pSrc[0] * (belta - 1) / 255.0f + 1) /log((float)belta) * 255.0f, 0, 255);g = CLIP3(log((float)pSrc[1] * (belta - 1) / 255.0f + 1) /log((float)belta) * 255.0f, 0, 255);r = CLIP3(log((float)pSrc[2] * (belta - 1) / 255.0f + 1) /log((float)belta) * 255.0f, 0, 255);b = CLIP3((b * ratio + pSrc[0] * (100 - ratio)) / 100, 0, 255);g = CLIP3((g * ratio + pSrc[1] * (100 - ratio)) / 100, 0, 255);r = CLIP3((r * ratio + pSrc[2] * (100 - ratio)) / 100, 0, 255);//skin pdfa = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;pSrc[0] = CLIP3((b * a + pSrc[0] * (255 - a)) / 255, 0, 255);pSrc[1] = CLIP3((g * a + pSrc[1] * (255 - a)) / 255, 0, 255);pSrc[2] = CLIP3((r * a + pSrc[2] * (255 - a)) / 255, 0, 255);pSrc += 4;pSkin += 4;}}free(skinPDF);return ret;}inline int ModeSmoothLight(int basePixel,int mixPixel){int res = 0;res = mixPixel > 128 ?((int)((float)basePixel+((float)mixPixel+(float)mixPixel-255.0f)*((sqrt((float)basePixel/255.0f) )*255.0f-(float)basePixel)/255.0f)):((int)((float)basePixel+((float)mixPixel+(float)mixPixel-255.0f)*((float)basePixel-(float)basePixel*(float)basePixel/255.0f)/255.0f));return CLIP3(res, 0, 255);};/**************************************************************************函數(shù): PS 圖層法膚色美白*參數(shù):*srcData:32BGRA 圖像數(shù)據(jù)*width: 圖像寬度*height: 圖像高度*stride: 圖像 Stride*ratio: 磨皮程度,范圍 [0,100]*返回值: 0-成功,其他失敗**************************************************************************/int f_SkinWhitePS(unsigned char* srcData, int width, int height, int stride,int ratio){int ret = 0;int length = height * stride;unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) *length);memcpy(skinPDF, srcData, sizeof(unsigned char) * length);ret = f_SkinPDF(skinPDF, width, height, stride);int maskSmoothRadius = 3;ret = f_FastGaussFilter(skinPDF, width, height, stride, maskSmoothRadius);unsigned char* pSrc = srcData;unsigned char* pSkin = skinPDF;for(int j = 0; j < height; j++){for(int i = 0; i < width; i++){int r, g, b, a;//skin white using smoothlight of psb = ModeSmoothLight(pSrc[0], 255);g = ModeSmoothLight(pSrc[1], 255);r = ModeSmoothLight(pSrc[2], 255);b = CLIP3((b * ratio + pSrc[0] * (100 - ratio)) / 100, 0, 255);g = CLIP3((g * ratio + pSrc[1] * (100 - ratio)) / 100, 0, 255);r = CLIP3((r * ratio + pSrc[2] * (100 - ratio)) / 100, 0, 255);//skin pdfa = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;pSrc[0] = CLIP3((b * a + pSrc[0] * (255 - a)) / 255, 0, 255);pSrc[1] = CLIP3((g * a + pSrc[1] * (255 - a)) / 255, 0, 255);pSrc[2] = CLIP3((r * a + pSrc[2] * (255 - a)) / 255, 0, 255);pSrc += 4;pSkin += 4;}}free(skinPDF);return ret;}
皮膚調(diào)色算法



#include?? #include? #include? #include? #include"Commen.h"?#include"f_LUTFilter.h"?#include"f_SkinPDF.h"?#include"f_GaussFilter.h"?#include"f_SkinColor.h"?/**************************************************************************函數(shù):?膚色調(diào)節(jié)?*參數(shù):*srcData:32BGRA 圖像數(shù)據(jù)*width: 圖像寬度*height: 圖像高度*stride: 圖像 Stride*skinMask: 皮膚蒙版*lutData: 32BGRA LUT 圖像數(shù)據(jù)*ratio: 膚色程度,范圍 [0,100]*返回值: 0-成功,其他失敗**************************************************************************/int?f_SkinColor(unsigned?char*?srcData,?int?width,?int?height,?int?stride,?unsigned char* lutData, int ratio){?int?ret?=?0;?int length = height * stride;unsigned char* tempData = (unsigned char*)malloc(sizeof(unsigned char) *length);memcpy(tempData, srcData, sizeof(unsigned char) * length);unsigned char* skinPDF = (unsigned char*)malloc(sizeof(unsigned char) *length);memcpy(skinPDF, srcData, sizeof(unsigned char) * length);ret = f_SkinPDF(skinPDF, width, height, stride);int maskSmoothRadius = 3;ret = f_FastGaussFilter(skinPDF, width, height, stride,maskSmoothRadius);ret = f_LUTFilter(tempData, width, height, stride, lutData);unsigned char* pSrc = srcData;unsigned char* pLut = tempData;unsigned char* pSkin = skinPDF;for(int j = 0; j < height; j++)????{???? ???for(int?i?=?0;?i?width;?i++)?{int r, g, b, a;b = CLIP3((pSrc[0] * (100 - ratio) + pLut[0] * ratio) / 100, 0, 255);g = CLIP3((pSrc[1] * (100 - ratio) + pLut[1] * ratio) / 100, 0, 255);r = CLIP3((pSrc[2] * (100 - ratio) + pLut[2] * ratio) / 100, 0, 255);a = (pSkin[0] + pSkin[1] + pSkin[2]) / 3;pSrc[0] = CLIP3((b * a + pSrc[0] * (255 - a)) / 255, 0, 255);pSrc[1] = CLIP3((g * a + pSrc[1] * (255 - a)) / 255, 0, 255);pSrc[2] = CLIP3((r * a + pSrc[2] * (255 - a)) / 255, 0, 255);pSrc += 4;pLut += 4;pSkin += 4;}}free(tempData);free(skinPDF);return ret;};


胡耀武 譚娟 李云夕 著
3 本書系統(tǒng)、全面地介紹了與圖像視頻濾鏡和人像美顏美妝特效相關(guān)的算法基礎(chǔ)知識(shí)與方法思路,涵蓋了市面上流行的美顏美妝App的特效功能,包括傳統(tǒng)方法和基于深度學(xué)習(xí)的AI濾鏡和美顏算法。


評(píng)論
圖片
表情
