multiple mask

40 views
Skip to first unread message

joel.tor...@gmail.com

unread,
Nov 29, 2018, 6:30:58 AM11/29/18
to PIVlab

Hi,

First of all, thanks a lot for your work! I have been using PIVlab for a while now and I recently updated to version 2.0. I use your software to process videos of granular column collapse tests. Therefore I need to adapt the masked region to my ROI as the analysis progresses. I used to be able to load external masks (last version I was working with was 1.43) as a *.MAT file containing 'xmask' and 'ymask' variables with as many masks as frame pairs, which when loaded applied automatically to all the frames. Now, with the new mask capabilities, I don't know how to load my masks: I have tried putting all the binary images into a *.TIFF file but only the first one is loaded for all frames, and I'd rather not apply each one of my masks manually on the frame pairs.

Any suggestions?


William Thielicke

unread,
Nov 29, 2018, 8:06:19 AM11/29/18
to PIVlab
Hi, I changed the "external mask" functionality in the last release, sorry... You are right that it would make a lot of sense to be able to load a series of TIF images.
I will note this down and implement it in the next release. Until then, the only possibility for you is to use an old PIVlab version...

joel.tor...@gmail.com

unread,
Nov 29, 2018, 12:31:12 PM11/29/18
to PIVlab
Hello again William,

Thank you for your quick reply. I'll be waiting for the next version release! In the meantime, I think I've found a workaround that does the job for me: adapting from older versions, I've just replaced the definition of function 'external_mask_Callback' in 'PIVlab_GUI.m' with this:

%%
function external_mask_Callback(~, ~, ~)
uiwait(helpdlg(['You can load a grayscale *.tif image here:' sprintf('\n') 'White = masked, black = no mask.']));

filepath=retr('filepath');
handles=gethand;
if size(filepath,1) > 1
[FileName,PathName] = uigetfile('*.tif','Select the binary image mask file');
if isequal(FileName,0) | isequal(PathName,0)
    else
        filename = fullfile(PathName,FileName);
        num_img = length(imfinfo(filename));
        for i = 1:num_img
            A = bwboundaries(imread(filename,i));
            for j = 1:length(A)
                maskiererx{j,2*i-1} = A{j}(:,2);
                maskiererx{j,2*i}   = A{j}(:,2);
                maskierery{j,2*i-1} = A{j}(:,1);
                maskierery{j,2*i}   = A{j}(:,1);
            end
        end
put('maskiererx' ,maskiererx);
put('maskierery' ,maskierery);
set(handles.mask_hint, 'String', 'Mask active', 'backgroundcolor', [0.5 1 0.5]);
dispMASK(0.333)
end
end
%%

Bastian Eysel

unread,
Mar 6, 2019, 6:29:23 AM3/6/19
to PIVlab
Hello, 

i'm struggling with a similar problem at the moment. For a video analysis i created multiple external masks for each frame in PIVlab. It works fine in the GUI with the new update but since i'm handling quite a lot of frames i would like to start the analysis via the command line. So my question is, how can i implement multiple masks in my own command line?

William Thielicke

unread,
Mar 6, 2019, 2:29:03 PM3/6/19
to PIVlab
Hi,
I think it should work like this, but I didn't test:

commandline_Mask is the mask that you provide to the commandline script.
PIVlab_mask.mat is a mask saved from the PIVlab GUI.

load('C:\Users\trash\Desktop\PIVlab_mask.mat');
commandline_Mask{:,1}=maskiererx{:,1}
commandline_Mask{:,2}=maskierery{:,1}

Bastian Eysel

unread,
Mar 7, 2019, 10:28:35 AM3/7/19
to PIVlab
Hey William, 

sorry to bother you again. I couldn't make it work. Since you posted that PIVlab_mask.mat is a masked saved by the PIVlab GUI i'm suspecting you thought i'm saving my Masks with the GUI first. At the moment im just using the GUI to evaluate my setup. I'm working with a highspeed camera so it's my aim to create a fully automated code. I wrote an algorithm that creates my masks. Now i want to use these .tif files as masks for the corresponding framepair. Shall i save the information of these Masks as a PIVlab_mask.mat (with the same size as u,v etc.) now? If so, how do i load them in the commandline (line 19)?  Furthermore i couldn't find commandline_Mask.m should there be one?

William Thielicke

unread,
Mar 7, 2019, 2:05:11 PM3/7/19
to PIVlab
Hi,
in your case, I would recommend to change my code a little bit. 
PIVlab is using polygons as masks, because they consume much less space. But what actually happens is the following: If you load a TIF mask in PIVlab, then it will be converted to a polygon. This polygon will be forwarded to the actual PIV algorithm. In the PIV algorithm, the polygon will be converted back to a pixel image. So for you it would be best to skip the whole polygon cenversion path and work with pixel data right from the start.
If you open piv_FFTmulti.m and go to line 27, then there is this line of code:
        mask = mask + poly2mask(masklayerx-xroi,masklayery-yroi,size(image1_roi,1),size(image1_roi,2)); %kleineres eingangsbild und maske geshiftet

This is where the polygon i converted to a pixel image.
I would recommend to remove this whole section from the code:
 
if numel(mask_inpt)>0
    cellmask=mask_inpt;
    mask=zeros(size(image1_roi));
    for i=1:size(cellmask,1);
        masklayerx=cellmask{i,1};
        masklayery=cellmask{i,2};
        mask = mask + poly2mask(masklayerx-xroi,masklayery-yroi,size(image1_roi,1),size(image1_roi,2)); %kleineres eingangsbild und maske geshiftet
    end
else
    mask=zeros(size(image1_roi));
end
 
When your automated script calls the piv_FFTmulti.m function, you can directly supply your pixel image as mask argument. But you need to convert it to a a binary image, e.g. by using
BW = im2bw(I,level)
Please do not use a ROI when calling piv_FFTmulti, otherwise things become a bit more complicated. 

lucas...@gmail.com

unread,
Apr 17, 2019, 1:01:39 PM4/17/19
to PIVlab
Hi William

What do you mean when you say "Please do not use a ROI when calling piv_FFTmulti, otherwise things become a bit more complicated."?

I need to use a ROI and a mask and I like to do it in the way that you suggested in this topic since it fits my needs (batch processing with different masks). If using a ROI may complicate things, perhaps I can crop the images and the masks in order to keep only the ROI (batch cropping would be easy since I'm working from the command line) and use the cropped images & masks when calling piv_FFTmulti...? (in that case of course there won't be a ROI input argument to the piv_FFTmulti function).

William Thielicke

unread,
Apr 18, 2019, 3:34:42 AM4/18/19
to PIVlab
Hi, I currently can't check the code, but as far as I remember, the ROI is processed in a different part of the code. So if you remove the lines that convert a poly to a BW image, then things might go wrong. But you can try, maybe it works.
Otherwise it is indeed a good idea to crop the images before analysis and skip the ROI input.
Reply all
Reply to author
Forward
0 new messages