Windows OS update from 32 bit to 64 bit
Show older comments
chan_vese.cpp(260) : warning C4267: '=' : conversion from 'size_t' to 'int', > possible loss of data
I recently upgraded my computer from 32 bit to 64 bit, I used to run my image processing algorithm developed on MATLAB2007b platform. After upgrade I am prompted with following error message as shown above. I am using a mex file 'chan_vese.cpp' as a part of image processing, I will be grateful if someone can help me to get rid of this error message.
Thanks in advance
Answers (1)
Kaustubha Govind
on 28 Sep 2011
0 votes
This is a generic compiler warning that you could ignore if you like. See Common Visual C++ 64-bit Migration Issues. Basically, size_t and int are both 32-bit wide on 32-bit machines. On 64-bit machines, size_t is 64-bit, but int is still 32-bit wide. This is why you now get a warning about the loss in precision.
To fix the warning, you simply have to insert a static_cast<int>(mySizetVariable) around the variable of type size_t.
2 Comments
Yashasvi Purwar
on 30 Sep 2011
Walter Roberson
on 30 Sep 2011
Does the code use A^B where A and B are both integer data types? Perhaps it has a uint8 from the image raised to an power?
If you have an integer data type raised to a power, you need to consider whether the result is certain to fit within the limits of that integer data type. If you are certain it will fit, then in place of A^B you can code
cast(double(A)^double(B),class(A))
or for simple squaring or cubing you could code A*A or A*A*A instead.
If you cannot be sure that the result will fit within the limits of the data type, then you should probably be using
double(A)^double(B)
and then being careful after that on how you use the result, as you might well have to convert to back to the integer data type later for the code to work properly.
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!