This forum has been archived. All content is frozen. Please use KDE Discuss instead.

convert a int Matrix to a float Matrix

Tags: None
(comma "," separated)
flatmax
Registered Member
Posts
2
Karma
0
Hi there,

I would like to convert the following :
Matrix<int, Dynamic, Dynamic> intMatrix;

To the following :
Matrix<float, Dynamic, Dynamic> floatMatrix;

Can anyone suggest the best approach ?

thanks
Matt
jitseniesen
Registered Member
Posts
204
Karma
2
floatMatrix = intMatrix.cast<float>();
flatmax
Registered Member
Posts
2
Karma
0
That was my original approach, however I think that it looses information.

My current approach is an element wise approach :
floatMatrix(i)=(float)(((double)intMatrix(i)/numeric_limits<int>::max())*numeric_limits<int>::max());

There is probably a better approach then this ... I would prefer some vector approach which would be more efficient .... ?

Matt
jitseniesen
Registered Member
Posts
204
Karma
2
Yes, converting int to float loses information for numbers above 2^24 (if I remember correctly). But I don't see how your more complicated conversion would help.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]