Skip to content

Commit 3cc5ab0

Browse files
authored
Merge pull request #85 from OpenPIV/py36
2to3 and py.test revealed the bugs
2 parents 2c8653d + f31ac3f commit 3cc5ab0

File tree

3 files changed

+43
-69
lines changed

3 files changed

+43
-69
lines changed

openpiv/junk.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from six import iteritems
2+
13
class ProcessParameters( UserDict ):
24
def __init__ (self, config_file='' ):
35
"""
@@ -39,7 +41,7 @@ def __init__ (self, config_file='' ):
3941
# cast parameters to the right type.
4042
# this trick is necessary because the ConfigParser
4143
# class only understands strings
42-
for k, v in self.iteritems():
44+
for k, v in iteritems(self):
4345
try:
4446
self[k] = int(v)
4547
except ValueError:
@@ -52,8 +54,8 @@ def pretty_print ( self ):
5254
"""
5355
Pretty print all the processing parameters.
5456
"""
55-
for k, v in self.iteritems():
56-
print("%s = %s" % ( k.rjust(30), repr(v).ljust(30) ));
57+
for k, v in iteritems(self):
58+
print(("%s = %s" % ( k.rjust(30), repr(v).ljust(30) )));
5759

5860
class Hdf5Database( ):
5961
"""

openpiv/pyprocess.py

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from numpy import ma
2626
from scipy.signal import convolve2d
2727
from numpy import log
28+
import matplotlib.pyplot as plt
2829

2930

