Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Image mask in C#

Solved!
Go to solution

Hi,

 

I have problem on doing "Image Mask" in C#. 

 

I've tried to operate "Image Mask From ROI" in NI Vison Assistant and create the C code.

In C code, it uses "imaqROIToMask()";

                             "imaqMask();"

                             "imaqGetROIBoundingBox();"

I do find similar functions using "NationalInstruments.CWIMAQControls.AxCWIMAQVision" control.

Such like:  axCWIMAQVision1.RegionsToMask();

                  axCWIMAQVision1.MaskToRegions();

                  axCWIMAQVision1.Mask();

 

First, i dont know exactly which function(s) do the "extract_mask_image" thing.

Second, when i use  "axCWIMAQVision1.RegionsToMask( , ,  object modelImage, object fillvalue );", I dont have any idea how i assing the last two parameters and what are they?

 

thanks for the time.

 

 

 

                            


 

0 Kudos
Message 1 of 6
(7,836 Views)

Hi,

 

did you already look at the Visual Basic example when creation the image mask. It is located under <National Instruments>\Vision\Examples\MSVB.NET\2. Functions\Image Management -> Mask.sln. The C# function call should be similar to VB.

 

You can find further information on using NI Vision for Visual Studio in "START > Programs > National instruments > Vision Assistant 8.6 > Readme" and in the VDM_VB_User_Manual in "START > Programs > National instruments > Vision > Documentation > NI-Vision"

 

To answer your question  about the ROIToMask parameters I attached an except from the "NI Vision for LabWindows/CVI Help" (NIVisionCVI.chm from the above directory):

 

imaqROIToMask

Usage

int imaqROIToMask(Image* mask, const ROI* roi, int fillValue, const Image* imageModel, int* inSpace);

Purpose

Transforms a region of interest (ROI) into a mask image.

Image Types Supported

IMAQ_IMAGE_U8

Parameters

Name

Type

Description

mask Image* The resulting mask image.
roi const ROI* The descriptor defining the ROI.
fillValue int The pixel value of the mask. All pixels inside the ROI receive this value.
imageModel const Image* An optional template for the destination mask image. This parameter can be any image type that NI Vision supports. If you supply an imageModel, the mask image is the size of the model. If you set imageModel to NULL, the size of mask is equal to the size of the bounding rectangle of the ROI, which reduces the amount of memory used. The function sets the offset of the mask image to reflect the real position of the ROI.
inSpace int* If you used imageModel, this parameter indicates on return whether the mask is a true representation of the ROI. If TRUE, the ROI data is completely within imageModel. If FALSE, some of the ROI data fell outside the space associated with imageModel. Set this parameter to NULL if you do not need this information, or if you did not use imageModel.

Return Value

Type

Description

int On success, this function returns a non-zero value. On failure, this function returns 0. To get extended error information, call imaqGetLastError().

 

Let me know if you need further assistance.

 

Andreas 

Andreas Stark
LabVIEW Lead @ Rocket Factory Augsburg
0 Kudos
Message 2 of 6
(7,812 Views)

Hi 0049,

     please specify exactly what do you seek to do using mask?

Waleed El-Badry MSc.,MCPD, ISTQB Certified Tester
Assistant Lecturer
Mechatronics Department
Faculty of Engineering
Misr University for Science & Technology



View Waleed El-Badry's profile on LinkedIn

0 Kudos
Message 3 of 6
(7,801 Views)

Thanks for the info.

 

What I want to do is:

1. load a picture from my hard disc.

2. cut a rectangle area to another image.(mask)

3. image processing.(pattern recognise)

 

The rectangle area is my input parameter. How can I set the parameters to use "CWIMAQVision1.Mask();" or 

"CWIMAQVision1.RegionsToMask();".

0 Kudos
Message 4 of 6
(7,789 Views)
Solution
Accepted by 0049

Have you looked at the example Mask.sln I mentioned above? Its a VB example, but the syntax should be very similar to C#. In this example a image is loaded an then a mask is used to define the region of  interest. For further information please refer to this developer zone article: http://zone.ni.com/devzone/cda/tut/p/id/3616

 

Below the excerpt from the CVI help where the parameters are described: 

 

imaqMask

Usage

int imaqMask(Image* dest, const Image* source, const Image* mask);

Purpose

Copies the source image to the destination image in the following manner: If a pixel in the mask has a value of 0, the function sets the corresponding source pixel to 0. Otherwise, the function copies the corresponding source pixel to the destination image.

Image Types Supported

IMAQ_IMAGE_U8, IMAQ_IMAGE_I16, IMAQ_IMAGE_SGL, IMAQ_IMAGE_COMPLEX, IMAQ_IMAGE_RGB, IMAQ_IMAGE_HSL

Parameters

Name

Type

Description

dest Image* The destination image.
source const Image* The source image.
mask const Image* The mask image. This image must be an IMAQ_IMAGE_U8 image.

Return Value

Type

Description

int On success, this function returns a non-zero value. On failure, this function returns 0. To get extended error information, call imaqGetLastError().

 

 

 

 

 

Andreas Stark
LabVIEW Lead @ Rocket Factory Augsburg
0 Kudos
Message 5 of 6
(7,765 Views)

Thanks everybody.

 

I got the solution.

0 Kudos
Message 6 of 6
(7,756 Views)