def encode(self, rosMsg):
        if not isinstance(rosMsg, sensor_msgs.msg.Image):
            raise TypeError('Given object is not a sensor_msgs.msg.Image '
                            'instance.')

        # Convert to PIL Image
        pil = Image.fromstring(
                ImageConverter._ENCODINGMAP_ROS_TO_PY[rosMsg.encoding],
                (rosMsg.width, rosMsg.height),
                rosMsg.data,
                'raw',
                ImageConverter._ENCODINGMAP_ROS_TO_PY[rosMsg.encoding],
                0,
                1)

        # Save to StringIO
        img = StringIO()
        pil.save(img, 'PNG')
        return img
Convert a ROS compatible message (sensor_msgs.Image) to a
dataset/ETHPy150Open rapyuta/rce/rce-core/rce/util/converters/image.py/ImageConverter.encode