ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

Compressed camera images from rosbag to matlab

asked 2014-10-01 02:04:53 -0600

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-10-10 05:00:21 -0600

hcostelha gravatar image

updated 2014-10-10 05:00:58 -0600

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...

edit flag offensive delete link more

Comments

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!

RafBerkvens gravatar image RafBerkvens  ( 2014-10-10 06:33:47 -0600 )edit

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.

RafBerkvens gravatar image RafBerkvens  ( 2014-10-10 08:36:56 -0600 )edit
0

answered 2017-04-12 11:51:45 -0600

vik748 gravatar image

updated 2017-04-12 14:26:51 -0600

Matlab Robotics toolbox can do this very easily now, check out https://www.mathworks.com/help/roboti...

img = readImage(msg)

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2014-10-01 02:04:53 -0600

Seen: 2,519 times

Last updated: Apr 12 '17