HALCON Reference Manual / File / Images Operators

read_image (Operator)

Name

read_image — Read an image with different file formats.

Synopsis

read_image( : Image : FileName : )

Description

The operator read_image reads the indicated image files from the background storage and generates the image. One or more file names can be passed in FileName. If more than one file name is passed, an image object tuple with the corresponding number of image objects is returned.

For the image formats TIFF, PNG, and JPEG-2000, binary alpha channels are interpreted as regions. For TIFF files, additionally binary SubIFDs with PhotometricInterpretation = TransparencyMask are interpreted as regions. Otherwise the region of the generated image object (= all pixels of the matrix) is chosen maximal.

For TIFF images, multipage TIFF files are returned as image object tuples.

All images files written by the operator write_image (format 'ima') have the extension '.ima'. A description file can be available for every image in HALCON format (same file name with extension '.exp'). The type of the pixel data (byte, int4, real) can also be taken from the description file. If this information is not available the type byte is used as presetting.

Besides the HALCON format TIFF, GIF, BMP, JPEG, JPEG-2000, PNG, PCX, SUN-Raster, PGM, PPM, PBM and XWD files can also be read. The gray values of PBM images are set at the values 0 and 255. The file formats are either recognized by the extension (if indicated) or because of the internal structure of the files. If the extension is indicated the image can be found faster. If no extension is indicated, files with extension are preferred to files without extension. In case of PGM, PPM and PBM the corresponding extension (e.g. 'pgm') or the general value 'pnm' can be used. In case of TIFF 'tiff' and 'tif' are accepted. In case of JPEG-2000 only 'jp2' is accepted. In case of colored images an image with three color channels (matrices) is created, the red channel being stored in the first, the blue channel in the second and the green channel in the third component (channel number).

Images of kind 'int8' can be read on 64 bit systems only. Further only the IMA and the TIFF format support this image type.

Image files are searched in the current directory (determined by the environment variable) and in the image directory of HALCON . The image directory of HALCON is preset at '.' and '/usr/local/halcon/images' in a UNIX environment and can be set via the operator set_system. More than one image directory can be indicated. This is done by separating the individual directories by a colon.

Furthermore the search path can be set via the environment variable HALCONIMAGES (same structure as 'image_dir'). Example:

setenv HALCONIMAGES "/usr/images:/usr/local/halcon/images"

HALCON also searches images in the subdirectory “images” (Images for the program examples). The environment variable HALCONROOT is used for the HALCON directory.

Attention

If CMYK or YCCK JPEG files are read, HALCON assumes that these files follow the Adobe Photoshop convention that the CMYK channels are stored inverted, i.e., 0 represents 100% ink coverage, rather than 0% ink as one would expect. The images are converted to RGB images using this convention. If the JPEG file does not follow this convention, but stores the CMYK channels in the usual fashion, invert_image must be called after reading the image.

If PNG images that contain an alpha channel are read, the alpha channel is returned as the second or fourth channel of the output image, unless the alpha channel contains exactly two different gray values, in which case a one or three channel image with a reduced domain is returned, in which the points in the domain correspond to the points with the higher gray value in the alpha channel.

Parameters

Image (output_object) image(-array) object (byte / direction / cyclic / int1 / int2 / uint2 / int4 / int8 / real)
Read image.

FileName (input_control) filename.read(-array) (string)
Name of the image to be read.
Default value: 'fabrik'
Suggested values: 'monkey', 'fabrik', 'mreut'
File extension: .ima, .tif, .tiff, .gif, .bmp, .jpg, .jpeg, .jp2, .png, .pcx, .ras, .xwd, .pbm, .pnm, .pgm, .ppm

Example

* Reading an image:
  read_image(Image,'monkey')

* Reading 3 images into an image array:
  read_image(Images,['ic_0','ic_1','ic_2'])

* Setting of search path for images on '/mnt/images' and '/home/images':
  set_system('image_dir','/mnt/images:/home/images')

Result

If the parameters are correct the operator read_image returns the value 2 (H_MSG_TRUE). Otherwise an exception is raised.

Parallelization Information

read_image is reentrant and processed without parallelization.

Possible Successors

disp_image, threshold, regiongrowing, count_channels, decompose3, class_ndim_norm, gauss_image, fill_interlace, zoom_image_size, zoom_image_factor, crop_part, write_image, rgb1_to_gray

Alternatives

read_sequence

See also

set_system, write_image

Module

Foundation


HALCON Reference Manual / File / Images Operators
Version 9.0.2 Copyright © 1996-2010 MVTec Software GmbH