# import the necessary packages
import numpy as np
import cv2
import imutils

class ColorDescriptor:
	def __init__(self, bins):
		# store the number of bins for the 3D histogram
		self.bins = bins

	def describe(self, image):
		# convert the image to the HSV color space and initialize
		# the features used to quantify the image
		image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
		features = []

		# grab the dimensions and compute the center of the image
		(h, w) = image.shape[:2]
		(cX, cY) = (int(w * 0.5), int(h * 0.5))

		# divide the image into four rectangles/segments (top-left,
		# top-right, bottom-right, bottom-left)
		segments = [(0, cX, 0, cY), (cX, w, 0, cY), (cX, w, cY, h),
			(0, cX, cY, h)]

		# construct an circular mask representing the center of the image
		cirMask = np.zeros(image.shape[:2], dtype = "uint8")
		cirMask = cv2.circle(cirMask,(cX,cY),int(0.25*cX), 255, -1)

		# loop over the segments
		for (startX, endX, startY, endY) in segments:
			# constructing a mask for each corner of the image, subtracting the cicrular center from it
			cornerMask = np.zeros(image.shape[:2], dtype = "uint8")
			cv2.rectangle(cornerMask, (startX, startY), (endX, endY), 255, -1)
			cornerMask = cv2.subtract(cornerMask, cirMask)

			# extract a color histogram from the image, then update the feature vector
			hist = self.histogram(image, cornerMask)
			features.extend(hist)

		# extract a color histogram from the circular region and updating the feature vector
		hist = self.histogram(image, cirMask)
		features.extend(hist)		

		# return the feature vector
		return features

	def histogram(self, image, mask):
		# extract a 3D color histogram from the masked region of the
		# image, using the supplied number of bins per channel
		hist = cv2.calcHist([image], [0, 1, 2], mask, self.bins,
			[0, 180, 0, 256, 0, 256])

		# normalize the histogram if we are using OpenCV 2.4
		if imutils.is_cv2():
			hist = cv2.normalize(hist).flatten()

		# otherwise handle for OpenCV 3+
		else:
			hist = cv2.normalize(hist, hist).flatten()

		# return the histogram
		return hist
fa0113171964f65a44faf4b0dc858d786b513a8a
<mask token>


class ColorDescriptor:

    def __init__(self, bins):
        self.bins = bins
    <mask token>
    <mask token>

<mask token>


class ColorDescriptor:

    def __init__(self, bins):
        self.bins = bins
    <mask token>

    def histogram(self, image, mask):
        hist = cv2.calcHist([image], [0, 1, 2], mask, self.bins, [0, 180, 0,
            256, 0, 256])
        if imutils.is_cv2():
            hist = cv2.normalize(hist).flatten()
        else:
            hist = cv2.normalize(hist, hist).flatten()
        return hist

<mask token>


class ColorDescriptor:

    def __init__(self, bins):
        self.bins = bins

    def describe(self, image):
        image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
        features = []
        h, w = image.shape[:2]
        cX, cY = int(w * 0.5), int(h * 0.5)
        segments = [(0, cX, 0, cY), (cX, w, 0, cY), (cX, w, cY, h), (0, cX,
            cY, h)]
        cirMask = np.zeros(image.shape[:2], dtype='uint8')
        cirMask = cv2.circle(cirMask, (cX, cY), int(0.25 * cX), 255, -1)
        for startX, endX, startY, endY in segments:
            cornerMask = np.zeros(image.shape[:2], dtype='uint8')
            cv2.rectangle(cornerMask, (startX, startY), (endX, endY), 255, -1)
            cornerMask = cv2.subtract(cornerMask, cirMask)
            hist = self.histogram(image, cornerMask)
            features.extend(hist)
        hist = self.histogram(image, cirMask)
        features.extend(hist)
        return features

    def histogram(self, image, mask):
        hist = cv2.calcHist([image], [0, 1, 2], mask, self.bins, [0, 180, 0,
            256, 0, 256])
        if imutils.is_cv2():
            hist = cv2.normalize(hist).flatten()
        else:
            hist = cv2.normalize(hist, hist).flatten()
        return hist

import numpy as np
import cv2
import imutils


class ColorDescriptor:

    def __init__(self, bins):
        self.bins = bins

    def describe(self, image):
        image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
        features = []
        h, w = image.shape[:2]
        cX, cY = int(w * 0.5), int(h * 0.5)
        segments = [(0, cX, 0, cY), (cX, w, 0, cY), (cX, w, cY, h), (0, cX,
            cY, h)]
        cirMask = np.zeros(image.shape[:2], dtype='uint8')
        cirMask = cv2.circle(cirMask, (cX, cY), int(0.25 * cX), 255, -1)
        for startX, endX, startY, endY in segments:
            cornerMask = np.zeros(image.shape[:2], dtype='uint8')
            cv2.rectangle(cornerMask, (startX, startY), (endX, endY), 255, -1)
            cornerMask = cv2.subtract(cornerMask, cirMask)
            hist = self.histogram(image, cornerMask)
            features.extend(hist)
        hist = self.histogram(image, cirMask)
        features.extend(hist)
        return features

    def histogram(self, image, mask):
        hist = cv2.calcHist([image], [0, 1, 2], mask, self.bins, [0, 180, 0,
            256, 0, 256])
        if imutils.is_cv2():
            hist = cv2.normalize(hist).flatten()
        else:
            hist = cv2.normalize(hist, hist).flatten()
        return hist

# import the necessary packages
import numpy as np
import cv2
import imutils

class ColorDescriptor:
	def __init__(self, bins):
		# store the number of bins for the 3D histogram
		self.bins = bins

	def describe(self, image):
		# convert the image to the HSV color space and initialize
		# the features used to quantify the image
		image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
		features = []

		# grab the dimensions and compute the center of the image
		(h, w) = image.shape[:2]
		(cX, cY) = (int(w * 0.5), int(h * 0.5))

		# divide the image into four rectangles/segments (top-left,
		# top-right, bottom-right, bottom-left)
		segments = [(0, cX, 0, cY), (cX, w, 0, cY), (cX, w, cY, h),
			(0, cX, cY, h)]

		# construct an circular mask representing the center of the image
		cirMask = np.zeros(image.shape[:2], dtype = "uint8")
		cirMask = cv2.circle(cirMask,(cX,cY),int(0.25*cX), 255, -1)

		# loop over the segments
		for (startX, endX, startY, endY) in segments:
			# constructing a mask for each corner of the image, subtracting the cicrular center from it
			cornerMask = np.zeros(image.shape[:2], dtype = "uint8")
			cv2.rectangle(cornerMask, (startX, startY), (endX, endY), 255, -1)
			cornerMask = cv2.subtract(cornerMask, cirMask)

			# extract a color histogram from the image, then update the feature vector
			hist = self.histogram(image, cornerMask)
			features.extend(hist)

		# extract a color histogram from the circular region and updating the feature vector
		hist = self.histogram(image, cirMask)
		features.extend(hist)		

		# return the feature vector
		return features

	def histogram(self, image, mask):
		# extract a 3D color histogram from the masked region of the
		# image, using the supplied number of bins per channel
		hist = cv2.calcHist([image], [0, 1, 2], mask, self.bins,
			[0, 180, 0, 256, 0, 256])

		# normalize the histogram if we are using OpenCV 2.4
		if imutils.is_cv2():
			hist = cv2.normalize(hist).flatten()

		# otherwise handle for OpenCV 3+
		else:
			hist = cv2.normalize(hist, hist).flatten()

		# return the histogram
		return hist