Пример #1
0
    def hue_histogram_as_image(self, hist):
        """ Returns a nice representation of a hue histogram """

        histimg_hsv = cv.CreateImage((320, 200), 8, 3)

        mybins = cv.CloneMatND(hist.bins)  #Contain all values
        cv.Log(mybins, mybins
               )  #Calculate logarithm of all values (so there are all above 0)

        (_, hi, _, _) = cv.MinMaxLoc(mybins)
        cv.ConvertScale(mybins, mybins, 255. /
                        hi)  #Rescale all element to get the highest at 255

        w, h = cv.GetSize(histimg_hsv)
        hdims = cv.GetDims(mybins)[0]
        for x in range(w):
            xh = (180 * x) / (w - 1)  # hue sweeps from 0-180 across the image
            val = int(mybins[int(hdims * x / w)] * h / 255)
            cv.Rectangle(histimg_hsv, (x, 0), (x, h - val), (xh, 255, 64), -1)
            cv.Rectangle(histimg_hsv, (x, h - val), (x, h), (xh, 255, 255), -1)

        histimg = cv.CreateImage((320, 200), 8,
                                 3)  #Convert image from hsv to RGB
        cv.CvtColor(histimg_hsv, histimg, cv.CV_HSV2BGR)
        return histimg
Пример #2
0
	def hue_histogram_as_image(self,hist):
		# Return a nice representation of a hue histogram
		histimg_hsv = cv.CreateImage((320,200),8,3)
		mybins = cv.CloneMatND(hist.bins)
		cv.Log(mybins,mybins)
		(_,hi,_,_) = cv.MinMaxLoc(mybins)
		cv.ConvertScale(mybins,mybins,255./hi)
		
		w,h = cv.GetSize(histing_hsv)
		hdims = cv.GetDims(mybins)[0]
		for x in range(w):
			xh = (180*x)/(w-1) # hue sweeps from 0-180 across the image
			val = int(mybins[int(hdims*x/w)]*h/255)
			cv2.rectangle(histimg_hsv,(x,0),(x,h-val),(xh,255,64),-1)
			cv2.rectangle(histimg_hsv,(x,h-val),(x,h),(xh,255,255),-1)
		histimg = cv2.cvtColor(histing_hsv,cv.CV_HSV2BGR)
		return histimg
Пример #3
0
    def hue_histogram_as_image(self, hist):
        """ Returns a nice representation of a hue histogram """

        histimg_hsv = cv.CreateImage((320, 200), cv.IPL_DEPTH_8U, 3)

        mybins = cv.CloneMatND(hist.bins)
        cv.Log(mybins, mybins)
        (_, hi, _, _) = cv.MinMaxLoc(mybins)
        cv.ConvertScale(mybins, mybins, 255. / hi)

        w, h = cv.GetSize(histimg_hsv)
        hdims = cv.GetDims(mybins)[0]
        for x in range(w):
            xh = (180 * x) / (w - 1)
            val = int(mybins[int(hdims * x) / w] * h / 255)
            cv.Rectangle(histimg_hsv, (x, 0), (x, h - val), (xh, 255, 64), -1)
            cv.Rectangle(histimg_hsv, (x, h - val), (x, h), (xh, 255, 255), -1)

        histimg = cv.CreateImage((320, 200), 8, 3)
        cv.CvtColor(histimg_hsv, histimg, cv.CV_HSV2BGR)
        return histimg