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

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 close merge delete

why would the patch-based version be faster ?

( 2015-02-19 03:41:26 -0500 )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?

( 2015-02-19 03:46:02 -0500 )edit

How fast is the C++ version?

( 2015-02-19 04:09:29 -0500 )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"

( 2015-02-19 04:11:21 -0500 )edit

( 2015-02-19 04:12:11 -0500 )edit

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

basically, you're looking for local maxima ?

( 2015-02-19 04:17:56 -0500 )edit

yep, at this moment

( 2015-02-19 04:19:34 -0500 )edit

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

( 2015-02-19 04:25:06 -0500 )edit

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

( 2015-02-19 04:36:00 -0500 )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.

( 2015-02-19 06:54:42 -0500 )edit