3031
WINSIZE = 32
@@ -531,23 +532,11 @@ def piv(frame_a, frame_b,
531532
raise(BaseException,'window size cannot be larger than the image')
532533

533534
# get field shape
534-
n_rows, n_cols = get_field_shape(frame_a.shape, window_size, overlap )
535+
n_rows, n_cols = get_field_shape(frame_a.shape, search_size, overlap )
535536

536537
u = np.zeros((n_rows, n_cols))
537538
v = np.zeros((n_rows, n_cols))
538-
sig2noise = np.zeros((n_rows, n_cols))
539-
540-
if search_size > window_size:
541-
frame_b = np.pad(frame_b, ((search_size-window_size)/2,
542-
(search_size-window_size)/2),'constant',
543-
constant_values = (0,0))
544-
545-
# print frame_a.shape, frame_a.dtype, frame_b.shape, frame_b.dtype
546-
# fig,ax = plt.subplots(1,2)
547-
# ax[0].imshow(frame_a,cmap=plt.cm.gray)
548-
# ax[1].imshow(frame_b,cmap=plt.cm.gray)
549-
# plt.show()
550-
# 'constant',constant_values = 0)
539+
sig2noise = np.zeros((n_rows, n_cols))
551540

552541
u, v = np.zeros((n_rows, n_cols)), np.zeros((n_rows, n_cols))
553542

@@ -563,62 +552,44 @@ def piv(frame_a, frame_b,
563552
for m in range(n_cols):
564553
# range(search_size/2, frame_a.shape[1] - search_size/2 , window_size - overlap ):
565554

566-
i = k*(window_size-overlap) + window_size/2
567-
j = m*(window_size-overlap) + window_size/2
568-
569-
# print 'center', i,j
570-
571555

572-
il = i - window_size/2
573-
jt = j - window_size/2
574-
ir = i + window_size/2
575-
jb = j + window_size/2
556+
# Select first the largest window, work like usual from the top left corner
557+
# the left edge goes as:
558+
# e.g. 0, (search_size - overlap), 2*(search_size - overlap),....
576559

577-
# print 'a', il,ir,jt,jb
578-
579-
# il = il if il > 0 else 0
580-
# ir = ir if ir < frame_a.shape[0] else frame_a.shape[0]
581-
# jt = jt if jt > 0 else 0
582-
# jb = jb if jb < frame_a.shape[1] else frame_a.shape[1]
583-
584-
window_a = frame_a[il:ir, jt:jb]
560+
il = k*(search_size - overlap)
561+
ir = il + search_size
585562

586-
# now shift the second image center accordingly
587-
i += (search_size - window_size)/2
588-
j += (search_size - window_size)/2
589-
590-
il = i - search_size/2
591-
ir = i + search_size/2
592-
jt = j - search_size/2
593-
jb = j + search_size/2
563+
# same for top-bottom
564+
jt = m*(search_size - overlap)
565+
jb = jt + search_size
594566

595-
# print 'b', il, ir, jt, jb
596-
597-
# il = il if il > 0 else 0
598-
# ir = ir if ir < frame_a.shape[0] else frame_a.shape[0]
599-
# jt = jt if jt > 0 else 0
600-
# jb = jb if jb < frame_a.shape[1] else frame_a.shape[1]
601-
602-
window_b = frame_b[il:ir, jt:jb]
603-
604-
# fig,ax = plt.subplots(1,2)
605-
# ax[0].imshow(window_a,cmap=plt.cm.gray)
606-
# ax[1].imshow(window_b,cmap=plt.cm.gray)
607-
# plt.show()
567+
# pick up the window in the second image
568+
window_b = frame_b[il:ir, jt:jb]
608569

570+
# now shift the left corner of the smaller window inside the larger one
571+
il += (search_size - window_size)//2
572+
# and it's right side is just a window_size apart
573+
ir = il + window_size
574+
# same same
575+
jt += (search_size - window_size)//2
576+
jb = jt + window_size
577+
578+
window_a = frame_a[il:ir, jt:jb]
579+
609580
if np.any(window_a):
610581
corr = correlate_windows(window_a, window_b,
611582
corr_method=corr_method,
612583
nfftx=nfftx, nffty=nffty)
613-
# plt.figure()
614-
# plt.contourf(corr)
615-
# plt.show()
584+
# plt.figure()
585+
# plt.contourf(corr)
586+
# plt.show()
616587
# get subpixel approximation for peak position row and column index
617-
row, col = find_subpixel_peak_position(
618-
corr, subpixel_method=subpixel_method)
588+
row, col = find_subpixel_peak_position(corr,
589+
subpixel_method=subpixel_method)
619590

620-
row -= (search_size + window_size - 1)/2
621-
col -= (search_size + window_size - 1)/2
591+
row -= (search_size + window_size - 1)//2
592+
col -= (search_size + window_size - 1)//2
622593

623594
# get displacements, apply coordinate system definition
624595
u[k,m],v[k,m] = -col, row

openpiv/tools.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import matplotlib.image as mpltimg
3232
from scipy import ndimage
3333
from skimage import filters, io
34+
from builtins import range
3435

3536

3637
def display_vector_field( filename, on_img=False, image_name='None', window_size=32, scaling_factor=1, **kw):
@@ -165,7 +166,7 @@ def mark_background(threshold, list_img, filename):
165166
mark = np.zeros(list_frame[0].shape, dtype=np.int32)
166167
background = np.zeros(list_frame[0].shape, dtype=np.int32)
167168
for I in range(mark.shape[0]):
168-
print(" row ", I , " / " , mark.shape[0]);
169+
print((" row ", I , " / " , mark.shape[0]));
169170
for J in range(mark.shape[1]):
170171
sum1 = 0
171172
for K in range(len(list_frame)):
@@ -187,7 +188,7 @@ def mark_background2(list_img, filename):
187188
list_frame.append(imread(list_img[I]))
188189
background = np.zeros(list_frame[0].shape, dtype=np.int32)
189190
for I in range(background.shape[0]):
190-
print(" row ", I , " / " , background.shape[0]);
191+
print((" row ", I , " / " , background.shape[0]));
191192
for J in range(background.shape[1]):
192193
min_1 = 255
193194
for K in range(len(list_frame)):
@@ -207,7 +208,7 @@ def find_reflexions(list_img, filename):
207208
background = mark_background2(list_img, filename)
208209
reflexion = np.zeros(background.shape, dtype=np.int32)
209210
for I in range(background.shape[0]):
210-
print(" row ", I , " / " , background.shape[0]);
211+
print((" row ", I , " / " , background.shape[0]));
211212
for J in range(background.shape[1]):
212213
if background[I,J] > 253:
213214
reflexion[I,J] = 255
@@ -226,15 +227,15 @@ def find_boundaries(threshold, list_img1, list_img2, filename, picname):
226227
print("mark1..");
227228
mark1 = mark_background(threshold, list_img1, "mark1.bmp")
228229
print("[DONE]");
229-
print(mark1.shape);
230+
print((mark1.shape));
230231
print("mark2..");
231232
mark2 = mark_background(threshold, list_img2, "mark2.bmp")
232233
print("[DONE]");
233234
print("computing boundary");
234-
print(mark2.shape);
235+
print((mark2.shape));
235236
list_bound = np.zeros(mark1.shape, dtype=np.int32)
236237
for I in range(list_bound.shape[0]):
237-
print( "bound row ", I , " / " , mark1.shape[0]);
238+
print(( "bound row ", I , " / " , mark1.shape[0]));
238239
for J in range(list_bound.shape[1]):
239240
list_bound[I,J]=0
240241
if mark1[I,J]==0:
@@ -387,7 +388,7 @@ def run( self, func, n_cpus=1 ):
387388
"""
388389

389390
# create a list of tasks to be executed.
390-
image_pairs = [ (file_a, file_b, i) for file_a, file_b, i in zip( self.files_a, self.files_b, xrange(self.n_files) ) ]
391+
image_pairs = [ (file_a, file_b, i) for file_a, file_b, i in zip( self.files_a, self.files_b, range(self.n_files) ) ]
391392

392393
# for debugging purposes always use n_cpus = 1,
393394
# since it is difficult to debug multiprocessing stuff.

0 commit comments

Comments
 (0)