0
$\begingroup$

Rosanswers logo

I have a bag file containing lots of sensor messages, including compressed camera images. I would like to use this stream of camera images in MATLAB.

I know of two possible approaches: either by exporting all images to JPG and load those into MATLAB, or by using ROSMATLAB.

I think that the first approach would involve creating a Python script to collect the camera images form the image_transport node republish. This seems to involve an awful lot of decompressing and compressing (when saving back to JPG), so I'm looking for a way to directly collect the images from the bag file and save those. I believe that the compressed images in the bag file are JPG compressed, so it should be possible to directly map them.

The second approach would also involve the republish node, I think, since ROSMATLAB does not yet seem to support image transport. Also, I've run into problems collecting the images on the subscriber. I've seen this great tutorial on creating an image publisher, but I found it hard to reverse it. I've also seen this question on ROS answers, which does a good job showing some of the basics, but I couldn't replicate it.

Long story short: can anyone provide a best practice to manage images from a rosbag in MATLAB?


Originally posted by RafBerkvens on ROS Answers with karma: 386 on 2014-10-01

Post score: 3

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You can use matlab_rosbag to open the file. Then just load the topic you want and fwrite the topic data to a jpg file. This will generate a normal jpg file which you can then view/edit in matlab using imread.

Now if only we could convert from jpg in memory to plain RGB...


Originally posted by hcostelha with karma: 230 on 2014-10-10

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by RafBerkvens on 2014-10-10:
I have written the entire data part from the matlab_rosbag image structure as a binary file called "image.jpg". Next, I loaded that using imread, giving me a valid MATLAB image. This is undoubtedly slow, using a lot of hard drive writing, but it gets me somewhere. Thanks!

Comment by RafBerkvens on 2014-10-10:
You can do it without saving to the harddrive using the code sequence discussed in this thread: http://www.mathworks.com/matlabcentral/answers/157391-how-to-convert-a-cell-array-into-an-image.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.