This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Read Image

Extract image from ROS Image message

  • Library:
  • Robotics System Toolbox / ROS


The Read Image block extracts an image from a ROS Image or CompressedImage message. You can select the ROS message parameters of a topic active on a live ROS network or specify the message parameters separately. The ROS messages are specified as a nonvirtual bus. Use the Subscribe block output to receive a message from a ROS network and input the message to the Read Image block.


When reading ROS image messages from the network, the Data property of the message can exceed the maximum array length set in Simulink®. To increase the maximum array length, click Tools > Manage Array Lengths > Robot Operating System, select the Data array, and increase the size based on the number of points in the image.



expand all

ROS Image or CompressedImage message, specified as a nonvirtual bus. You can use the Subscribe block to get a message from an active ROS network.

Data Types: bus


expand all

Extracted image signal from ROS message, returned as an M-by-N-by-3 matrix for color images, and an M-by-N matrix for grayscale images. The matrix contains the pixel data from the Data property of the ROS message.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16

Alpha channel for image, returned as an M-by-N matrix. This matrix is the same height and width as the image output and has values [0 1] to indicate the opacity of each corresponding pixel, with a value of 0 being completely transparent.


For CompressedImage messages, the Alpha channel returns all zeros if the Show Alpha output port is enabled.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16

Error code for image conversion, returned as a scalar. The error code values are:

  • 0 – Successfully converted the image message.

  • 1 – Incorrect image encoding. Check that the incoming message encoding matches the ImageEncoding parameter.

  • 2 – The dimensions of the image message exceed the limits specified in the Maximum Image Size parameter.

  • 3 – The Data field of the image message was truncated. See Managing Array Sizes in Simulink ROS to increase the maximum length of the array.

  • 04 – Image decompression failed.

Data Types: uint8


expand all

Maximum image size, specified as a two-element [height width] vector.

Click Configure using ROS ... to set this parameter automatically using an active topic on a ROS network. You must be connected to the ROS network.

Image encoding for the input ImageMsg. Select the supported encoding type which matches the Encoding property of the message. For more information about encoding types, see readImage.

Toggle Alpha channel output port if your encoding supports an Alpha channel.


Only certain encoding types support alpha channels. The ImageEncoding parameter determines if this parameter appears in the block mask.

Toggle the ErrorCode port to monitor errors.

Toggle variable-size signal output. Variable-sized signals should only be used if the image size is expected to change over time. For more information about variable sized signals, see Variable-Size Signal Basics (Simulink).

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Introduced in R2017b