Why is MATLAB rounding to whole number after multiplying and summing DICOM structure fields?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Daniel Bridges
am 7 Jul. 2016
Bearbeitet: Daniel Bridges
am 8 Jul. 2016
Working with DICOM files, thinking a meshgrid the best way to work with DICOM coordinates between structure and dose (please tell me if there's a better way), I'm trying to prepare a meshgrid to represent the DICOM coordinates, given the RTDOSE matrix with Attributes specifying the first element's DICOM coordinate:
>> doseinfo.ImagePositionPatient(1)
ans = -191.1930
>> gridxmin = double(doseinfo.ImagePositionPatient(1))
gridxmin = -191.1930
>> doseinfo.Width * doseinfo.PixelSpacing(1)
ans = 380
>> gridxmax=double(gridxmin+ doseinfo.Width *doseinfo.PixelSpacing(1))
gridxmax = 189
>> gridxmin + doseinfo.Width * doseinfo.PixelSpacing(1)
ans = 189
>> gridxmax - gridxmin
ans = 380.1930
As you can see, double appears not to be the problem, but rather, somehow multiplying causes the result to round. Why is it summing to 189 instead of the correct value 188.8070?
It may be worth noting that if I try inserting a factor of 1000 (to convert from millimeter to micrometer), the max value is 0 instead of 188807 (gridxmin = -191193, gridxmax = 0) -- although such a meshgrid can't be used anyway, as it throws the error
Error using repmat
Maximum variable size allowed by the program is exceeded.
Error in meshgrid (line 77)
xx = repmat(xx, ny, 1, nz);
Something weird seems to be happening with this use of structures created from dicominfo. The problem is not resolved if I extract the data from the structure before calculation:
>> xstart = doseinfo.ImagePositionPatient(1);
xwidth = doseinfo.Width; xspacing = doseinfo.PixelSpacing(1);
gridxmin = xstart;
gridxmax = xstart + xwidth * xspacing
gridxmax =
189
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Jul. 2016
When you multiply a double by an integer data type, the result is calculated as double and then converted to the integer data type.
6 Kommentare
Walter Roberson
am 7 Jul. 2016
In C, does K * 2 + 1 mean K * (short int)(2) + (short int)1 with the short int widened if necessary depending on the type of K? Or does it mean K * (int)(2) + (int)(1) with the int widened as needed? Or does it mean K * (long int)(2) + (long int)(1) with the int converted to float or double if needed? If you have a long int, float is not necessarily widening...
It has been a while for me; I would need to re-check the C standards to find out exactly how the expression would be interpreted. As (int) is what my memory is suggesting.
Guillaume
am 7 Jul. 2016
In C (and C++), an integer literal with no suffix is of type int.
In C#, an integer literal with no suffix is of type int, uint, long, or ulong (whichever smallest type can fit the constant).
If K is narrower than int, then the result will be int. If K is wider, the result will be the type of K.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu DICOM Format finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!