Working with Image Coordinates

Image coordinates are measured relative to the window’s offset. The offset is an arbitrary point that measures the distance from the origin (0,0) of the image coordinate system to the upper left corner of the window. Another way to think about the offset is that it labels the coordinates of the upper left corner of the window. As Initial state of coordinate systems after image acquisition illustrates, the offset of a newly acquired image is (0, 0) and it coincides with the upper left corner of the root image. In other words, the root offset is also (0, 0).

Note: Although the root offset describes the location of the window relative to the upper left corner of the root image, this value is not particularly useful when working with images.

The rest of this section uses the following function to illustrate what happens to the image coordinate system as you work with windows. Assume, also, that the image in Initial state of coordinate systems after image acquisition is a binary image. White pixels have high values and black pixels have low values.

void showWindowInfo()
{
ccIPair theOffset = thePelBuf.offset();
ccIPair rootOffset = thePelBuf.offsetRoot();

std::cout << "offset: (" << theOffset.x() << ", ";
std::cout << theOffset.y() << ")" << std::endl;

std::cout << "root offset: (" << rootOffset.x() << ", ";
std::cout << rootOffset.y() << ")" << std::endl;

std::cout << "width: " << thePelBuf.width();
std::cout << " height: " << thePelBuf.height() << std::endl;
}

If you were to call showWindowInfo() immediately after acquiring the image in Initial state of coordinate systems after image acquisition, you would see the following results:

offset: (0, 0)
root offset: (0, 0)
width: 15 height: 7

The black pixel in the upper left corner of the shape is at location (5,1) in image coordinates. So the following statement would be true.

thePelBuf.get(5,1) == 0; // True. The pixel at (5,1) is black.