Tracing the displacement of a certain point in a list of images:

37 views
Skip to first unread message

Wenyue ZHANG

unread,
Nov 11, 2024, 4:00:05 AM11/11/24
to openpiv-users
Dear PIV community,

I am trying to trace the displacement of a certain point in a list of images (from a vedio).

First, I refer to the example provided in notebooks:
Since the velocity (displacement) field generated by OpenPIV is in Eulerian specification,
I cannot simply conduct "Umean = np.sum(U, axis=0)" for the results in time sequence.
What I can do is to conduct time integration using Finite Difference Methods.
Two concerns on this process are included:
1. Spatial interpolation needs to be conducted by me;
2. Random walk errors accumulates in the process.

According to some previous theads:
it seems that winde.py can realize the demand.

I had some trials on the given examples, which works on two images:
They works well, so I have a trial on a list of images.

My codes are as follow:
========================
# import packages
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 matplotlib.pyplot as plt

#Set up all the settings
settings = windef.PIVSettings()

path = pathlib.Path('.../test/multi-grid')

'Data related settings'
# Folder with the images to process
settings.filepath_images = path / 'input'  # type: ignore
# Folder for the outputs
settings.save_path = path / 'output'  # type: ignore
# Root name of the output Folder for Result Files
settings.save_folder_suffix = 'Test'
# Format and Image Sequence (see below for more options)
settings.frame_pattern_a = 'IMG_010*.jpg'
settings.frame_pattern_b = '(1+2),(2+3)'

'Region of interest'
# (50,300,50,300) #Region of interest: (xmin,xmax,ymin,ymax) or 'full' for full image
settings.roi = (500,2000,625,1200)

'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.deformation_method = 'symmetric'

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

settings.num_iterations = 2  # 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, 32, 16) # if longer than n iteration the rest is ignored
# The overlap of the interroagtion window for each pass.
settings.overlap = (32, 16, 8) # 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 = 20  # scaling factor pixel/meter
settings.dt = 1  # time between to 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 = 4
settings.filter_kernel_size = 2  # kernel size for the localmean method
'Output options'
# Select if you want to save the plotted vectorfield: True or False
settings.save_plot = False
# Choose wether you want to see the vectorfield or not :True or False
settings.show_plot = True
settings.scale_plot = 25  # select a value to scale the quiver plot of the vectorfield
# run the script with the given settings

windef.piv(settings)
========================

Sadly, the code doesn't work, reporting "Something happened in the validation".
I had a trial on the first two figures, by only replacing the following part:
========================
settings.frame_pattern_a = 'IMG_0100.jpg'
settings.frame_pattern_a = 'IMG_0101.jpg'
========================
It failed, reporting "index 0 is out of bounds for axis 0 with size 0".
When I tried:
========================
settings.roi = 'full'
========================
it fialed reprting "operands could not be broadcast together with shapes (4725,64,33) (140,64,33) "

I had a trial with the images in the provided tutourials (images are downloaded to the same local folder),
by only replacing the following parts:
========================
settings.frame_pattern_a = 'exp1_001_a.bmp' settings.frame_pattern_b = 'exp1_001_b.bmp'settings.roi = 'full'
========================
or
========================
settings.frame_pattern_a = 't_23.png' settings.frame_pattern_b = 't_24.png' settings.roi = 'full'
========================
both works well.

I am confused whether the windef.py has a problem on the input file type.
In addition, I cannot find an example for the windef dealing with a list of images.
I wonder whether such an example is available.

Best regards,
Wenyue Zhang

Alex Liberzon

unread,
Nov 11, 2024, 11:33:30 AM11/11/24
to openpiv-users
maybe you want to use OpenPTV? this's another project that does that - follows the particles in the flow. 

OpenPIV is to follow the flow or estimate the field. I do not understand how windef can do what you ask for - after all it will be always an Eulerian point. What is possible is to use OpenPIV first, then create flow fields and use some other tool to interpolate through the field using the point position (by some image processing) and then creating the particle velocity as an interpolation from field velocity. 

for some reason I cannot reach your test images in the drive, something about access. 

Wenyue ZHANG

unread,
Nov 12, 2024, 4:08:26 AM11/12/24
to openpiv-users
Thanks for the reply.

The reason I am estimating displacement of a particle using OpenPIV includes:
1. I am calibrating a PIV system, including the camera and the software. To ensure that the sytem really reflects the phenomena in the physical world correctly, I want to compare the result, by simply measuring the displacement of a targeted point.
2. When conducting physical modeling for geotechnial phenomena, we want to generate the strain field of the ground.

These demands may be out of the interest of OpenPIV community, so I will try to do the spatial interpolation from the flow field by myself.

