Gazebo | Ignition | Community
Ask Your Question

How to simulate monochrome / greyscale camera in Gazebo?

asked 2022-02-04 19:46:50 -0600

shonigmann gravatar image

updated 2022-02-07 12:05:49 -0600

Is there a proper way to simulate monochrome / greyscale camera in Gazebo?

The answer to question #3470 suggests setting the <format> tag to L8. This almost works as expected, but I noticed that the output image only uses the red channel of the rendered scene. Thus a blue object would appear as black, as shown below:

image description

Is there a way to get the sensor to output the mean greyscale value (e.g. (R+G+B)/3)?

Edit: adding a photo showing the same result in RViz and the Gazebo Topic Visualizer, as well as showing the ambient and background color settings image description

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2022-02-07 12:31:16 -0600

shonigmann gravatar image

Looking at the source code, it looks like L8 and L_INT8 set bpp to 8, which is used by FreeImage_ConvertFromRawBits() as the bit-depth:

bpp Type: SystemUInt32 The bit depth (bits per pixel) of the raw bitmap.

I have a hunch that the renderer is producing an RGB image by default, and the L8 option is just taking the first 8 bits of each pixel, i.e. the Red channel only.

Certainly more efficient than averaging over the 3 channels for each frame, but it feels a bit misleading... I'll open an issue on the Gazebo github, but given the massive issue backlog I have doubts anything will come of it. For my purposes I will likely end up writing a plugin to average RGB images into grey scale.

edit flag offensive delete link more


There is an example for B&W OGRE compositor. Add the compositor to the OGRE camera of an RGB camera sensor (via sensor plugin), and more correct grey RGB images can be obtained. Necessary files can be found from these files. GLSL 150 should be good for Gazebo on Ubuntu. Would be better to get output in 1 channel anyway.

Veerachart gravatar imageVeerachart ( 2022-02-08 01:17:08 -0600 )edit

Interesting - thanks for the resources! We may go this route if we end up needing "true" mono. for now, we're going to see how much mileage we can get out of L8

shonigmann gravatar imageshonigmann ( 2022-02-08 13:14:34 -0600 )edit

There is actually a sample browser from OGRE that you can install and see the samples (the version will be quite newer than what Gazebo is using). They look quite different from what we see from Gazebo. I've been trying to pick out some tricks to improve model's look in the cameras, not actually successful though.

Veerachart gravatar imageVeerachart ( 2022-02-08 19:36:52 -0600 )edit

answered 2022-02-06 19:42:20 -0600

Veerachart gravatar image

L8 should work as a grayscale camera. Have you checked with the Topic Visualizer? Maybe this is just the visualization problem. Things in GUI side are not exactly the same as things on the world (physics + sensors) side.

edit flag offensive delete link more


I checked in RViz and observed the same result. I've added edited my question to add a photo that shows the same result in Rviz, the GUI, and in the topic visualizer

shonigmann gravatar imageshonigmann ( 2022-02-07 12:04:42 -0600 )edit

You are right. I just checked by saving R8G8B8 images and L8 images. Taking out only the R channel of the RGB image (using GIMP's color mixer) results in the same shade as the L8 image. I've been using L8 for a while, and never noticed this. Thought that the gray images should work fine. Thank you for the finding.

Veerachart gravatar imageVeerachart ( 2022-02-07 20:38:01 -0600 )edit

I appreciate the sanity check / confirmation that there isn't something wrong with my configuration!

shonigmann gravatar imageshonigmann ( 2022-02-07 22:20:19 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2022-02-04 19:46:50 -0600

Seen: 235 times

Last updated: Feb 07 '22