日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

基于像素的皮肤检测技术

發(fā)布時(shí)間:2024/3/24 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于像素的皮肤检测技术 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

基于像素的皮膚檢測(cè)技術(shù)

介紹一種基于顏色空間的皮膚檢測(cè)技術(shù),可以檢測(cè)亞洲人種與白人的皮膚,皮膚檢測(cè)

人臉識(shí)別的基礎(chǔ),也是很多人像識(shí)別技術(shù)的基礎(chǔ)操作,在實(shí)際應(yīng)用中還是非常有用的。

?

基于像素的皮膚檢測(cè)主要是尋找正確的顏色空間幾何,圖像處理中,常見(jiàn)的顏色空間

有如下幾種

1.??????RGB色彩空間 – R代表單色紅,G代表單色綠,B代表單色藍(lán)

2.??????HSV色彩空間 – H 代表色彩, S代表飽和度,V代表強(qiáng)度值

3.??????YCbCr色彩空間 – 是數(shù)字電視的色彩空間

?

RGB轉(zhuǎn)換為HSV的Java代碼如下:

public static float[] rgbToHSV(int tr, int tg, int tb) { float min, max, delta; float hue, satur, value; min = Math.min(tr, Math.min(tg, tb)); max = Math.max(tr, Math.max(tg, tb)); value = max; delta = max - min; if(max != 0) { satur = delta/max; } else { satur = 0; hue = -1; } if(tr == max) { hue = (tg - tb)/delta; } else if(tg == max) { hue = 2 + (tb-tr)/delta; } else { hue = 4 + (tr-tg)/delta; } hue = hue * 60.0f; if(hue < 0) { hue = hue + 360; } return new float[]{hue, satur, value}; }
RGB轉(zhuǎn)換為YCbCr的Java代碼如下:

public static int[] rgbToYcrCb(int tr, int tg, int tb) { double sum = tr + tg + tb; double r = ((double)tr)/sum; double g = ((double)tg)/sum; double b = ((double)tb)/sum; double y = 65.481 * r + 128.553 * g + 24.966 * b + 16.0d; double Cr = -37.7745 * r - 74.1592 * g + 111.9337 * b + 128.0d; double Cb = 111.9581 * r -93.7509 * g -18.2072 * b + 128.0d; return new int[]{(int)y, (int)Cr, (int)Cb}; }
一個(gè)簡(jiǎn)單的基于RGB顏色空間的皮膚算法如下:

(R, G, B) is classified as skin if

R > 95 and G > 40 and B > 20and max{R, G, B} – min{R, G, B} > 15 and |R-G| > 15

and R > G and R > B

實(shí)現(xiàn)代碼如下:

public boolean isSkin(int tr, int tg, int tb) { int max = Math.max(tr, Math.max(tg, tb)); int min = Math.min(tr, Math.min(tg, tb)); int rg = Math.abs(tr - tg); if(tr > 95 && tg > 40 && tb > 20 && rg > 15 && (max - min) > 15 && tr > tg && tr > tb) { return true; } else { return false; } }

一個(gè)簡(jiǎn)單的基于HSV顏色空間的皮膚算法如下:

(H, S, V) will be classified as skin if

H > 0 and H < 50 and S > 0.23 andS < 0.68

實(shí)現(xiàn)代碼如下:

public boolean isSkin(int tr, int tg, int tb) { float[] HSV = ColorUtil.rgbToHSV(tr, tg, tb); if((HSV[0] > 0.0f && HSV[0] < 50.0f ) && (HSV[1] > 0.23f && HSV[1] < 0.68f)){ return true; } else { return false; } }

一個(gè)簡(jiǎn)單的基于YCbCr顏色空間的皮膚算法如下:

(Y, Cb, Cr) will be classified as skin if:

Y?> 80 and 85<Cb?< 135 and 135 <Cr?< 180, and (Y,Cb,Cr)= [0,255]?

對(duì)于的Java代碼如下:

public boolean isSkin(int tr, int tg, int tb) { int y = (int)(tr * 0.299 + tg * 0.587 + tb * 0.114); int Cr = tr - y; int Cb = tb - y; if(y> 80 && y < 255 && Cr > 133 && Cr < 173 && 77 < Cb && Cb < 127) { return true; } return false; }
基于上述三個(gè)算法實(shí)現(xiàn)的皮膚檢測(cè)的效果如下:


皮膚檢測(cè)濾鏡的源代碼如下:

