Reply to topic

convert a int Matrix to a float Matrix

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
186
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
186
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.

 
Reply to topic

Bookmarks



Who is online

Registered users: adabrowski, Alexa [Bot], Baidu [Spider], Bing [Bot], bjoernbalazs, CyberAngel, edmael, Exabot [Bot], Felix VI, firewalker, Google [Bot], gp[], jensreuterberg, lazyit, maggy, MSNbot Media, nezumi, orbmiser, pbCyanide, peje, salvochea, sebas, stavallo, TheraHedwig, Uri_Herrera, Yahoo [Bot]