Robert Jones
Robert Jones

Reputation: 597

Coordinates of a pixel between two images

I am looking for a solution to easily compute the pixel coordinate from two images.

Question: If you take the following code, how could I compute the pixel coordinate that changed from the "QVector difference" ? Is it possible to have an (x,y) coordinate and find on the currentImage which pixel it represents ?

char *previousImage;
char *currentImage;
QVector difference<LONG>;

for(int i = 0 ; i < CurrentImageSize; i++)
{
    //Check if pixels are the same (we can also do it with RGB values, this is just for the example)
    if(previousImagePixel != currentImagePixel)
    {
        difference.push_back(currentImage - previousImage);
    }
    currentImage++;
}

EDIT: More information about this topic:

The main objective here is to clearly know what is the new value of a pixel that changed between the two images and to know which pixel is it (its coordinates)

Upvotes: 0

Views: 315

Answers (2)

Lou Franco
Lou Franco

Reputation: 89232

There is not enough information to answer, but I will try to give you some idea.

You have declared char *previousImage;, which implies to me that you have a pointer to the bytes representing an image. You need more than that to interpret the image.

  1. You need to know the pixel format. You mention RGB, So -- for the time being, let's assume that the image uses 3 bytes for each pixel and the order is RGB
  2. You need to know the width of the image.
  3. Given the above 2, you can calculate the "Row Stride", which is the number of bytes that a row takes up. This is usually the "bytes per pixel" * "image width", but it is typically padded out to be divisible by 4. So 3 bpp and a width of 15, would be 45 bytes + 3 bytes of padding to make the row stride 48.
  4. Given that, if you have an index into the image data, you first integer-divide it against the row stride to get the row (Y coordinate).
  5. The X coordinate is the (index mod the row stride) integer-divided by the bytes per pixel.

Upvotes: 1

Carmellose
Carmellose

Reputation: 5087

From what I understand, you want compute the displacement or motion that occured between two images. E.g. for each pixel I(x, y, t=previous) in previousImage, you want to know where it did go in currentImage, and what is his new coordinate I(x, y, t=current).

If that is the case, then it's called motion estimation and measuring the optical flow. There are many algorithms for that, who rely on more or less complex hypotheses, depending on the objects you observe in the image sequence.

The simpliest hypothesis is that if you follow a moving pixel I(x, y, t) in the scene you observe, its luminance will remain constant over time. In other words, dI(x,y,t) / dt = 0.

Since I(x, y, t) is function of three parameters (space and time) with two unknowns, and there is only one equation, this is an ill defined problem that has no easy solution. Many of the algorithms add an additional hypothesis, so that the problem can be solved with a unique solution.

You can use existing libraries which will do that for you, one of them which is pretty popular is openCV.

Upvotes: 1

Related Questions