Main Content

CompressedImage

(To be removed) Create compressed image message

Since R2019b

CompressedImage object will be removed in a future release. Use message structure format when you create ROS messages using the rosmessage function, by specifying the Dataformat name-value argument as "struct". You can use rosReadImage and rosWriteImage functions to read and write compressed image data from ROS messages respectively. For more information, see ROS Message Structure Functions.

Description

The CompressedImage object is an implementation of the sensor_msgs/CompressedImage message type in ROS. The object contains the compressed image and meta-information about the message. You can create blank CompressedImage messages and populate them with data, or subscribe to image messages over the ROS network. To convert the image to a MATLAB® image, use the readImage function.

Only images that are sent through the ROS Image Transport package are supported for conversion to MATLAB images.

Creation

Description

example

msg = rosmessage('sensor_msgs/CompressedImage') creates an empty CompressedImage object. To specify image data, use the msg.Data property. You can also get these image messages off the ROS network using rossubscriber.

Properties

expand all

This property is read-only.

Message type of ROS message, returned as a character vector.

Data Types: char

This property is read-only.

ROS Header message, returned as a Header object. This header message contains the MessageType, sequence (Seq), timestamp (Stamp), and FrameId.

Image format, specified as a character vector.

Example: 'bgr8; jpeg compressed bgr8'

Image data, specified as a uint8 array.

Object Functions

readImage(To be removed) Convert ROS image data into MATLAB image

Examples

collapse all

Read and write a sample ROS CompressedImage message by converting it.

Load sample ROS messages and inspect the image message. The imgcomp object is a sample ROS CompressedImage message object.

exampleHelperROSLoadMessages
imgcomp
imgcomp = 
  ROS CompressedImage message with properties:

    MessageType: 'sensor_msgs/CompressedImage'
         Header: [1x1 Header]
         Format: 'bgr8; jpeg compressed bgr8'
           Data: [30376x1 uint8]

  Use showdetails to show the contents of the message

Create a MATLAB image from the CompressedImage message using readImage and display it.

I = readImage(imgcomp);
imshow(I)

compImg = rosmessage('sensor_msgs/CompressedImage')
compImg = 
  ROS CompressedImage message with properties:

    MessageType: 'sensor_msgs/CompressedImage'
         Header: [1x1 Header]
         Format: ''
           Data: [0x1 uint8]

  Use showdetails to show the contents of the message

Version History

Introduced in R2019b

collapse all

R2021a: ROS Message Structure Functions

You can now create messages as structures with fields matching the message object properties. Using structures typically improves performance of creating, updating, and using ROS messages, but message fields are no longer validated when set. Message types and corresponding field values from the structures are validated when sent across the network.

To support message structures as inputs, new functions that operate on specialized ROS messages have been provided. These new functions are based on the existing object functions of message objects, but support ROS and ROS 2 message structures as inputs instead of message objects.

The object functions will be removed in a future release.

Message TypesObject Function NameNew Function Name

Image

CompressedImage

readImage

writeImage

rosReadImage

rosWriteImage

LaserScan

readCartesian

readScanAngles

lidarScan

plot

rosReadCartesian

rosReadScanAngles

rosReadLidarScan

rosPlot

PointCloud2

apply

readXYZ

readRGB

readAllFieldNames

readField

scatter3

rosApplyTransform

rosReadXYZ

rosReadRGB

rosReadAllFieldNames

rosReadField

rosPlot

QuaternionreadQuaternion

rosReadQuaternion

OccupancyGrid

readBinaryOccupanyGrid

readOccupancyGrid

writeBinaryOccupanyGrid

writeOccupanyGrid

rosReadOccupancyGrid

rosReadBinaryOccupancyGrid

rosReadOccupancyGrid

rosWriteBinaryOccupancyGrid

rosWriteOccupancyGrid

OctomapreadOccupancyMap3D

rosReadOccupancyMap3D

PointStamped

PoseStamped

QuaternionStamped

Vector3Stamped

TransformStamped

apply

rosApplyTransform

All messagesshowdetails

rosShowDetails