www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/ReadAndWriteImageMessagesExample.m

    %% Read and Write |Image| Messages
% Read and write a sample ROS |Image| message by converting it
% to a MATLAB image. Then, convert a MATLAB(R) image to ROS
% message.
%%
% Load sample ROS messages and inspect the image message data. |img| 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