Math operations with Double or Uint8
Mostrar comentarios más antiguos
Hi Matlab community :-)
I have to perform mathematical operations on a sequence of images Mt with a fixed background landscape Mo.
The images are in Uint8 format, and the transformation mt=(Mt-Mo) provide the moving subjects, with mt(i,j)>0 all i,j,
however, if I perform dt=(double(Mt)-double(Mo)) a different result is obtained, with certain dt(i,j)<0 and dt~=double(mt).
Now, I would like to work with Uint8, but this format does not accept all mathematical transformations, such as log(mt);
in that case, I have to pass at the Double transformation, as log(double(mt)), but this seems to me inconsistent ...
In summary, working with Double or Uint8 provide different numerical results, how to make them consistent?
Thanks for your attention, Carlo
2 comentarios
"if I perform dt=(double(Mt)-double(Mo)) a different result is obtained, with certain dt(i,j)<0 and dt~=double(mt)."
Clearly some of the values of Mo are greater than the corresponding values in Mt. If you subtract them as UINT8 then those locations will be zero (and discard information), whereas if you subtract them as DOUBLE you will get negative values (and retain information). We cannot tell you what is appropriate for your data processing: is it suitable or even meaningful for your processing/algorithm to have loss of information? How do you expect random people on the internet to answer that, when you do not tell them anything about what you are doing with that data?
"I would like to work with Uint8, but this format does not accept all mathematical transformations, such as log(mt)"
It is a bit odd to require the natural logarithm ... do you really expect log base 2?
In any case, tell me the exact output value and class you expect to get for this very simple piece of code:
log(uint8(3))
"In summary, working with Double or Uint8 provide different numerical results, how to make them consistent?"
How exactly should they be "consistent" ? Do you expect binary floating point operations and integer operations to provide excactly the same results for all arithmetic operations, i.e. be completely indistinguishable? If that were possible, why do you think would computer scientists bother having different numeric classes?
Carlo Grillenzoni
el 22 de Oct. de 2023
Editada: Carlo Grillenzoni
el 22 de Oct. de 2023
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!