/** Merge the region with the id from labelimage img into this image with the newId, if the previous id in this image is compareId */
bool GeoImage::mergeInto(GeoImage & img, int compareId, int id, int newId)
{
  int llx, lly, urx, ury;
  int x, y;
  bool objectInserted = false;
#ifdef WIN32
#pragma message ("besser picBBox benutzen?")
#else
#warning besser picBBox benutzen?
#endif
  llx = int (geo2picX(img.pic2geoX(0)));
  lly = int (geo2picY(img.pic2geoY(img.rows())));
  urx = int (geo2picX(img.pic2geoX(img.cols())));
  ury = int (geo2picY(img.pic2geoY(0)));
  if (llx < 0)
    llx = 0;
  if (lly >= rows_)
    lly = rows_;
  if (urx >= cols_)
    urx = cols_;
  if (ury < 0)
    ury = 0;

  //! This loop should be optimized
  for (y = ury; y < lly; y++)
    for (x = llx; x < urx; x++) {
#if 0
      Q_ASSERT(x >= 0);
      Q_ASSERT(x < cols());
      Q_ASSERT(y >= 0);
      Q_ASSERT(y < rows());
#endif
      if (getId(x, y) != compareId)
        continue;
      float gx, gy;
      gx = pic2geoX(x);
      gy = pic2geoY(y);
      int nx, ny;
      nx = int (img.geo2picX(gx));
      ny = int (img.geo2picY(gy));
#if 0
      Q_ASSERT(nx >= 0);
      Q_ASSERT(nx < img.cols());
      Q_ASSERT(ny >= 0);
      Q_ASSERT(ny < img.rows());
#endif
      if (img.getId(nx, ny) == id) {
//                              qDebug("GeoImage::mergeInto 1->(%d,%d)",x,y);
        ((int *) data_)[y * cols_ + x] = newId;
        objectInserted = true;
      }
    }
  return objectInserted;
}