OpenPIV simple Multipass

70 views
Skip to first unread message

Akash Singh

unread,
Sep 27, 2023, 8:45:26 AM9/27/23
to openpiv-users
I have an issue with the simple multipass function in windef.py. I am having very incorrect result for the v displacement and the result are good with first_pass. Did someone encounter this issue. Thanks a lot!

Best,
Akash

Ivan Nepomnyashchikh

unread,
Sep 27, 2023, 12:23:09 PM9/27/23
to openpiv-users
I have had something similar. I have already mentioned that somewhere in one of the previous discussions.

When I had this issue, I decided windef.py did not work and I stopped using it. But then, accidentally, I uncovered that it was me who was using it wrong. Thus, windef.py is extremely sensitive to the thresholds that you give to signal to noise ratio and to the median filter. Change those parameters a tiny bit and you get nonsensical results.

My suggestion is you need to work on getting those parameters right. 

If I were you, I would do the following.
windef.py takes effort to set up and run. If you use windef.py to fine tune those parameters you will spend your life time on that. Thus, rewrite your data processing code using the simplest PIV function (for example, openpiv.pyporcess.correlation_to_displacement, or any other that suits you better). Use that simple and fast code to fine tune your thresholds. Then use the thresholds in your windef.py. They might require a tine adjustment, still. But that will be feasible.

Ivan

Alex Liberzon

unread,
Sep 27, 2023, 12:42:33 PM9/27/23
to openpiv-users
Hi, 

Could you please add a link to which demo case you’re referring? If it’s your own images - could you please share with us, along with the code you use to see where the problem might be? 

Regards
Alex

Akash Singh

unread,
Sep 27, 2023, 1:07:39 PM9/27/23
to openpiv-users
Hello Alex,
 I am loading .nd2 files but I have attached two sample images between which I apply my PIV. The result for a 'first_pass' with ws = 64, ol = 32 matches correctly with 'extended_search_area_piv' but the v velocity diverges largely when I use 'simple_multipass'.
Here is the setting and the function run I use for it:

