The IDS peak ICV library provides a flexible, language-independent image model that allows easy image creation, manipulation, and conversion across all supported programming languages. Each language binding offers APIs that integrate naturally with the language environment while maintaining consistency with the core image model.
This guide describes the primary ways to create and work with images using the IDS peak ICV library.
Creating an image
Images can be created in several ways, depending on your data source and application requirements. The following core methods are available in all supported programming languages:
Creating from an IDS peak genericAPI buffer
When an image is captured into a buffer using the IDS peak genericAPI, an ICV image can be created directly from that buffer by constructing an ImageView.
- C++
std::shared_ptr<peak::core::Buffer> buffer = dataStream->WaitForFinishedBuffer(5'000);
peak::core::ImageView imageView = buffer->ToImageView();
- C#
using var buffer = dataStream.WaitForFinishedBuffer(5000);
var imageView = buffer.ToImageView();
using var image = new Image(imageView);
- Python
buffer = data_stream.WaitForFinishedBuffer(ids_peak.Timeout(5000))
image_view = buffer.ToImageView()
image = Image.create_from_image_view(image_view)
Using the image processing pipeline
Use this method when the buffer acquired via the IDS peak genericAPI contains raw camera data that requires processing before it can be used as a ready-to-use image. The Image Processing Pipeline performs essential steps such as debayering, color correction, and format conversion automatically.
This approach can also be used if auto features (e.g., auto exposure, auto gain, or auto white balance) are required.
- C++
std::shared_ptr<peak::core::Buffer> buffer = dataStream->WaitForFinishedBuffer(5'000);
- C#
using var buffer = dataStream.WaitForFinishedBuffer(5000);
using var image = pipeline.Process(buffer.ToImageView());
- Python
pipeline = DefaultPipeline()
buffer = data_stream.WaitForFinishedBuffer(ids_peak.Timeout(5000))
image = pipeline.process(buffer.ToImageView())
Reading from a file
Create an image by loading it from a supported file format.
- C++
- C#
using var image = new Image("beads.png");
- Python
image = Image.create_from_file("beads.png")
From pixel format and size
Create a blank image by specifying the pixel format and the image dimensions (width × height).
- C++
- C#
using var image = new Image(PixelFormat.Mono8, new Size(640, 480));
- Python
image = Image.create_from_pixel_format_and_size(PixelFormat.MONO_8, Size(640, 480))
Creating from a raw buffer
Construct an image directly from a raw byte buffer. The buffer must contain binary image data in a format supported by the IDS peak ICV library.
- C++
std::array<uint8_t, 3> buffer{ 1, 2, 3 };
- C#
var imageBuffer = new byte[]{1, 2, 3};
var bufferPinned = GCHandle.Alloc(imageBuffer, GCHandleType.Pinned);
using var imageFromBuffer = new Image(PixelFormat.Mono8, new Size(3, 1), bufferPinned.AddrOfPinnedObject(), (uint)imageBuffer.Length);
- Python
buffer = np.array([[1, 2, 3]], dtype=PixelFormat.MONO_8.numpy_dtype)
image = Image.create_from_np_array(PixelFormat.MONO_8, Size(3, 1), buffer)
Setting an image region
Each IDS peak ICV image includes a Region, which by default covers the entire image. When no custom region is specified, the entire image is processed. You can define a custom region to process only a specific part of the image.
The region can be of any shape, depending on the use case, and can be set dynamically at runtime.
If you need to revert to processing the entire image, you can reset the region back to its default full image coverage.
Additionally, the current region of an image can be queried programmatically.
- C++
image.SetRegion(region);
auto imageRegion = image.GetRegion();
image.ResetRegion();
- C#
using var regionFromPoints = new Region(new[] { new Point(1, 2), new Point(3, 4) });
image.Region = regionFromPoints;
var region = image.Region;
image.ResetRegion();
- Python
region = Region.create_from_points(np.array([[1, 2], [3, 4]]))
image.region = region
image_region = image.region
image.reset_region()
Handling of pixel formats
Pixel formats define how pixel data is stored and interpreted. The IDS peak ICV library supports various pixel formats which are described in detail in Pixel and Pixel Format Specifications.
Converting an image to a different pixel format
To convert an image from one pixel format to another, use the appropriate conversion functions provided by the library. Check the documentation for each function to verify format compatibility and any conversion limitations.
- C++
- C#
using var convertedImage = image.ConvertPixelFormat(PixelFormat.Mono10);
- Python
image_converted = image.convert_pixel_format(PixelFormat.MONO_10)
Getting detailed information about pixel formats
To correctly interpret pixel data, you can query details such as the format name, the bit depth, and the minimum and maximum possible channel values.
- C++
std::cout << info.GetName() << std::endl;
std::cout << info.GetStorageBitsPerPixel() << std::endl;
std::cout << info.GetMaximumValuePerChannel() << std::endl;
- C#
Console.WriteLine(pixelFormatInfo.Name);
Console.WriteLine(pixelFormatInfo.StorageBitsPerPixel);
Console.WriteLine(pixelFormatInfo.MaximumValuePerChannel());
- Python
pixel_format = PixelFormat.MONO_8
print(pixel_format.name)
print(pixel_format.storage_bits_per_pixel)
print(pixel_format.maximum_value_per_channel)
By using these methods, you obtain the information required to correctly interpret the image data and make informed decisions about image processing and format conversions.
Accessing raw data
If a transfer from IDS peak ICV to a third-party library is needed, you can get a pointer to raw data:
- C++
const uint8_t* data = image.
GetData();
- C#