Loading an OMNI Image

omni.Image.load() can be used to load an existing .omni metadata file.

See Loading input in a task type for how to load an OMNI file that is provided as an input parameter.

See also Import external data / Export Data.

Convert NumPy Array

omni.Image.from_numpy_array() can be used to create an OMNI image from a NumPy array.

For example Example.CV.Gauss uses this approach:

import omni
import xfworkerutil

import cv2

worker = xfworkerutil.XFWorkerJob()

inputs = worker.job['inputs']
sigma = inputs['gauss_sigma']
support = inputs['gauss_support']

if sigma is None:
    # cv2.GaussianBlur automatically selects sigma from kernel size if sigma is zero.
    sigma = 0
kernel_size = (support * 2 + 1, support * 2 + 1)

# Download input files (if not local)
image = worker.get_omni_image(inputs['image'])

if image.dimensions != 2:
    worker.error(f"Image of {image.dimensions} dimensions not supported.")

# Use openCV for image processing

blurred_pixels = cv2.GaussianBlur(image.pixels, kernel_size, sigma)

# Save the segment image
blurred_omni_path = worker.create_related_path(image.metadata_path, '_blurred.omni')
blurred_raw_path = worker.create_related_path(image.metadata_path, '_blurred.raw')
blurred_image = omni.Image.from_numpy_array(blurred_pixels, blurred_omni_path, {
        'pixels_filename': blurred_raw_path.name,
        'dimensions': image.dimensions,
        'size': image.size,
        'pixel_size_mm': image.pixel_size_mm,
        'pixel_type': image.pixel_type,
if image.pixel_min_value is not None:
    blurred_image.metadata['pixel_min_value'] = image.pixel_min_value
if image.pixel_max_value is not None:
    blurred_image.metadata['pixel_max_value'] = image.pixel_max_value
blurred_image.pixels_path = blurred_raw_path

# Upload output files
image_output = worker.upload_omni_output(blurred_image)

# Save outputs
outputs = {
    "image": image_output,

Import AIM file

omni.import_from_aim() can be used to import an AIM file as an OMNI image.

aimio can be used to work with AIM files directly.