#NEWLINE# def HSHist( im , h_bins = 32 , s_bins = 32 , mask = None , normalize = True ) : #NEWLINE# #INDENT# '\n    Compute the hue saturation histogram of an image. (Based on OpenCV example code).\n    \n    @param im: the image\n    @type im: pv.Image\n    @param h_bins: the number of bins for hue.\n    @type h_bins: int\n    @param s_bins: the number of bins for saturation.\n    @type s_bins: int\n    @param mask: an image containing a mask\n    @type mask: cv.Image or np.array(dtype=np.bool)\n    @return: an OpenCV histogram\n    @rtype: pv.Histogram\n    ' #NEWLINE# ( w , h ) = im . size #NEWLINE# hsv = im . asHSV ( ) #NEWLINE# h_plane = cv . CreateImage ( ( w , h ) , cv . IPL_DEPTH_8U , 1 ) #NEWLINE# s_plane = cv . CreateImage ( ( w , h ) , cv . IPL_DEPTH_8U , 1 ) #NEWLINE# cv . Split ( hsv , h_plane , s_plane , None , None ) #NEWLINE# planes = [ h_plane , s_plane ] #NEWLINE# hist_size = [ h_bins , s_bins ] #NEWLINE# h_ranges = [ 0 , 180 ] #NEWLINE# s_ranges = [ 0 , 255 ] #NEWLINE# ranges = [ h_ranges , planes ] #NEWLINE# hist = cv . CreateHist ( hist_size , cv . CV_HIST_ARRAY , ranges , 1 ) #NEWLINE# if ( mask != None ) : #NEWLINE# #INDENT# mask = mask . asOpenCVBW ( ) #NEWLINE# #UNINDENT# cv . CalcHist ( planes , hist , mask = mask ) #NEWLINE# return pv . Histogram ( hist , HIST_HS , h_bins , s_bins , None )