Extract image from ROS Image message
ROS Toolbox / ROS
The Read Image block extracts an image from a ROS
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.
Image— Extracted image signal
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.
AlphaChannel— Alpha channel for image
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.
CompressedImage messages, the Alpha channel returns all zeros if the
Show Alpha output port is enabled.
ErrorCode— Error code for image conversion
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
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 Manage Array Sizes for ROS Messages in Simulink to increase the maximum length of the array.
4 – Image decompression failed.
Maximum Image Size— Maximum image size
[2000 2000](default) | two-element vector
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— Image encoding
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
Show Alpha output port— Toggle AlphaChannel port
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.
Show ErrorCode output port— Toggle ErrorCode port
ErrorCode port to monitor errors.
Output variable-size signals— Toggle variable-size signal output
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).
Usage notes and limitations:
Requires OpenCV to be installed for local host deployment.