10-29-2008 11:39 AM
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.
Solved! Go to Solution.
10-31-2008 10:38 AM
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
11-02-2008 07:36 AM
11-03-2008 03:07 AM
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();".
11-05-2008 05:59 AM
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().
11-05-2008 08:42 AM
Thanks everybody.
I got the solution.