Why pixels can have float values?
Asked Answered
B

2

5

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

Boche answered 13/1, 2016 at 15:58 Comment(0)
F
5

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.

Felice answered 13/1, 2016 at 16:16 Comment(0)
T
5

I believe (if I did understand you properly) that you have discovered the world of interpolation. An image itself, is a continous plane with x coordinates in the range of [0, width] and y coordinates in the range of [0, height]. To show the image in a monitor, or store it in disk, the image is discretized in pixels.

If you are applying discrete operations, such as convolutions, additions or thresholds to an image, it is normal to think of it as a grid of values. However, specially in your case that you are tracking objects in an image, you should think of it as a continuous space. The center of mass of a object, wont probably lay in a discrete value, it will be some floating point coordinate in the above range (i.e. p = (50.5, 10.1)), but that shouldn't be a problem.

If you want, you can also access the color (or gray-scale value) of the p = (50.5, 10.1) pixel by using bilinear (or more complex) interpolation.

Tease answered 13/1, 2016 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.