title: Using SVM after feature extraction for Nudity Detection Algorithm
body: <p><strong>Nudity Detection Algorithm</strong></p>
  
  <ul>
  <li>normalization</li>
  <li>Zoning</li>
  <li>Feature Extraction</li>
  <li>Classification using SVM</li>
  </ul>
  
  <p>Following methods are use</p>
  
  <p><strong>1.Normalization</strong>: First image is converted into .jpg format and size of 256X256.Then it is converted into YCbCr color space,for this i use OpenCV python.Here is the <strong>code</strong>.</p>
  
  <p><strong>2.Zoning</strong>: Normalized Images are then divided into three zones.It is because assumption is "Nudity of images are found mostly in Central zone".</p>
  
  <p><strong>3.Feature Extraction</strong>: In this module Image is in YCbCr,Skin pixels are filtered by thresholding in range <strong>(0,133,77),(255,173,127)</strong> and divided into three zones.and then for each zones features are calculated 2 color features(number of connected skin pixels and proportion of skin pixel to total pixel) and 2 texture features(Homogeneity and correlation).texture features are calculated using glcm (skimage.features module).here is the <strong>code</strong></p>
  
  <pre><code>import os
  import numpy as np
  import cv2
  from cv2 import cv
  import skimage.feature as sf
  total_pixels=256.0*256.0
  
  class normalize:
      def __init__(self,src,dst):
          self.src=src
          self.dst=dst+"_1.jpg"
      def resize(self):
          x,y=256,256
          src=cv2.imread(self.src,1)
          src=cv2.resize(src,(x,y))
          cv2.imwrite(self.dst,src)
          dst=cv2.imread(self.dst,1)
          return dst
  """Segmentation module is used to segment out skin pixels in YCrCb color space"""
  
  def segmentation(src):
      img=src.copy()
      img=cv2.cvtColor(src,cv.CV_BGR2YCrCb)
      dst=cv2.inRange(img,(0,133,77),(255,173,127))
      return dst
  
  """Image Zoning and feature extraction module"""
  
  class features:
      def __init__(self,src):
          self.zone1=src
          self.zone2=src[30:226,30:226]
          self.zone3=src[60:196,60:196]
  
      def createglcm(self,zone):
          return sf.greycomatrix(zone,[1],[0,np.pi/4,np.pi/2,-np.pi/2,-np.pi/4,np.pi*25/12],normed=True)
  
      def getCorrelation(self,glcm):
          return sf.greycoprops(glcm,'correlation')
  
      def getHomogeneity(self,glcm):
          return sf.greycoprops(glcm,'homogeneity')
  
      def getcolorfeatures(self,zone):
          contours, hierarchy = cv2.findContours(zone,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
  
          skin_pixel_connected=0 
  
          for i in range(len(contours)):
              skin_pixel_connected=skin_pixel_connected+cv2.contourArea(contours[i])
  
          return [skin_pixel_connected,skin_pixel_connected/total_pixels]
  </code></pre>
  
  <p>Now i have retrieved a list of various features as given in code. How to make feature vector for svm from python lists.How to use SVM for training by using nude and non-nude image(i have 5000 images) and then for detection.? Can any body suggest me.</p>