what is the fastest way to do patch-based image analysis

asked 2015-02-19 03:37:10 -0600

fery gravatar image

hi,

I am trying to do some analysis over an image but i need to do that patch by patch. I am using opencv python for this purpose. but this way it takes long time(3 mins) for an mid resolution image (1980 * 1020),

is there any fast way or its the best that i can get?!

edit retag flag offensive close merge delete

Comments

why would the patch-based version be faster ?

berak gravatar imageberak ( 2015-02-19 03:41:26 -0600 )edit

What do you mean Berak? its way faster using c++ opencv, ok I know c++ is faster than python but the difference is more than i expected. and also I am doing very simple calculation on every patch why should it take that long?

fery gravatar imagefery ( 2015-02-19 03:46:02 -0600 )edit

How fast is the C++ version?

FooBar gravatar imageFooBar ( 2015-02-19 04:09:29 -0600 )edit

ah I am looking for high luminance occurrence in every patch:

img= cv2.imread("3.png")
window= 5
overlap= 4
h, w= img.shape

    gridx = xrange(0, w - window, window - overlap)
    gridx = np.hstack((gridx, w - window))

    gridy = xrange(0, h - window, window - overlap)
    gridy = np.hstack((gridy, h - window))

    for i in xrange(len(gridx)):
        for j in xrange(len(gridy)):
            xx = gridx[i]
            yy = gridy[j]
            patch = img[yy: yy + window, xx: xx + window]
            mean = np.mean(patch)
            if (central_v-mean) >(np.std(patch)/2):
                        print "HL"
fery gravatar imagefery ( 2015-02-19 04:11:21 -0600 )edit

about 20 sec FooBar

fery gravatar imagefery ( 2015-02-19 04:12:11 -0600 )edit

ah, ok. iterating with ranges over pixels is sloooow.

basically, you're looking for local maxima ?

berak gravatar imageberak ( 2015-02-19 04:17:56 -0600 )edit

yep, at this moment

fery gravatar imagefery ( 2015-02-19 04:19:34 -0600 )edit

start at least with parallel for loops for each patch since the operation is independent for each patch :)

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-19 04:25:06 -0600 )edit

StevenPuttemans: I would need later to go for neighborhood, so don't think parallel can help me :(

fery gravatar imagefery ( 2015-02-19 04:36:00 -0600 )edit

It depends, if you need a 4*4 neighborhood, then simply go for block processing in the parallel loop instead of single regions. Will still increase performance since you can do multiple blocks at a time.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-19 06:54:42 -0600 )edit