"""

from openpiv import windef  # <---- see windef.py for details
from openpiv import tools, scaling, validation, filters, preprocess
import openpiv.pyprocess as process
from openpiv import pyprocess
import numpy as np
import pathlib
import importlib_resources
from time import time
import warnings
import cv2 as cv
from nd2reader import ND2Reader
from scipy.ndimage.filters import gaussian_filter, gaussian_filter1d
import sys
sys.path.append(r"D:\ESPCI\codes\multgridPIV")  # Add the folder containing the script to the Python path
#import windef_modified  # Import the script as a module
import openpiv.filters
import matplotlib.pyplot as plt
%matplotlib inline



t1 = 23
t2 = 24
gauss_bg = 101
gauss_ns = 1
im1_t0 = tools.imread('t_23.png')#im1[t1]
im2_t0 = tools.imread('t_24.png')#im1[t2]
#im1_t0_fil = gaussian_filter(im1_t0-gaussian_filter(im1_t0, gauss_bg),gauss_ns)
im1_t0_fil = gaussian_filter(im1_t0/gaussian_filter(im1_t0, gauss_bg),gauss_ns)
im2_t0_fil = gaussian_filter(im2_t0/gaussian_filter(im2_t0, gauss_bg),gauss_ns)

settings = windef.PIVSettings()


'Image preprocessing'
# 'None' for no masking, 'edges' for edges masking, 'intensity' for intensity masking
# WARNING: This part is under development so better not to use MASKS
###settings.dynamic_masking_method = 'None'
###settings.dynamic_masking_threshold = 0.005
###settings.dynamic_masking_filter_size = 7
settings.roi = 'full'

settings.deformation_method = 'symmetric'

'Processing Parameters'
settings.correlation_method='circular'  # 'circular' or 'linear'
settings.normalized_correlation=False

settings.num_iterations = 1  # select the number of PIV passes
# add the interroagtion window size for each pass.
# For the moment, it should be a power of 2
settings.windowsizes = ([64]) # if longer than n iteration the rest is ignored
# The overlap of the interroagtion window for each pass.
settings.overlap = ([16]) # This is 50% overlap
# Has to be a value with base two. In general window size/2 is a good choice.
# methode used for subpixel interpolation: 'gaussian','centroid','parabolic'
settings.subpixel_method = 'gaussian'
# order of the image interpolation for the window deformation
settings.interpolation_order = 3
settings.scaling_factor = 1  # scaling factor pixel/meter
settings.dt = (im1.timesteps[t2] - im1.timesteps[t1]) * 1e-3  # time between two frames (in seconds)
'Signal to noise ratio options (only for the last pass)'
# It is possible to decide if the S/N should be computed (for the last pass) or not
# settings.extract_sig2noise = True  # 'True' or 'False' (only for the last pass)
# method used to calculate the signal to noise ratio 'peak2peak' or 'peak2mean'
settings.sig2noise_method = 'peak2peak'
# select the width of the masked to masked out pixels next to the main peak
settings.sig2noise_mask = 2
# If extract_sig2noise==False the values in the signal to noise ratio
# output column are set to NaN
'vector validation options'
# choose if you want to do validation of the first pass: True or False
settings.validation_first_pass = True
# only effecting the first pass of the interrogation the following passes
# in the multipass will be validated
'Validation Parameters'
# The validation is done at each iteration based on three filters.
# The first filter is based on the min/max ranges. Observe that these values are defined in
# terms of minimum and maximum displacement in pixel/frames.
settings.min_max_u_disp = (-30, 30)
settings.min_max_v_disp = (-30, 30)
# The second filter is based on the global STD threshold
settings.std_threshold = 7  # threshold of the std validation
# The third filter is the median test (not normalized at the moment)
##settings.median_threshold = 3  # threshold of the median validation
# On the last iteration, an additional validation can be done based on the S/N.
##settings.median_size=1 #defines the size of the local median
'Validation based on the signal to noise ratio'
# Note: only available when extract_sig2noise==True and only for the last
# pass of the interrogation
# Enable the signal to noise ratio validation. Options: True or False
# settings.do_sig2noise_validation = False # This is time consuming
# minmum signal to noise ratio that is need for a valid vector
##settings.sig2noise_threshold = 1.2
'Outlier replacement or Smoothing options'
# Replacment options for vectors which are masked as invalid by the validation
settings.replace_vectors = True # Enable the replacment. Chosse: True or False
settings.smoothn=True #Enables smoothing of the displacemenet field
settings.smoothn_p=0.5 # This is a smoothing parameter
# select a method to replace the outliers: 'localmean', 'disk', 'distance'
settings.filter_method = 'localmean'
# maximum iterations performed to replace the outliers
settings.max_filter_iteration = 1 #4
settings.filter_kernel_size = 1  # kernel size for the localmean method
'Output options'
# Select if you want to save the plotted vectorfield: True or False
settings.save_plot = True
# Choose wether you want to see the vectorfield or not :True or False
settings.show_plot = True
settings.scale_plot = 200  # select a value to scale the quiver plot of the vectorfield
# run the script with the given settings

x, y, u, v, flags = windef.simple_multipass(im1_t0_fil,im2_t0_fil,settings)
u /= settings.dt
v /= settings.dt 

fig, axs = plt.subplots(1,1, figsize=(12,12))
axs.imshow(im1_t0_fil)
fig.gca().invert_yaxis()
axs.quiver(x,y,u,v,color='white', scale = 0.01, scale_units='xy')

""""""

Most likely as mentioned by Ivan, it can be the issue of additional parameter sensitivity of the 'multipass' method. I will go through and check for each. Thanks a lot!

Best regards,
Akash
t_24.png
t_23.png

Akash Singh

unread,
Sep 27, 2023, 1:08:54 PM9/27/23
to openpiv-users
Hello Evan,
Thanks for the suggestion I will go through with it.

Best regards,
Akash

Ivan Nepomnyashchikh

unread,
Sep 27, 2023, 1:33:55 PM9/27/23
to openpiv-users
Your images are very bad, unless you are doing single frame PIV. But even for single frame PIV, they are not the best.

If you are doing double frame PIV, then you, clearly, have every single kind of optical distortion described in the Adrian's book. And you have them in an exaggerated manner.

If you want to proceed with your images (which I, personally, would be highly skeptical of), you, definitely, need an image fit function. Simple pix-to-mm conversion won't work in your case. OpenPIV can't get you an image fit function.

If you are just playing around, then I wouldn't suggest playing with windef.py. windef.py is an algorithm for fine tuning. Using it for your images is like using Bently on a farm. Just stay with extended_search_area.

If you want to publish it, I, personally, would be highly skeptical of doing it. I would suggest you redesigning your experimental setup first to get good PIV images. Then you can start messing around with windef.py.

You can make windef.py work with your current images, but I, personally, will not believe whatever you are getting is correct.

Ivan

Alex Liberzon

unread,
Sep 27, 2023, 4:09:39 PM9/27/23
to Akash Singh, openpiv-users
Hi,

I didn't check your code yet, (maybe share it as a running example on repl.it or google colab, for shorter comparison) - I would try to check if there's something with the conversion of images using cv2 and .nd2.

the .png files are working fine, apparently

see here





--
You received this message because you are subscribed to a topic in the Google Groups "openpiv-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openpiv-users/RYIrl5fbL-k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openpiv-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openpiv-users/701cf85e-c35c-489a-a0e3-151f6fe36c5fn%40googlegroups.com.

Akash Singh

unread,
Sep 28, 2023, 8:32:35 AM9/28/23
to Alex Liberzon, openpiv-users
Hello Alex,
   Thank you for the response. I will try to put it. I have some questions regarding your code:
1)  The 'v' obtained in the extended_search_area_piv, while plotting the quivers, I usually get fine results by just inverting the axis of my image, the quivers correspond well to the actual motion in the image. Did not need to apply negative v or transformation to the coordinates. Does it work similarly for functions in windef.py?
2) I am sorry maybe I missed out on it but in your notebook 'test20_multipass.ipynb', you seem to have used again extended_search_area_piv. I was talking about more issues with the simple_multipass function in windef(and even windef.py I ran it as well).

I have attached the link to the Google Collab below. Thanks a lot for your help again!


Best wishes,
Akash

Alex Liberzon

unread,
Sep 28, 2023, 3:55:53 PM9/28/23
to Akash Singh, openpiv-users
You're right, I added test20_windef.ipynb

you're right that at some point the vectors are shown wrong way - but these are just intermediate steps - eventually windef stores the data correctly.

Akash Singh

unread,
Sep 29, 2023, 8:15:13 AM9/29/23
to Alex Liberzon, openpiv-users
Thanks Alex, 
Indeed it seems to be the case. In other cases, If I transpose the v component, it gives the right orientation. 

Best,
Akash

Akash Singh

unread,
Oct 11, 2023, 10:21:39 AM10/11/23
to Alex Liberzon, openpiv-users
Hello Alex,
  The exact bug is in the sign of the v component and the y array output of the simple_multipass. The correction is v= -v and y = y[::-1, :]  i.e. the outer axis of y needs to be inversed. 

Thanks a lot for all the inputs. 

Best regards,
Akash

Alex Liberzon

unread,
Oct 11, 2023, 11:37:07 AM10/11/23
to Akash Singh, openpiv-users
Please raise an issue in github. There’s a function that takes care of this at the end of windef and we need to copy it to simple_multipass


From: Akash Singh <akash...@gmail.com>
Sent: Wednesday, October 11, 2023 5:21:24 PM
To: Alex Liberzon <alex.l...@gmail.com>
Cc: openpiv-users <openpi...@googlegroups.com>
Subject: Re: [openpiv-users] Re: OpenPIV simple Multipass
 
Reply all
Reply to author
Forward
0 new messages