Initialize ImageDev
This example shows how to properly initialize and finalize a program with the ImageDev library.
After having initialized ImageDev and controlled the availability of a valid license, this example applies
a simple processing that generates a random image in order to demonstrate that ImageDev is ready to use.
Since ImageDev 2024.1, initialization and finalization are automatically managed in Python. Initialization and finalization are therefore not necessary in Python and are omitted in most of Python examples of this guide. However, an explicit call of these methods may be mandatory in some specific cases. This example shows how to initialize and finalize ImageDev also in Python to address these cases.
See also
Since ImageDev 2024.1, initialization and finalization are automatically managed in Python. Initialization and finalization are therefore not necessary in Python and are omitted in most of Python examples of this guide. However, an explicit call of these methods may be mandatory in some specific cases. This example shows how to initialize and finalize ImageDev also in Python to address these cases.
#include <ImageDev/ImageDev.h>
#include <string.h>
using namespace imagedev;
int
main( int argc, char* argv[] )
{
int status = 0;
try
{
// ImageDev library initialization
if ( imagedev::isInitialized() == false )
imagedev::init();
// Generate a random image
auto imageInput = randomImage2d( RandomImage2d::OutputType::UNSIGNED_INTEGER_8_BIT, 256, 256, 80.0, 10.0 );
std::cout << "This example ran successfully." << std::endl;
}
catch ( const imagedev::Exception& error )
{
// Print potential exception in the standard output
std::cerr << "InitializeImageDev exception: " << error.what() << std::endl;
status = -1;
}
// ImageDev library finalization
imagedev::finish();
// Check if we must ask for an enter key to close the program
if ( !( ( argc == 2 ) && strcmp( argv[1], "--no-stop-at-end" ) == 0 ) )
std::cout << "Press Enter key to close this window." << std::endl, getchar();
return status;
}
using System;
using ImageDev;
using IOLink;
namespace T01_02_InitializeImageDev
{
class Program
{
static void Main( string[] args )
{
int status = 0;
try
{
// Initialize the ImageDev library if not done
if ( Initialization.IsInitialized() == false )
Initialization.Init();
// Generate a random image
ImageView imageInput = Processing.RandomImage2d( RandomImage2d.OutputType.UNSIGNED_INTEGER_8_BIT, 256, 256, 80.0, 10.0 );
}
catch ( Exception error )
{
// Print potential exception in the standard output
System.Console.WriteLine("InitializeImageDev exception: " + error.ToString() );
status = -1;
}
// ImageDev library finalization
Initialization.Finish();
// Check if we must ask for an enter key to close the program
if (!((args.Length >= 1) && (args[0] == "--no-stop-at-end")))
{
System.Console.WriteLine("Press Enter key to close this window.");
System.Console.ReadKey();
}
System.Environment.Exit(status);
}
}
}
import imagedev
try:
# Initialize the ImageDev library if not done
manual_init = False
if (imagedev.is_initialized() == False):
imagedev.init()
manual_init = True
# Generate a random image
imagedev.random_image_2d(imagedev.RandomImage2d.UNSIGNED_INTEGER_8_BIT, 256, 256, 80.0, 10.0)
# ImageDev library finalization if ImageDev has been intialized by the program
if manual_init: imagedev.finish()
except Exception as error:
# Print potential exception in the standard output
print("initialize_imagedev exception: " + str(error)) See also
© 2025 Thermo Fisher Scientific Inc. All rights reserved.