Velocity field from GUI and SCRIPT not the same.

37 views
Skip to first unread message

Jonathan S.

unread,
Sep 19, 2025, 12:08:12 PMSep 19
to PIVlab
Dear Community,
on my dataset, I executed PIVlab via graphical user interface (GUI) and via matlab script. I compared the two velocity fields and found that they are close, but not quite the same. 
The GUI analysis seems more accurate. I chose each parameter I could choose in the script to match what I was entering in the GUI. You can find the settings and the 2 frames attached to this post. I was wondering why they differ, and thinking that they are more settings you could select/unselect in the GUI, which are not available in the script. I would like to have the same accuracy by just executing the script. I appreciate your help.
Best wishes,
Jonathan


Jonathan S.

unread,
Sep 19, 2025, 12:09:13 PMSep 19
to PIVlab
frame0030.tif

Jonathan S.

unread,
Sep 19, 2025, 12:09:45 PMSep 19
to PIVlab
Jonathan S. schrieb am Freitag, 19. September 2025 um 18:09:13 UTC+2:
frame0031.tif
settings.txt

Jonathan S.

unread,
Sep 19, 2025, 12:10:16 PMSep 19
to PIVlab
Sorry, it was not possible to post all files in one message.

William

unread,
Sep 20, 2025, 9:30:54 AMSep 20
to PIVlab
Could you post an image of both results, so we can see how different they are?
Message has been deleted
Message has been deleted

Jonathan S.

unread,
Sep 22, 2025, 4:04:35 AMSep 22
to PIVlab
This is the code for the PIV analysis. I am plotting the original vectors


%preprocess images
image1_uint16 = uint16(65535 * mat2gray(image1));
image2_uint16 = uint16(65535 * mat2gray(image2));
image1_pre = preproc.PIVlab_preproc (image1_uint16,...
preprocess_setting{1,2},...
preprocess_setting{2,2},...
preprocess_setting{3,2},...
preprocess_setting{4,2},...
preprocess_setting{5,2},...
preprocess_setting{6,2},...
preprocess_setting{7,2},...
preprocess_setting{8,2},...
preprocess_setting{9,2},...
preprocess_setting{10,2});
image2_pre = preproc.PIVlab_preproc (image2_uint16,...
preprocess_setting{1,2},...
preprocess_setting{2,2},...
preprocess_setting{3,2},...
preprocess_setting{4,2},...
preprocess_setting{5,2},...
preprocess_setting{6,2},...
preprocess_setting{7,2},...
preprocess_setting{8,2},...
preprocess_setting{9,2},...
preprocess_setting{10,2});
% Perform PIV analysis using the preprocessed images
[x, y, u, v, typevec,corr_map,~] = piv.piv_FFTmulti(image1_pre,image2_pre,... % typevec tells us for the calculation stage the status of the vector. 0 valid, 1 excluded by std test, 2 by median test, 3 interpolated bc of missing data
piv_setting{1,2},...
piv_setting{2,2},...
piv_setting{3,2},...
piv_setting{4,2},...
piv_setting{5,2},...
piv_setting{6,2},...
piv_setting{7,2},...
piv_setting{8,2},...
piv_setting{9,2},...
piv_setting{10,2},...
piv_setting{11,2},...
piv_setting{12,2},...
piv_setting{13,2},0,...
piv_setting{14,2},...
piv_setting{15,2}); %actual PIV analysis
% Postprocessing
[u_filt,v_filt] = postproc.PIVlab_postproc(u,v, ...
posprocess_setting{1,2},...
posprocess_setting{2,2},...
posprocess_setting{3,2},...
posprocess_setting{4,2},...
posprocess_setting{5,2},...
posprocess_setting{6,2},...
posprocess_setting{7,2});
% typevec is not refreshed in the postprocessing stage, so we do it manually.
% Vectors filtered by postprocessing are overwritten with NaN.
typevec_filt = typevec; % initiate
typevec_filt(isnan(u_filt))=2; % overwrite all newly filtered values (now Nan) with 2, although they could also be excluded due to reason 1
typevec_filt(isnan(v_filt))=2;
% typevec_filt(typevec==0)=0; % amin wanted this for some mask... but this will be confusing, because all the vectors which have been excluded in postprocessing will now be marked as normal
% interpolate missing data
if posprocess_setting{8,2}
mask_interp = isnan(u_filt) | isnan(v_filt); % places that were NaN before inpainting
u_filt=misc.inpaint_nans(u_filt,4);
v_filt=misc.inpaint_nans(v_filt,4);
typevec_filt(mask_interp) = 3; % mark as interpolated
end


Jonathan S. schrieb am Montag, 22. September 2025 um 09:30:25 UTC+2:
gui.pngscript.png

Jonathan S.

unread,
Sep 22, 2025, 4:58:06 AMSep 22
to PIVlab
These are the two velocity fields, automatic scaling off. For later frames with worse contrast both algorithms perform way more differently.

William schrieb am Samstag, 20. September 2025 um 15:30:54 UTC+2:
gui.png
script.png

William

unread,
Sep 22, 2025, 4:39:36 PMSep 22
to PIVlab
Hi, I would say that you're mainly seeing random noise. Your interrogation area is way too small, and the images have a pretty bad S2N. Subtle changes in image intensity may lead to different results here (e.g. mat2gray might have an effect, or the auto contrast stretch in the GUI).

I would recommend settings like in the attached image.


Screenshot 2025-09-22 223859.jpg

Jonathan S.

unread,
Sep 23, 2025, 4:37:04 AMSep 23
to PIVlab
Thanks a lot William. I really appreciate your help. It is amazing for an open source software that you are there to help us out. PIVlab helped me a lot in my research. Have a wonderful day!
Best
Jonathan

Jonathan S.

unread,
Sep 23, 2025, 5:14:07 AMSep 23
to PIVlab
I just wanted to add:
With your proposed more coarse grid the two methods look much more similar, especially for high-contrast frames in the beginning. However, the GUI still seems to perform better, especially concerning postprocessing. Some low contrast frames have extrem velocity vectors that the script-based version does not filter out very well.
Reply all
Reply to author
Forward
0 new messages