write_image
— Write images in graphic formats.
The operator write_image
saves the input image Image
in the
file FileName
in the format Format
. If the domain (region)
cannot be saved in the specified Format
(this is the case for 'bmp',
'jpeg', and 'ima'), all pixels outside the region receive the color defined
by FillColor
. For gray value images a value between 0 (black) and
255 (white) must be passed. For RGB color images the RGB values can be passed
directly as a hexadecimal value: e.g., 0xffff00 for a yellow background
(red=255, green=255, blue=0).
The following formats are currently supported:
All HALCON pixel types are supported. Image object tuples with up to 65535 image objects and up to 65535 channels can be written. Image objects with channels of mixed pixel types can be written.
Compression is possible with
'deflate [num]' : | Adobe deflate compression (lossless) |
'jpeg [num]' : | JPEG (lossy) |
'lzw' | LZW (lossless) |
'packbits' | PackBits (lossless) |
Here, '[num]' denotes an optional specification of a compression parameter. For 'deflate' , a number between 0 (no compression) and 9 (maximum compression) can be specified. For 'jpeg' , a number between 0 and 100 can be specified. The semantics are identical to the semantics of 'jpeg' described below. 'jpeg' can only be used for images of type byte and int1 with up to four channels.
The domain (region) of each image object can be saved in compressed form via 'mask' (default setting) or as an additional alpha channel via 'alpha' . The domain is only stored if it does not comprise the full image. 'jpeg' and 'alpha' cannot be used together because owing to the lossy compression of JPEG the domain of the image cannot be reconstructed correctly. The different options can be accumulated by appending them separated by a space character.
Examples:'tiff deflate 9' : | Adobe deflate compression, |
the domain is stored as a mask image if necessary | |
'tiff jpeg 90' : | JPEG compression with high quality, |
the domain is stored as a mask image if necessary | |
'tiff lzw alpha' : | LZW compression, |
the domain is stored as an alpha channel if necessary | |
'tiff' or 'tiff none' : | no compression, |
the domain is stored as a mask image if necessary |
Attention: Note that 'bigtiff' denotes TIFF files that can be larger than 4 GB, while 'tiff' denotes TIFF files that are limited to 4 GB. The file size depends on the image size and the selected compression. Therefore, 'bigtiff' should be selected if there is a possibility that the compressed file will grow to more than 4 GB.
Restriction:
This format can only store images with one channel (gray value image) or three channels (RGB image).
Only images with the pixel type byte are supported for this file format.
Together with the format string the quality value determining the compression rate can be provided, e.g., 'jpeg 30'.
Restriction:
This format can only store images with one channel (gray value image) or three channels (RGB image).
Only images with the pixel type byte are supported for this file format.
Attention: Images stored for being processed later should not be stored in this format due to the loss of information during compression.
Together with the format string the quality value determining the compression rate can be provided (e.g., 'jp2 40' ). This value corresponds to the ratio of the size of the compressed image and the size of the uncompressed image (in percent). Since lossless JPEG-2000 compression already reduces the file size significantly, only smaller values (typically smaller than 50) influence the file size. If no value is provided for the compression (and only then), the image is compressed without loss.
The image can contain an arbitrary number of channels. Possible types are byte, cyclic, direction, int1, uint2, int2, and int4. In the case of int4 it is only possible to store images with less or equal to 24 bits precision (otherwise an exception is raised). If an image with a reduced domain is written, the region is stored as 1-bit alpha channel.
Restriction: The maximal supported image size (width x height) for JPEG-2000 is also in HALCON-XL.
Attention: Note that the JPEG-2000 encoding of an image requires a lot of memory. For large images, it is therefore recommended to use a different format (e.g., 'tiff' ).
Together with the format string the quality value determining the compression rate can be provided, e.g., 'jpegxr 30' (use 'jpegxr' or 'jpegxr 100' for lossless encoding). Image object tuples with an arbitrary number of image objects can be written. In the case of int4 and real images, the numeric range is compressed to 24 bit accuracy. Note that this may induce loss regardless of the quality setting. If an image with a reduced domain is written, the region is stored without loss as 1-bit alpha channel. Complex images, vector fields and regular images with two gray value channels are padded with an empty third channel to be compliant with the standard.
Restriction:
This format cannot be written in parallel.
Images can have up to 8 channels.
All HALCON pixel types except int8 are supported.
Attention: Note that you need to have write permission in your current working directory in order to save an image in JPEG-XR format, regardless of the target directory.
Together with the format string, a compression level between 0 and 9 can be specified, where 0 corresponds to no compression and 9 to the best possible compression. Alternatively, the compression can be selected with the following strings: 'best' , 'fastest' , and 'none' . Hence, examples for correct parameters are 'png' , 'png 7' , and 'png none' .
Images of type byte and uint2 can be stored in PNG files. If an image with a reduced domain is written, the region is stored as the alpha channel, where the points within the domain are stored as the maximum gray value of the image type and the points outside the domain are stored as the gray value 0. If an image with a full domain is written, no alpha channel is stored.
Restriction:
This format can only store images with one channel (gray value image) or three channels (RGB image).
The maximal supported image size (width x height) for PNG is also in HALCON-XL.
All types of HALCON images are supported. See write_object
for more
information about the HOBJ format.
This file format is now legacy and the HOBJ format should be used instead.
The data is written in binary form line by line (without header or carriage
return). The size of the image and the pixel type are stored in the
description file ”FileName
.exp”. All HALCON pixel types except
'complex' and 'vector_field' can be written.
Restriction: This format can only store images with one channel (gray value image).
Image
(input_object) (multichannel-)image(-array) →
object (byte / direction / cyclic / int1 / complex / int2 / uint2 / vector_field / int4 / int8 / real)
Input images.
Format
(input_control) string →
(string)
Graphic format.
Default: 'tiff'
Suggested values: 'tiff' , 'tiff mask' , 'tiff alpha' , 'tiff deflate 9' , 'tiff deflate 9 alpha' , 'tiff jpeg 90' , 'tiff lzw' , 'tiff lzw alpha ' , 'tiff packbits' , 'bigtiff' , 'bigtiff mask' , 'bigtiff alpha' , 'bigtiff deflate 9' , 'bigtiff deflate 9 alpha' , 'bigtiff jpeg 90' , 'bigtiff lzw' , 'bigtiff lzw alpha ' , 'bigtiff packbits' , 'bmp' , 'jpeg' , 'jpeg 100' , 'jpeg 80' , 'jpeg 60' , 'jpeg 40' , 'jpeg 20' , 'jp2' , 'jp2 50' , 'jp2 40' , 'jp2 30' , 'jp2 20' , 'jpegxr' , 'jpegxr 50' , 'jpegxr 40' , 'jpegxr 30' , 'jpegxr 20' , 'png' , 'png best' , 'png fastest' , 'png none' , 'ima' , 'hobj'
FillColor
(input_control) number →
(integer / real)
Fill gray value for pixels not belonging to the image domain (region).
Default: 0
Suggested values: -1, 0, 255, 65280, 16711680
FileName
(input_control) filename.write(-array) →
(string)
Name of image file.
File extension:
.hobj
, .ima
, .tif
, .tiff
, .bmp
, .jpg
, .jpeg
, .jp2
, .jxr
, .png
If the parameter values are correct the operator write_image
returns the value 2 (
H_MSG_TRUE)
. Otherwise an exception is raised.
Foundation