package com.process.blur.study; import java.awt.Color; import java.awt.image.BufferedImage; import com.gloomyfish.skin.dection.DefaultSkinDetection; import com.gloomyfish.skin.dection.FastSkinDetection; import com.gloomyfish.skin.dection.GaussianSkinDetection; import com.gloomyfish.skin.dection.HSVSkinDetection; import com.gloomyfish.skin.dection.ISkinDetection; public class SkinFilter extends AbstractBufferedImageOp { private ISkinDetection skinDetector; public SkinFilter(int type) { if(type == 2) { skinDetector = new FastSkinDetection(); } else if(type == 4) { skinDetector = new HSVSkinDetection(); } else if(type == 8) { skinDetector = new GaussianSkinDetection(); } else { skinDetector = new DefaultSkinDetection(); } } @Override public BufferedImage filter(BufferedImage src, BufferedImage dst) { int width = src.getWidth(); int height = src.getHeight(); if ( dst == null ) dst = createCompatibleDestImage( src, null ); int[] inPixels = new int[width*height]; int[] outPixels = new int[width*height]; getRGB( src, 0, 0, width, height, inPixels ); if(skinDetector instanceof GaussianSkinDetection) { ((GaussianSkinDetection)skinDetector).setDispSample(getDispersion(src)); } int index = 0; for(int row=0; row<height; row++) { int ta = 0, tr = 0, tg = 0, tb = 0; for(int col=0; col<width; col++) { index = row * width + col; ta = (inPixels[index] >> 24) & 0xff; tr = (inPixels[index] >> 16) & 0xff; tg = (inPixels[index] >> 8) & 0xff; tb = inPixels[index] & 0xff; if(skinDetector.isSkin(tr, tg, tb)) { outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb; } else { tr = tg = tb = 0; outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb; } } } setRGB( dst, 0, 0, width, height, outPixels ); return dst; } public Color getDispersion(BufferedImage image) { // calculate means of pixel int index = 0; int height = image.getHeight(); int width = image.getWidth(); int[] inPixels = new int[width*height]; getRGB(image, 0, 0, width, height, inPixels ); double redSum = 0, greenSum = 0, blueSum = 0; Color meanColor = getMean(image); double redmeans = meanColor.getRed(); double greenmeans = meanColor.getGreen(); double bluemeans = meanColor.getBlue(); double total = height * width; for(int row=0; row<height; row++) { int ta = 0, tr = 0, tg = 0, tb = 0; for(int col=0; col<width; col++) { index = row * width + col; ta = (inPixels[index] >> 24) & 0xff; tr = (inPixels[index] >> 16) & 0xff; tg = (inPixels[index] >> 8) & 0xff; tb = inPixels[index] & 0xff; double rd = (tr - redmeans); double gd = (tg - greenmeans); double bd = (tb - bluemeans); redSum += rd * rd; greenSum += gd * gd; blueSum += bd * bd; } } int reddiff = (int)Math.sqrt((redSum / total)); int greendiff = (int)Math.sqrt((greenSum / total)); int bluediff = (int)Math.sqrt(blueSum / total); System.out.println(" red dispersion value = " + reddiff); System.out.println(" green dispersion value = " + greendiff); System.out.println(" blue dispersion value = " + bluediff); return new Color(reddiff, greendiff, bluediff); } public Color getMean(BufferedImage image) { // calculate means of pixel int index = 0; int height = image.getHeight(); int width = image.getWidth(); int[] inPixels = new int[width*height]; getRGB(image, 0, 0, width, height, inPixels ); double redSum = 0, greenSum = 0, blueSum = 0; double total = height * width; for(int row=0; row<height; row++) { int ta = 0, tr = 0, tg = 0, tb = 0; for(int col=0; col<width; col++) { index = row * width + col; ta = (inPixels[index] >> 24) & 0xff; tr = (inPixels[index] >> 16) & 0xff; tg = (inPixels[index] >> 8) & 0xff; tb = inPixels[index] & 0xff; redSum += tr; greenSum += tg; blueSum +=tb; } } int redmeans = (int)(redSum / total); int greenmeans = (int)(greenSum / total); int bluemeans = (int)(blueSum / total); System.out.println(" red average value = " + redmeans); System.out.println(" green average value = " + greenmeans); System.out.println(" blue average value = " + bluemeans); return new Color(redmeans, greenmeans, bluemeans); } }
討論:

皮膚檢測(cè)中的后續(xù)處理非常重要,可以除去噪聲,平滑圖像,是皮膚檢測(cè)的結(jié)果

更加的準(zhǔn)確,輸出的更容易接受。


參考引用:

《A New Fast Skin Color Detection Technique》 -?Tarek M. Mahmoud

《Improved Automatic Skin Detection in Color?Images》 -?Filipe Tomaz

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? and Tiago Candeias and Hamid Shahbazkia

《Skin Detection using HSV color space》- unknown author


總結(jié)

以上是生活随笔為你收集整理的基于像素的皮肤检测技术的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。