def test_process_extended_search_area(): """ test of the extended area PIV from Cython """ frame_a, frame_b = create_pair(image_size=64) u, v, _ = piv(frame_a, frame_b, window_size=16, search_area_size=32, dt=2., overlap=0) assert np.allclose(u, shift_u/2., atol=threshold) assert np.allclose(v, shift_v/2., atol=threshold)
def test_extended_search_area_overlap(): """ test of the extended area PIV with different overlap """ frame_a = np.zeros((64, 64)) frame_a = random_noise(frame_a) frame_a = img_as_ubyte(frame_a) frame_b = np.roll(np.roll(frame_a, 3, axis=1), 2, axis=0) u, v = piv(frame_a, frame_b, window_size=16, search_size=32, overlap=8) # print u,v assert (np.max(np.abs(u - 3) + np.abs(v + 2)) <= 0.3)
def test_validation_peak2peak(): """test of the simplest PIV run default window_size = 32 """ _, _, s2n = piv(frame_a, frame_b, window_size=32, sig2noise_method="peak2peak") assert np.allclose(np.min(s2n), 1.24009)
def test_extended_search_area_overlap(): """ test of the extended area PIV with different overlap """ frame_a = np.zeros((64,64)) frame_a = random_noise(frame_a) frame_a = img_as_ubyte(frame_a) frame_b = np.roll(np.roll(frame_a,3,axis=1),2,axis=0) u,v = piv(frame_a,frame_b,window_size=16,search_size=32,overlap=8) # print u,v assert(np.max(np.abs(u-3)+np.abs(v+2)) <= 0.3)
def test_extended_search_area_sig2noise(): """ test of the extended area PIV with sig2peak """ frame_a = np.zeros((64,64)) frame_a = random_noise(frame_a) frame_a = img_as_ubyte(frame_a) frame_b = np.roll(np.roll(frame_a,3,axis=1),2,axis=0) u,v,s2n = piv(frame_a,frame_b,window_size=16,search_size=32, sig2noise_method='peak2peak') assert(np.max(np.abs(u-3)+np.abs(v+2)) <= 0.2)
def test_validation_peak2mean(): """test of the simplest PIV run default window_size = 32 """ _, _, s2n = piv(frame_a, frame_b, window_size=32, sig2noise_method="peak2mean") assert np.allclose(s2n.min(), 1.443882)
def test_piv_smaller_window(): """ test of the search area larger than the window """ frame_a = np.zeros((32, 32)) frame_a = random_noise(frame_a) frame_a = img_as_ubyte(frame_a) frame_b = np.roll(np.roll(frame_a, -3, axis=1), -2, axis=0) u, v = piv(frame_a, frame_b, window_size=16, search_size=32) # print u,v assert (np.max(np.abs(u + 3)) < 0.2) assert (np.max(np.abs(v - 2)) < 0.2)
def test_piv(): """ test of the simplest PIV run """ frame_a = np.zeros((32, 32)) frame_a = random_noise(frame_a) frame_a = img_as_ubyte(frame_a) frame_b = np.roll(np.roll(frame_a, 3, axis=1), 2, axis=0) u, v = piv(frame_a, frame_b, window_size=32) # print u,v assert (np.max(np.abs(u - 3)) < 0.2) assert (np.max(np.abs(v + 2)) < 0.2)
def test_piv(): """ test of the simplest PIV run """ frame_a = np.zeros((32,32)) frame_a = random_noise(frame_a) frame_a = img_as_ubyte(frame_a) frame_b = np.roll(np.roll(frame_a,3,axis=1),2,axis=0) u,v = piv(frame_a,frame_b,window_size=32) # print u,v assert(np.max(np.abs(u-3)) < 0.2) assert(np.max(np.abs(v+2)) < 0.2)
def test_piv_smaller_window(): """ test of the search area larger than the window """ frame_a = np.zeros((32,32)) frame_a = random_noise(frame_a) frame_a = img_as_ubyte(frame_a) frame_b = np.roll(np.roll(frame_a,-3,axis=1),-2,axis=0) u,v = piv(frame_a,frame_b,window_size=16,search_size=32) # print u,v assert(np.max(np.abs(u+3)) < 0.2) assert(np.max(np.abs(v-2)) < 0.2)
def test_extended_search_area_overlap(): """ test of the extended area PIV with different overlap """ frame_a, frame_b = create_pair(image_size=72) u, v, _ = piv(frame_a, frame_b, window_size=16, search_area_size=32, overlap=8) print(f"\n u={u}\n v={v}\n") assert np.allclose(u, shift_u, atol=threshold) assert np.allclose(v, shift_v, atol=threshold)
def test_extended_search_area(): """ test of the extended area PIV with larger image """ frame_a, frame_b = create_pair(image_size=64, u=-3.5, v=-2.1) u, v, _ = piv(frame_a, frame_b, window_size=16, search_area_size=32, overlap=0) assert np.allclose(u, -3.5, atol=threshold) assert np.allclose(v, -2.1, atol=threshold)
def test_piv(): """test of the simplest PIV run default window_size = 32 """ frame_a, frame_b = create_pair(image_size=32) # extended_search_area_piv returns image based coordinate system u, v, _ = piv(frame_a, frame_b, window_size=32) print(u, v) assert np.allclose(u, shift_u, atol=threshold) assert np.allclose(v, shift_v, atol=threshold)
def test_extended_search_area_sig2noise(): """ test of the extended area PIV with sig2peak """ frame_a, frame_b = create_pair(image_size=64, u=-3.5, v=2.1) u, v, s2n = piv(frame_a, frame_b, window_size=16, search_area_size=32, sig2noise_method="peak2peak", subpixel_method="gaussian") assert np.allclose(u, -3.5, atol=threshold) assert np.allclose(v, 2.1, atol=threshold)
def test_extended_search_area_sig2noise(): """ test of the extended area PIV with sig2peak """ frame_a = np.zeros((64, 64)) frame_a = random_noise(frame_a) frame_a = img_as_ubyte(frame_a) frame_b = np.roll(np.roll(frame_a, 3, axis=1), 2, axis=0) u, v, s2n = piv(frame_a, frame_b, window_size=16, search_size=32, sig2noise_method='peak2peak') assert (np.max(np.abs(u - 3) + np.abs(v + 2)) <= 0.2)
def two_images(image_1, image_2): with open("image_1.bmp", "wb") as fh1: fh1.write(base64.b64decode(image_1)) with open("image_2.bmp", "wb") as fh2: fh2.write(base64.b64decode(image_2)) frame_a = tools.imread('image_1.bmp') frame_b = tools.imread('image_2.bmp') winsize = 32 # pixels searchsize = 64 # pixels, search in image B overlap = 12 # pixels dt = 0.02 # sec u, v, sig2noise = pyprocess.piv(frame_a.astype(np.int32), frame_b.astype(np.int32), window_size=winsize, overlap=overlap, dt=dt, search_size=searchsize, sig2noise_method='peak2peak') x, y = pyprocess.get_coordinates(image_size=frame_a.shape, window_size=searchsize, overlap=overlap) u, v, mask = validation.sig2noise_val(u, v, sig2noise, threshold=1.3) u, v = filters.replace_outliers(u, v, method='localmean', max_iter=10, kernel_size=2) x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor=96.52) file_name = 'result.txt' if os.path.isfile(file_name): os.remove(file_name) tools.save(x, y, u, v, np.zeros_like(u), file_name) # no masking, all values are valid with open(file_name, "rb") as resultFile: file_reader = resultFile.read() image_encode = base64.encodestring(file_reader) base64_string = str(image_encode, 'utf-8') return base64_string
u, v = process.extended_search_area_piv(frame_a.astype(np.int32), frame_b.astype(np.int32), window_size=24, overlap=12, search_area_size=32, dt=1.) plt.figure() plt.quiver(u, v) plt.axis('equal') plt.show() u1, v1 = pyprocess.piv(frame_a, frame_b, window_size=32, search_size=48, overlap=24) # x, y = process.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=0) plt.figure() plt.quiver(u1, v1, v1) plt.axis('equal') plt.show() u2, v2 = pyprocess.piv(frame_a, frame_b, corr_method='direct', window_size=32) # x, y = process.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=0) plt.figure()
def test_piv_smaller_window(): """ test of the search area larger than the window """ frame_a, frame_b = create_pair(image_size=32, u=-3.5, v=-2.1) u, v, _ = piv(frame_a, frame_b, window_size=16, search_area_size=32) assert np.allclose(u, -3.5, atol=threshold) assert np.allclose(v, -2.1, atol=threshold)
u, v, sig2noise = process.extended_search_area_piv( frame_a.astype(np.int32), frame_b.astype(np.int32), window_size=24, overlap=12, dt=0.02, search_area_size=64, sig2noise_method='peak2peak' ) x, y = process.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=12 ) u, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 1.3 ) u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2) x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 ) tools.save(x, y, u, v, mask, 'exp1_001.txt' ) tools.display_vector_field('exp1_001.txt', scale=100, width=0.0025) u1, v1, sig2noise = pyprocess.piv( frame_a.astype(np.int32), frame_b.astype(np.int32), window_size=24, overlap=12, dt=0.02, search_size=64, sig2noise_method='peak2peak' ) x, y = process.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=12 ) u1, v1, mask = validation.sig2noise_val( u1, v1, sig2noise, threshold = 1.3 ) u1, v1 = filters.replace_outliers( u1, v1, method='localmean', max_iter=10, kernel_size=2) x, y, u1, v1 = scaling.uniform(x, y, u1, v1, scaling_factor = 96.52 ) tools.save(x, y, u1, v1, mask, 'exp1_001_1.txt' ) tools.display_vector_field('exp1_001_1.txt', scale=100, width=0.0025)
frame_a = tools.imread( 'exp1_001_a.bmp' ) frame_b = tools.imread( 'exp1_001_b.bmp' ) u, v, sig2noise = process.extended_search_area_piv( frame_a.astype(np.int32), frame_b.astype(np.int32), window_size=24, overlap=12, dt=0.02, search_area_size=64, sig2noise_method='peak2peak' ) x, y = process.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=12 ) u, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 2.5 ) u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2) x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 ) tools.save(x, y, u, v, mask, 'exp1_001.txt' ) tools.display_vector_field('exp1_001.txt', scale=100, width=0.0025) u, v, s2n= pyprocess.piv(frame_a, frame_b, corr_method='fft', window_size=24, overlap=12, dt=0.02, sig2noise_method='peak2peak' ) x, y = pyprocess.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=12 ) u, v, mask = validation.sig2noise_val( u, v, s2n, threshold = 2.5 ) u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2.5) x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor = 96.52 ) tools.save(x, y, u, v, mask, 'exp1_002.txt' ) tools.display_vector_field('exp1_002.txt', scale=100, width=0.0025) u,v,s2n = pyprocess.piv( frame_a, frame_b, corr_method='direct', window_size=24, overlap=12, dt=0.02, sig2noise_method='peak2peak' ) x, y = pyprocess.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=12 ) u, v, mask = validation.sig2noise_val( u, v, sig2noise, threshold = 2.5 ) u, v = filters.replace_outliers( u, v, method='localmean', max_iter=10, kernel_size=2.5)
#frame_b = frame_b[:256,:] plt.figure() plt.imshow(np.c_[frame_a,frame_b],cmap=plt.cm.gray) plt.show() u, v = process.extended_search_area_piv(frame_a.astype(np.int32), frame_b.astype(np.int32), window_size=24, overlap=12, search_area_size=32, dt = 1.) plt.figure() plt.quiver(u,v) plt.axis('equal') plt.show() u1, v1 = pyprocess.piv(frame_a, frame_b, window_size=32, search_size=48, overlap=24) # x, y = process.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=0) plt.figure() plt.quiver(u1,v1,v1) plt.axis('equal') plt.show() u2, v2 = pyprocess.piv(frame_a, frame_b, corr_method = 'direct', window_size=32) # x, y = process.get_coordinates( image_size=frame_a.shape, window_size=24, overlap=0) plt.figure() plt.quiver(u2,v2,v2)
window_size=24, overlap=12) u, v, mask = validation.sig2noise_val(u, v, sig2noise, threshold=2.5) u, v = filters.replace_outliers(u, v, method='localmean', max_iter=10, kernel_size=2) x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor=96.52) tools.save(x, y, u, v, mask, 'exp1_001.txt') tools.display_vector_field('exp1_001.txt', scale=100, width=0.0025) u, v, s2n = pyprocess.piv(frame_a, frame_b, corr_method='fft', window_size=24, overlap=12, dt=0.02, sig2noise_method='peak2peak') x, y = pyprocess.get_coordinates(image_size=frame_a.shape, window_size=24, overlap=12) u, v, mask = validation.sig2noise_val(u, v, s2n, threshold=2.5) u, v = filters.replace_outliers(u, v, method='localmean', max_iter=10, kernel_size=2.5) x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor=96.52) tools.save(x, y, u, v, mask, 'exp1_002.txt') tools.display_vector_field('exp1_002.txt', scale=100, width=0.0025)
u, v = filters.replace_outliers(u, v, method='localmean', max_iter=10, kernel_size=2) x, y, u, v = scaling.uniform(x, y, u, v, scaling_factor=96.52) tools.save(x, y, u, v, mask, 'exp1_001.txt') tools.display_vector_field('exp1_001.txt', scale=100, width=0.0025) u1, v1, sig2noise = pyprocess.piv(frame_a.astype(np.int32), frame_b.astype(np.int32), window_size=24, overlap=12, dt=0.02, search_size=64, sig2noise_method='peak2peak') x, y = process.get_coordinates(image_size=frame_a.shape, window_size=24, overlap=12) u1, v1, mask = validation.sig2noise_val(u1, v1, sig2noise, threshold=1.3) u1, v1 = filters.replace_outliers(u1, v1, method='localmean', max_iter=10, kernel_size=2)