![]() |
IPSDK
4_1_0_2
IPSDK : Image Processing Software Development Kit
|
module demonstrating shape analysis and measurement in 2d case More...
module demonstrating shape analysis and measurement in 2d case
This application computes measurements on 2d shapes from an input image TIFF files cupple (a grey level and a binary image).
The application can be called through a command line as follows:
<application_exe_filename> [--inputGreyImgPath <input_grey_image_file_path>] [--inputBinImgPath <input_binary_image_file_path>] [--outputXmlResultPath <output xml result path>]
Arguments:
--inputGreyImgPath optional; specifies the name of the TIFF file, from
which the input grey level image will be loaded; if not
specified by the user, the input image is loaded from
file
<DEV_ROOT>/data/Sample/images/blobs_483x348_UInt8.tif
--inputBinImgPath optional; specifies the name of the TIFF file, from
which the input binary image will be loaded; if not
specified by the user, the input image is loaded from
file
<DEV_ROOT>/data/Sample/images/blobs_483x348_Binary.tif
--outputXmlResultPath optional; specifies the name of the XML file, in
which the output analysis results will be saved; if not
specified by the user, the output results file is saved to
file
<TEMPORARY_IPSDK_DIR>/Sample/shapeAnalysis2d.xmlHere is a snapshot of default input images used by the application and of corresponding output results when application is launched without any argument:
We start by including all the necessary header files:
In the main function body, we start by asking to display all the log messages generated by IPSDK libraries and by our application itself to the application console:
Next, we initialize the IPSDK environment by invoking "ipsdk::core::LibraryInitializer::getInstance().init()". This method must be called before using any entity or function of IPSDK libraries. It returns an object of type ipsdk::core::LibInitResult, that tells us whether the initialization was OK or not. If the initialization failed (because the IPSDK license file was not found, for instance), we notify the user with an appropriate log message, and we close the application.
We then initialize input paths through the call of the "readCmdArguments" function. As its name suggests, it parses the command line to initialize the input and output images files paths, depending on the options specified by the user. The definition of this function is not explained here, because it mainly uses boost functions, and no IPSDK code.
Once the IPSDK environment correctly initialized, we load our input images from the associated TIFF file.
We then apply a connected components algorithm on input binary image (see Connected Component 2d).
A contour based version of this 'labeled' image is then processed. The user should note that a polygonal approximation of contours is processed during previous step (see Label shape extraction 2d).
At last we define a collection of measures to be processed and we launch the shape analysis (see Shape Analysis 2d).
Measure results can then be individually extracted from returned object MeasureSetPtr pOutMeasureSet as demonstrated by following code (extracted type must match measure results type, see measure result type associated to Area2d for example) :
Measure results can also be saved to file using XML file format (for example) using following code :
The final action consists in cleaning the IPSDK environment before exiting. This cleaning operation (call to "ipsdk::core::LibraryInitializer::getInstance().clear()") must be the last call to IPSDK environment. It guarantees in particular that all threads created by IPSDK libraries are complete.
See the full source listing
1.8.14