-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvanilla_piv_snippet.py
29 lines (27 loc) · 1.48 KB
/
vanilla_piv_snippet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def CalcFlowUsingVanillaPIV(imagePair, iwPos):
# Calculate the flow based on traditional window-based PIV analysis
shiftDescriptionPIV = np.zeros(iwPos.shape)
smallIWSize = controlPointSpacing
largeIWSize = 2 * controlPointSpacing
for n in range(iwPos.shape[0]):
a = imagePair[0, iwPos[n,1]-int(smallIWSize/2):iwPos[n,1]+int(smallIWSize/2),\
iwPos[n,0]-int(smallIWSize/2):iwPos[n,0]+int(smallIWSize/2)]
b = imagePair[1, iwPos[n,1]-int(largeIWSize/2):iwPos[n,1]+int(largeIWSize/2),\
iwPos[n,0]-int(largeIWSize/2):iwPos[n,0]+int(largeIWSize/2)]
sad_using_c_code = jpsad.sad_correlation(a, b)
zeroPoint = np.array([1,1])*int((largeIWSize-smallIWSize)/2)
shiftDescriptionPIV[n] = -(np.array(np.unravel_index(sad_using_c_code.argmin(), sad_using_c_code.shape))[::-1]-zeroPoint)
if xMotionPermitted:
return shiftDescriptionPIV
else:
return shiftDescriptionPIV[:,1:]
if source == 'synthetic':
# Synthetic images - draw all vectors
thresh = 0
else:
# Experimental PIV images - suppress vectors in dark regions
thresh = 6e5
shiftDescriptionPIVRaw = CalcFlowUsingVanillaPIV(dualObject[0], iwPos)
ShowDualObjectAndFlow(dualObject, shiftDescriptionPIVRaw*3, suppressDark=thresh)
shiftDescriptionPIVReconstructed = CalcFlowUsingVanillaPIV(dualObjectRecovered[0], iwPos)
ShowDualObjectAndFlow(dualObjectRecovered, shiftDescriptionPIVReconstructed*3, suppressDark=thresh)