Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 4
0
    cv.DFT( dft_A, dft_A, cv.CV_DXT_FORWARD, complexInput.height )

    cv.NamedWindow("win", 0)
    cv.NamedWindow("magnitude", 0)
    cv.ShowImage("win", im)

    # Split Fourier in real and imaginary parts
    cv.Split( dft_A, image_Re, image_Im, None, None )

    # Compute the magnitude of the spectrum Mag = sqrt(Re^2 + Im^2)
    cv.Pow( image_Re, image_Re, 2.0)
    cv.Pow( image_Im, image_Im, 2.0)
    cv.Add( image_Re, image_Im, image_Re, None)
    cv.Pow( image_Re, image_Re, 0.5 )

    # Compute log(1 + Mag)
    cv.AddS( image_Re, cv.ScalarAll(1.0), image_Re, None ) # 1 + Mag
    cv.Log( image_Re, image_Re ) # log(1 + Mag)


    # Rearrange the quadrants of Fourier image so that the origin is at
    # the image center
    cvShiftDFT( image_Re, image_Re )

    min, max, pt1, pt2 = cv.MinMaxLoc(image_Re)
    cv.Scale(image_Re, image_Re, 1.0/(max-min), 1.0*(-min)/(max-min))
    cv.ShowImage("magnitude", image_Re)

    cv.WaitKey(0)
    cv.DestroyAllWindows()