From: kevin@neuron.arc.nasa.gov (Kevin Montgomery)
Subject: IL: ilmemoryimg coord space reset -> 'img1 << img2' => 'img1 != img2'
Keywords: imagevision, IL, ilmemoryimg
Organization: NASA-Ames Biocomputation Center
Date: Wed, 14 Oct 1992 02:24:09 GMT

howdy folks-
	just realized that an ilMemoryImg object resets the ilCoordSpace,
rather than using the CoordSpace of the source image on a copyTile.  Now it
sure makes sense, but the behaviour I noticed before was confusing enough to
be worth noting: 

	I created a memimg and '<<' (copyTile)-ed in an image,
	then read back what was in the array (via getPixel) and 
	found that what the original image had wasn't what I read
	out and into the memimg!  

what had happened was that the input fileimg was in a CoordSpace
that was Upper-Left and what the memimg defaults to is Lower-Left.

was surprising enough that I thought other folks might like to be aware 
of it.  (it's the kinda thing that you assume works the way you first
think, for some reason...)

						kevin

========================== the run ========================================
Values from fileimg ...:
image data type = 2 (2 = ilUChar).

0: 62   64      65      65      68      70      70      74      75      75
1: 62   64      64      65      66      68      69      72      74      77
2: 64   66      66      67      67      69      69      72      74      76
3: 63   66      67      67      67      67      68      70      73      76
4: 67   68      68      68      68      68      70      71      73      75
5: 66   68      68      68      68      70      70      70      72      73
6: 68   69      70      70      70      70      71      72      74      74
7: 69   71      71      71      72      73      72      72      72      72
8: 68   72      73      75      75      74      72      71      72      73
9: 67   70      74      75      74      74      74      71      70      72
Values from memimg ...:
image data type = 2 (2 = ilUChar).

0: 64   52      44      37      29      24      25      30      42      57
1: 65   54      46      36      27      23      26      33      45      58
2: 67   55      46      34      28      26      27      32      45      59
3: 67   55      45      38      28      23      25      32      48      61
4: 71   58      49      39      31      27      30      36      48      60
5: 70   57      46      33      26      25      28      37      50      62
6: 74   59      49      37      27      29      31      38      50      65
7: 74   60      49      33      27      28      31      40      56      67
8: 72   58      47      33      27      27      32      43      59      72
9: 69   56      44      33      27      26      32      43      61      74


========================== the code ========================================
#include <iostream.h>
#include <il/ilGenericImgFile.h>
#include <il/ilMemoryImg.h>

void print_vals(ilImage *img)
{
  cout << "image data type = " << img->getDataType() << " (2 = ilUChar).\n" 
       << flush;
  unsigned char val;
  ilPixel pix(ilUChar, 1, &val);
  for (int y=0; y<10; y++) {
    cout << '\n' << y << ": ";
    for (int x=0; x<10; x++) {
      img->getPixel(x, y, pix);
      cout << pix[0] << "\t" << flush;
    }
  }
  cout << "\n" << flush;
}


void main(int argc, char *argv[])
{
 ilFileImg *fileimg = ilOpenImgFile(argv[1], "r");

  // get image size
  ilSize size;
  fileimg->getSize(size);

  // make an image in memory
  ilType type = ilUChar;
  ilOrder order = fileimg->getOrder();
  ilMemoryImg *memimg = new ilMemoryImg(size, type, order);

  // if this line isn't included, will map coord spaces on ya...
  // memimg->setCoordSpace( fileimg->getCoordSpace() );

  // copy in the image
  *memimg << *fileimg;

  cerr << "Values from fileimg ...:\n";
  print_vals(fileimg);
  cerr << "Values from memimg ...:\n";
  print_vals(memimg);
}