Creat Region of Interest mask in IMAQ image

Wednesday, May 2nd, 2012

I have been working on using a USB webcam as a research tool to observe the heart beat of a Daphina (water flea) these days. Since LabVIEW 2009 IMAQdx is available for 3rd party USB cameras, no extra USB driver is required. So I used the old but classic webcam Philips SPC 900NC to build a Daphnia observation system. I may talk more about this later.

To cut a long story short, I tried to process only the Region of Interest (ROI) of the grabbed image rather than the whole one. This can make the analysis easier. Since this USB webcam does not support ROI imaging, we cannot set XY pixels on it.   I tried to google the solution and found creating a mask or, a pseudo ROI, can block the unwanted image. I programmed an example for blocking the unwanted image by selecting ROI on the image:

For some unknown reason I cannot create snippet from this VI, so I save the screenshot instead.
In this example three memories were created to store the original image, the mask and the modified image. If an ROI is selected (FALSE case), firstly convert the ROI info to a mask, and then mask the source image with the mask image. If no ROI is selected (TRUE case), the destination image is linked to the source image.

Note that:1. The property node “ROI” is created by right clicking the “image” indicator in the block diagram and selecting “Create>Property Node>ROI”.
2. The image type of the “Mask” must be Grayscale U8. The original and the changed images can be any image type.
3. It is masking the image rather than ROI imaging. So it will NOT increase the frame rate nor decrease the image size. All black regions are filled with 255 by default.

Hope this example can be helpful. Let me know if you have any problem or are interested in controlling conventional USB webcams with LabVIEW IMAQdx.

8 comments on “Creat Region of Interest mask in IMAQ image

  1. John Wu says:

    Hi I’ve got a suggestion for you, IMAQ programs can be a little hard to write from scratch at first, usually what I do is just write a simple script in Vision Assistant, then convert that script into LabVIEW code. Or if you’re not interested in the code and just want the function the work, you can add a Vision Assistant Express VI to your code. Cheers.

    • foolooo says:

      Hi John, Thanks for the suggestion. Yes the Vision Assistant looks much more straightforward to hand on. I started from some example usually but I will try this idea next time. Cheers.

  2. Birgit says:

    Another suggestion: Use IMAQ Extract in the end to crop the image (depending on the shape of your ROI, use a global rectangle or tetragon) – that way you only apply the algorithm to smaller parts. Sure, extraction/masking takes time, but for computationally expensive algorithms it helps.
    IMAQ Dispose has a (True) if you want to dispose of all pics (in the very end), but you need to be careful with that one.
    Grayscale U8 is the standard type for Imaq create. You don’t need to wire it.
    I don’t quite get the loop , but you’re probably using it for some algorithm. I would use shift registers for the errors/merge them earlier for better readability.

    Greetings from someone who does this kind of stuff for a living (and I’m also interested in cheap/open source cameras), I’ll RSS your blog/feel free to mail me..;-),

    • foolooo says:

      Thanks for your suggestion, Birgit. The loop was used to test if I can select ROI on the front panel and transform it to a cropped picture. Agree with all your words. Cheers.

  3. Shubham sharma says:

    Hey there, I am working on a project where I need to find the pulp area of second premolar from X-ray images, I have different x-ray images and therefore I want to have a varying region of Interest. How can I build a program/template to find the area of second premolar?

    • Bo Fu says:

      Hi Shubham,

      So do you want to manually select the regions of interest (ROI) or do it automatically? LabVIEW IMAQ module allows you to manually select the ROI by using the mouse to click and drag. If it is the first case, try to copy my code in this post and see if it works.

      But if you want the computer to select it for you then it is more on Machine Vision. You need to “train” your computer the right pattern and then it can look for the right region. The second way will be much more complicated.

      Let me know if more question.


  4. ansu says:

    how to crop a rectangular regio from an image using vision assistant

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: