FIX: mosaic output image size fit best inputs extents

Merged Rémi Cresson requested to merge 2217-mosaic_out_size into develop


Closes #2217 (closed)


The Mosaic application computes the output image origin, size, and spacing in the GenerateOutputInformation method of the base mosaic filter.

First, the extent of the output image is retrieved. The pixel spacing is computed from the smallest pixel spacing values of the input images. Then, the origin is computed (from this pixel spacing, and the extent). After that, the output image size is finally computed.

In the current implementation, the output image size is rounded to the upper number of pixels (the idea was to avoid losing one col/row of pixels, and it was not a big deal if we add some extra row/col to the output image):

  // Set final size
  m_OutputSize[0] = vcl_floor((extentSup[0] - extentInf[0]) / vcl_abs(m_OutputSpacing[0])) + 1;
  m_OutputSize[1] = vcl_floor((extentSup[1] - extentInf[1]) / vcl_abs(m_OutputSpacing[1])) + 1;

However this is very embarrassing when you need to mosaic several images of the same extent/size, because the output image size will have +1 row/col.

The proposed change intend to correct that using std::round to compute the output image size from the extent and the pixel spacing. This way, the output image size is more correctly adjusted and fits better the actual content: if the continuous size of the output image falls between the start corner of the pixel and its center, it will be rounded to the lower number. If it falls between its center and its end corner, it will be rounded to the upper number.

  // Set final size (proposed changes)
  m_OutputSize[0] = std::round((extentSup[0] - extentInf[0]) / vcl_abs(m_OutputSpacing[0]));
  m_OutputSize[1] = std::round((extentSup[1] - extentInf[1]) / vcl_abs(m_OutputSpacing[1]));

Implementation Details

Classes and files

Only 2 lines of Modules/Filtering/Mosaic/include/otbStreamingMosaicFilterBase.hxx are changed (as described above).


If we are lucky, tests could pass (depending on the rounding of the input images extents...) If not, the baseline of all Mosaic tests must be updated.


No need


The copyright owner is INRAe (ex-IRSTEA) and has signed the ORFEO ToolBox Contributor License Agreement.

Edited by Rémi Cresson

Merge request reports