![]() |
IPSDK
4_1_0_2
IPSDK : Image Processing Software Development Kit
|
module demonstrating the computation of boundary on a 2d binary image More...
module demonstrating the computation of boundary on a 2d binary image
This application computes the boundary image on a 2d binary input image loaded from a given input RAW file, and saves the result in a given RAW file.
The application can be called through a command line as follows:
<application_exe_filename> [--inputImgFilePath <input_image_file_path>] [--outputImgFilePath <output_image_file_path>]
Arguments:
--inputImgFilePath optional; specifies the name of the RAW file, from
which the 2d binary input image will be loaded; if not
specified by the user, the input image is loaded from
file
<DEV_ROOT>/data/Sample/images/MorphoBin2d1.raw
--outputImgFilePath optional; specifies the name of the RAW file, in
which the 2d output image resulting from the
boundary extraction will be saved;
if not specified by the user, the output image is
saved in file
<TEMPORARY_IPSDK_DIR>/Sample/boundary.raw
--imgXSz mandatory if inputImgFilePath option is specified,
ignored otherwise; specifies the width of input image
--imgYSz mandatory if inputImgFilePath option is specified,
ignored otherwise; specifies the height of input imageHere is a snapshot of default input image used by the application and of corresponding output image when application is launched without any argument:
The sequence of operations executed by this application is very similar to other samples. However, we can notice in particular that, this time, instead of using TIFF file format to load/save images, we use RAW file format.
We start by including all 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:
Then we declare objects 'inImgFilePath' and 'outImgFilePath'.
We also declare the variables that will store the dimensions of input image:
Paths and image dimensions are initialized from the command line thanks to the call of the "readCmdArguments" function:
Once the IPSDK environment is correctly initialized, we load our input image from the associated RAW file, by calling the function ipsdk::image::file::loadRawImageFile. Contrary to other image file formats such as TIFF, RAW files don't contain neither image dimensions information, nor number of channels or pixel data type. That's why "loadRawImageFile" function takes one more argument compared to a function such as "loadTiffImageFile": the geometry of the image. This geometry is represented with the type BaseImageGeometry, and is initialized here with the function geometry2d, that takes 3 arguments: the pixel data type, and the width and the height of the image.
The call of "loadRawImageFile is enclosed in a try/catch block, to handle the case where an exception is thrown by loadRawImageFile (if the file is not found or corrupted, for instance). If an error occurs, a message is displayed to the user, IPSDK environment is cleaned by calling "ipsdk::core::LibraryInitializer::getInstance().clear()" and the application terminates.
We can now apply the "boundary" operation on our freshly loaded input image, by calling "ipsdk::imaproc::morpho::boundary2dImg". This function takes our object pInImg, and returns the resulting image in an object of type ImagePtr, that we store in our variable pOutImg.
Once again, the call of "boundary2dImg" function is enclosed in a try/catch block to handle any failure during this operation. If the operation fails, we notify the user and clean IPSDK environment before exiting.
If all the previous operations were successfully completed, we save the image resulting from the "boundary" operation to the RAW file specified by the user (or to a default RAW file, if the user did not specify anything), by calling the function "saveRawImageFile".
Finally, the program cleans the IPSDK environment and exitings:
See the full source listing
1.8.14