Making a mask using a binary image.

classic Classic list List threaded Threaded
9 messages Options
Taeyang Han Taeyang Han
Reply | Threaded
Open this post in threaded view
|

Making a mask using a binary image.

Hi William! Thank you for your effort for PIVlab.
It gives me a great chance to start a research using PIV.

Now I try to analyze two-phase flow (liquid-vapor) by PIV.
As you know when I want to get the liquid velocity in two-phase flow, bubble could be a noise.
So I want to make bubble area into a mask.
I got a binary image of the bubble by MATLAB, but I couldn’t apply the binary image as a mask.
Could you give me an advise for it?
William William
Reply | Threaded
Open this post in threaded view
|

Re: Making a mask using a binary image.

Hi,
If you click on "load mask", then a window should pop up that gives you information on how to setup your binary mask. That should help.

Please consider donating for the PIVlab project:
http://paypal.me/pools/c/81Y8wBVi4y

The developer needs to update to a recent Matlab release in order to keep the project running.

Daniele Daniele
Reply | Threaded
Open this post in threaded view
|

Re: Making a mask using a binary image.

Hi William, PIVlab is a great tool, thanks a lot!
I am having some trouble uploading a mask, every time I upload a mat file nothing happens and no mask appears.
I created a mask by generating a cell variable containing as many columns as images and in each column I placed a matrix with two column, the first is the x and the second is the y coordinates of the polygon I want to mask. Then I saved the variable as a .mat file. Something like this:

[c,x,y]=roipoly(rand(152,231)) % here I choose the polygon
f{1,1}=[x,y];
for i=1:totNumberImages % assuming I want the same mask for all images
f{1,i}=[x,y];
end
save('mask.mat','f')

When I upload mask.mat nothing happens.
Can you give me a suggestion please?
Thanks!
William William
Reply | Threaded
Open this post in threaded view
|

Re: Making a mask using a binary image.

I'll have a look at this tonight.

Please consider donating for the PIVlab project:
http://paypal.me/pools/c/81Y8wBVi4y

The developer needs to update to a recent Matlab release in order to keep the project running.

Daniele Daniele
Reply | Threaded
Open this post in threaded view
|

Re: Making a mask using a binary image.

Thanks William, I solved the previous problem (my mistake, I didn't understand your explanation).

I have another question: how can I create a mask composed of different polygons for each frame?
In my images I have more than one object that I need to mask in each frame and I can recognize them via Matlab so it would be useful to be able to upload my custom masks automatically instead of drawing one by one for 50 frames.

Thanks again.
William William
Reply | Threaded
Open this post in threaded view
|

Re: Making a mask using a binary image.

Hi,
loading multiple mask per frame is not supported (because it makes it even more complicated to generate your own mask outside PIVlab).
But have a look at these lines in pivlab_gui.m:
load (fullfile(PathName,FileName));
        for i=1:size(xmask,2)
            %1   2  3  4
            %12 34 56 78
            maskiererx{1,i*2-1}=xmask(:,i);
            maskiererx{1,i*2}=xmask(:,i);
            maskierery{1,i*2-1}=ymask(:,i);
            maskierery{1,i*2}=ymask(:,i);
        end
        put('maskiererx' ,maskiererx);
        put('maskierery' ,maskierery);
You could modify them to load multiple masks per frame. In order to understand the data structure, I recommend to load some images, draw some masks, save as PIVlab session, and then load this session file in Matlab, and have a look at the variables maskiererx and maskierery. I think it's not really difficult.

Please consider donating for the PIVlab project:
http://paypal.me/pools/c/81Y8wBVi4y

The developer needs to update to a recent Matlab release in order to keep the project running.

Daniele Daniele
Reply | Threaded
Open this post in threaded view
|

Re: Making a mask using a binary image.

Thanks for the suggestion William.
It was easy to implement the possibility to import multiple masks per frame.
If anybody is interested, here's how I changed the part of the code to import external masks.

load (fullfile(PathName,FileName));
        for i=1:size(xmask,2)
            for m=1:size(xmask,1)
            %1   2  3  4
            %12 34 56 78
            maskiererx{m,i*2-1}=xmask{m,i};
            maskiererx{m,i*2}=xmask{m,i};
            maskierery{m,i*2-1}=ymask{m,i};
            maskierery{m,i*2}=ymask{m,i};
            end
        end

You need to upload a .mat file containing xmask and ymask as cell arrays instead of matrix so the columns represent the frames and each row correspond to a different mask for that frame. Easy.
William William
Reply | Threaded
Open this post in threaded view
|

Re: Making a mask using a binary image.

Thanks for reporting your results. I should add an autodetect feature and some example mat files for manual masks.

Please consider donating for the PIVlab project:
http://paypal.me/pools/c/81Y8wBVi4y

The developer needs to update to a recent Matlab release in order to keep the project running.

andrea andrea
Reply | Threaded
Open this post in threaded view
|

Re: Making a mask using a binary image.

In reply to this post by William
Hi William,
I had the same problem with loading an external mask.

I tried with:

xmask=[1;200;200;1]
ymask=[1;1;200;200]
save('mask.mat','xmask','ymask');

but loading the file mask.mat, from PIVlab 'Exclusion (ROI,mask)' window, nothing happen.

Can you please explain me how to do it?

Thank you