%% Read and Write Image Messages
% Read and write a sample ROS Image message by converting it to a MATLAB image. Then, convert a MATLAB® image to a ROS message.
% Load sample ROS messages and inspect the image message data. The img object is a sample ROS Image message object.

exampleHelperROSLoadMessages
img

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

I = readImage(img);
imshow(I)

%
% Create a ROS Image message from a MATLAB image.

imgMsg = rosmessage('sensor_msgs/Image');
imgMsg.Encoding = 'rgb8'; % Specifies Image Encoding Type
writeImage(imgMsg,I)
imgMsg

%
% Copyright 2019 The MathWorks, Inc.