Differences in brightness rendering with Xvfb

I am having a problem with some unit tests we have to check behaviour of our code applying transformations and displaying the results using vtkImageResliceToColors.

The test code renders to image and saves the result as a file which is then compared. On a Linux machine this all works fine. However when I try to run it under Xvfb so it can be used in Docker for CI I have a problem. The image produced is correct but it is darker, usually by a factor of four (i.e. the brightest pixels are (64,64,64) rather (255,255,255)) although sometimes only by a factor two. This is in the renderer image before the luminance filter is applied. The test code is

vtkSmartPointer<vtkImageResliceToColors> base_image_reslice = /* from code under test */;
vtkSmartPointer<vtkImageResliceToColors> overlay_reslice = /* from code under test */;

vtkNew<vtkImageActor> base_image_actor;
vtkNew<vtkImageActor> overlay_actor;
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> render_window;
vtkNew<vtkWindowToImageFilter> window_to_image;
vtkNew<vtkImageLuminance> rgb_to_grey;
vtkNew<vtkPNGWriter> writer;

render_window->SetOffScreenRendering( true );
render_window->AddRenderer( renderer );
window_to_image->SetInput( render_window );
rgb_to_grey->SetInputConnection( window_to_image->GetOutputPort() );

base_image_actor->GetMapper()->SetInputConnection(base_image_reslice->GetOutputPort());
base_image_actor->GetProperty()->SetOpacity(1.0);
overlay_actor->GetMapper()->SetInputConnection(overlay_reslice->GetOutputPort());
overlay_actor->GetProperty()->SetOpacity(0.5); // Makes relative position easier to see

renderer->AddActor( base_image_actor );
renderer->AddActor( overlay_actor );

render_window->Render();

writer->SetFileName( test_output_filename );
writer->SetInputConnection( window_to_image->GetOutputPort() );
writer->Write();

I am currently running with Xfvb using the command

xvfb-run --server-args="-screen 0 1280x1024x24 -ac -noreset -br "

but have tried lots of variants tweaking most of the options I can that seem relevant.

The brightness change happens if running under Xvfb on a real hardware or in Docker container so isn’t a Docker issue, it seems to be an interaction Xvfb and VTK.

I am at a loss as to why VTK (or GL underneath?) would be rendering the image with a more restricted brightness range and don’t seem to know the right search terms to find an explanation or solution. Any ideas please?

I don’t really have a good explanation why but for reference to anyone who stumbles across this in the future a colleague found we could solve this issue by using render_window->SetMultiSamples(0).

1 Like