1+ import numpy as np
2+ import matplotlib .pyplot as plt
3+
4+ from openpiv import pyprocess , tools
5+ import pkg_resources as pkg
6+
7+ # import numpy as np
8+
9+ import matplotlib .animation as animation
10+
111"""This module contains image processing routines that improve
212images prior to PIV processing."""
313
1626"""
1727
1828
19- def piv_example ( ):
29+ def simple_piv ( im1 , im2 ):
2030 """
2131 Simplest PIV run on the pair of images using default settings
2232
23- piv(im1,im2) will create a tmp.vec file with the vector filed in pix/dt (dt=1) from
24- two images, im1,im2 provided as full path filenames (TIF is preferable, whatever imageio can read)
33+ piv(im1,im2) will create a tmp.vec file with the vector filed in pix/dt
34+ (dt=1) from two images, im1,im2 provided as full path filenames
35+ (TIF is preferable, whatever imageio can read)
2536
2637 """
2738
28- import imageio
29- import numpy as np
30- import matplotlib .pyplot as plt
39+ frame_a = tools .imread (im1 )
40+ frame_b = tools .imread (im2 )
3141
32- from openpiv import pyprocess
33- import pkg_resources as pkg
42+ vel = pyprocess .extended_search_area_piv (
43+ frame_a .astype (np .int32 ), frame_b .astype (np .int32 ), window_size = 32 ,
44+ overlap = 16 , search_area_size = 64
45+ )
46+ x , y = pyprocess .get_coordinates (image_size = frame_a .shape ,
47+ search_area_size = 64 , overlap = 16 )
3448
35- # import numpy as np
49+ fig , ax = plt .subplots (figsize = (6 , 6 ))
50+ ax .imshow (frame_a , cmap = plt .get_cmap ("gray" ), alpha = 0.8 , origin = "upper" )
51+ ax .quiver (x , y , vel [0 ], vel [1 ], scale = 50 , color = "r" )
52+ plt .show ()
53+
54+ return x , y , vel [0 ], vel [1 ]
3655
37- import matplotlib .animation as animation
3856
57+ def piv_example ():
58+ """
59+ PIV example uses examples/test5 vortex PIV data to show the main principles
60+
61+ piv(im1,im2) will create a tmp.vec file with the vector filed in pix/dt
62+ (dt=1) from two images, im1,im2 provided as full path filenames
63+ (TIF is preferable)
64+
65+ """
3966 # if im1 is None and im2 is None:
4067 im1 = pkg .resource_filename ("openpiv" , "examples/test5/frame_a.tif" )
4168 im2 = pkg .resource_filename ("openpiv" , "examples/test5/frame_b.tif" )
4269
43- frame_a = imageio .imread (im1 )
44- frame_b = imageio .imread (im2 )
70+ frame_a = tools .imread (im1 )
71+ frame_b = tools .imread (im2 )
4572
46- frame_a [0 :32 , 512 - 32 :] = 255
73+ frame_a [0 :32 , 512 - 32 :] = 255
4774
4875 images = []
4976 images .extend ([frame_a , frame_b ])
@@ -58,17 +85,19 @@ def piv_example():
5885 im = ax .imshow (images [i % 2 ], animated = True , cmap = plt .cm .gray )
5986 ims .append ([im ])
6087
61- _ = animation .ArtistAnimation (fig , ims , interval = 200 , blit = False , repeat_delay = 0 )
88+ _ = animation .ArtistAnimation (fig , ims , interval = 200 , blit = False ,
89+ repeat_delay = 0 )
6290 plt .show ()
6391
6492 # import os
6593
6694 vel = pyprocess .extended_search_area_piv (
67- frame_a .astype (np .int32 ), frame_b .astype (np .int32 ), window_size = 32 ,
68- overlap = 16
95+ frame_a .astype (np .int32 ), frame_b .astype (np .int32 ), window_size = 32 ,
96+ search_area_size = 64 ,
97+ overlap = 8
6998 )
70- x , y = pyprocess .get_coordinates (image_size = frame_a .shape ,
71- search_area_size = 32 , overlap = 16 )
99+ x , y = pyprocess .get_coordinates (image_size = frame_a .shape ,
100+ search_area_size = 64 , overlap = 8 )
72101
73102 fig , ax = plt .subplots (1 , 2 , figsize = (11 , 8 ))
74103 ax [0 ].imshow (frame_a , cmap = plt .get_cmap ("gray" ), alpha = 0.8 , origin = "upper" )
0 commit comments