convert a int Matrix to a float Matrix

flatmax
Registered Member
Posts
2
Karma
0

convert a int Matrix to a float Matrix

Fri Mar 08, 2013 4:48 am
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

Re: convert a int Matrix to a float Matrix

Fri Mar 08, 2013 8:46 am
floatMatrix = intMatrix.cast<float>();
flatmax
Registered Member
Posts
2
Karma
0

Re: convert a int Matrix to a float Matrix

Sat Mar 09, 2013 12:31 am
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

Re: convert a int Matrix to a float Matrix

Sat Mar 09, 2013 11:42 am
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.

Who is online

Registered users: alindichris, Baidu [Spider], Bing [Bot], davidemme, Exabot [Bot], ggael, Google [Bot], jgrulich, koriun, La Ninje, Majestic-12 [Bot], mmolch, orbmiser, Panz, petehuffington, RockFord, scottpetrovic, slangkamp, Sogou [Bot], tokiedian, vpinon, Yahoo [Bot]