Search code examples
opencvfloating-pointpixelprecision

Why pixels can have float values?


this may be a simple question, but i wonder why pixel values can have float values? I'm tracking a target and get the mass center with contours() and moments() method and if i want i can get float values of them.

But why is this even possible? An image can't have a 0.1234 Pixel


Solution

  • A Mat can hold float values, as well as many other types. Examples of images having float` values are:

    • BGR images are typically in range 0, 255 for uchar, but in range [0,1] for float. It's just a convention.
    • Your image is the result of some operation that produces float results. This is not necessarily a ready-to-display image, but in this case is just a regular matrix, holding some values. Don't forget that an image is just a matrix whose values represent the pixel values.

    You can also have float coordinates. This is the case of sub-pixel accuracy. The centroid of a blob may have float coordinates. e.g. (5.1, 6.8). You can draw this point loosing a bit of precision with integer coordinates, e.g. (5, 7), but you may need the float value for further computation.