However, I am still interested in the windef.py, which enhences the effeciency when dealing with a list of images.
It would be helpful if someone can confirm whether the windef.py doesn't work for certian files.
Sorry for my mistake, the photos can now be accessed through the follwing link:

Best regards,
Wenyue Zhang

2024年11月12日火曜日 1:33:30 UTC+9 alex.l...@gmail.com:

Ivan Nepomnyashchikh

unread,
Nov 12, 2024, 12:31:04 PM11/12/24
to openpiv-users
Having a brief look at your images, I would say PIV might work.
Firtst, cut off the top of the image. Second, invert it and gray-scale it (background must be black, particles must be white).
Third, I suspect you use those black large dots closer to the bottom of the image to "calibrate" your algorithm, don't you? If so, I think the dots are way too large. Moreover, having larger dots surrounded by the "PIV seeding particles" is not a good idea. All the particles must be of the same size. The size of the particle must be on the order of 2 pixels (not less than 1pix and not larger than 4 pix). Make sure you meet this requirement. You must have on the order of 8 particles per interrogation window. And each of this particles must move about a quarter of the interrogation window size. You must meet these requirements before doing PIV. How do you meet them? Use an image viewing piece of software that allows you to impose a grid on your image. You are working with 3 interrogation window sizes: 64x64 pix, 32x32 pix, 16x16 pix. So, in your software, impose a 64x64 pix grid on your image. Pick any dot in your image. See if it looks to you like it occupies about 2 pixels.Then use the left and right arrows on your keyboard to quickly go between the images. Simultaneously, see with your eyes how far the dot of your choice moves. Does it look to you like it moves 16pix (i.e, a quarter of the interrogation window size)?  Also check if there are 8 dots per interrogation window on average. If all these requirements are met, do the same for 32pix and 16pix interrogation windows. 
Lastly, you are making a mistake using the most advanced algorithm (i.e., the windef algorithm). It is very complex. Start with simple PIV. Have a feeling on how the validation works in simple PIV, how to pick the proper parameters for validation. How to pick proper PIV parameters in general. Once you have that feeling, you can move on to windef. PIV is very sensitive to the parameters. Slight change in parameters can make a huge difference.
Have a look at this google group conversation where I provided an example of the most basic PIV: https://groups.google.com/g/openpiv-users/c/ysUh8YJC_M0/m/t1lPA-O7AgAJ.
Personally, I don't have time right now to make your code work. So, either you do it yourself or Dr. Liberzon finds some time to make your code work.
Ivan

Alex Liberzon

unread,
Nov 12, 2024, 5:33:22 PM11/12/24
to openpiv-users
OpenPIV does not work directly with RGB or other color images. If it reads it, then it converts it under the hood to greyscale and this might not be the right conversion. I think you talk about small dots as PIV trackers and large dark blobs as control points. the large blobs are not recommended to use in OpenPIV - they only "destroy" the displacement field around them. 
Mask those and track them separately. if you want to work only in Python, use trackpy or opencv 
then the masked images can be converted to black and white and uneven illumination needs to be removed. 

Ivan gave here great advice below 

Wenyue ZHANG

unread,
Nov 13, 2024, 12:44:55 AM11/13/24
to openpiv-users
Thanks for your kind reply.

Actually the images are not taken by me but retrieved from the internet.
I am still trying to get famimilar with the OpenPIV codes.

Two kinds of seeding particles with different sizes, along with the not moving control points (the large black dots), make the analysis not easy.
By following the basic tutourials, I had attained "somehow plausible results", but still with some strange vectors occurring localling.
I will try to improve the results, following your valuable suggestions.

Best regards,
Wenyue Zhang
2024年11月13日水曜日 2:31:04 UTC+9 nepo...@oregonstate.edu:

Wenyue ZHANG

unread,
Nov 13, 2024, 12:49:49 AM11/13/24
to openpiv-users
Thanks for the reply from Alex.

Actually I had realized the problems introduced by the large blobs,
so I was trying to remove them using masking, which is related to the previous question I raised'

I think I will go back to simple PIV instead of windef, following the valuable suggestions from Ivan.

Best regards 
2024年11月13日水曜日 7:33:22 UTC+9 alex.l...@gmail.com:

Alex Liberzon

unread,
Nov 13, 2024, 1:05:18 AM11/13/24
to Wenyue ZHANG, openpiv-users
OpenPIV is designed to deal with PIV-like images. As it was mentioned above, the images you found on the internet are not so much for OpenPIV. There was a branch of OpenPIV  developed for geotechnical problems, try to find it - I believe they adjusted what's needed for this application. I think in this group we once mentioned it. 

Alex


--
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/UmhDdn3e3D0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openpiv-user...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/openpiv-users/fdb9432c-67cc-47c6-bcb7-ba216935657an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages