Ask Your Question
0

histogram in database

asked Mar 14 '13

mrgloom gravatar image

I compute histogram for image(code below)

def compute_histogram_rgb(src, r_bins = 32, g_bins = 32, b_bins= 32):
        #create planes
        rplane = cv.CreateImage(cv.GetSize(src), 8, 1)
        gplane = cv.CreateImage(cv.GetSize(src), 8, 1)
        bplane = cv.CreateImage(cv.GetSize(src), 8, 1)

        planes = [rplane, gplane, bplane]
        cv.Split(src, rplane, gplane, bplane, None)

        #compute histogram
        hist = cv.CreateHist((r_bins, g_bins, b_bins), cv.CV_HIST_ARRAY,
                ranges = ((0, 255),(0, 255), (0, 255)), uniform = True)
        cv.CalcHist(planes, hist)      #compute histogram
        cv.NormalizeHist(hist, 1.0)    #normalize hist

        return hist

and then I want to store histogram in database (sqllite3 in python) but I don't know what format histogram is, do I need to unwrap it to vector?

Preview: (hide)

Comments

it would get much easier using the cv2 instead of the cv api, since it would be a simple numpy array then, which is easy to serialize as a 'blob' in sqlite3

berak gravatar imageberak (Mar 15 '13)edit

cv2 is more complicated, do you have any example with numpy array?

mrgloom gravatar imagemrgloom (Mar 15 '13)edit

1 answer

Sort by » oldest newest most voted
0

answered Mar 14 '13

Documentation says the following

Python: cv.CreateHist(dims, type, ranges=None, uniform=1)  hist

So I am guessing that the createHist function actually throws back a python defined hist data type.

This link has some information contained on how histograms are actually created. I guess this can help ya further? http://msenux.redwoods.edu/math/python/hist.php

When storing in a database, I would suggest reading out the data of that object type and putting it in a own selected format.

Preview: (hide)

Comments

it seems when table created I need to specify type of column http://docs.python.org/2/library/sqlite3.html

mrgloom gravatar imagemrgloom (Mar 14 '13)edit

That is something you have to do in every database environment. However, I do not think it will support basic storage of a complete hist object. So creating a vector of integers or so, will certainly do the trick.

StevenPuttemans gravatar imageStevenPuttemans (Mar 14 '13)edit

Question Tools

Stats

Asked: Mar 14 '13

Seen: 1,181 times

Last updated: Mar 14 '13