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
185
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
185
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: alake, Baidu [Spider], Bing [Bot], boudewijn, donK23, eddiej, Essence of Orange, Exabot [Bot], garthecho, Google [Bot], google01103, GreatEmerald, Hans, jstaniek, ken300, koriun, mutlu, odysseus-art, parzt, rasyalarasati, Sogatori, tadassu, TheraHedwig, Tuukka, Yahoo [Bot]