Filter löschen
Filter löschen

It seems that matlab is rounding my negative values to 0 when stored in a matrix. How can I undo that? And is the cosine values in the right order?

7 Ansichten (letzte 30 Tage)
read = dicomread('2.dcm')
[X, map] = dicomread('2.dcm');
%montage(X, map, 'Size', [2 5]);
info = dicominfo('2.dcm');
Y = dicomread(info);
%figure, imshow(Y);
%imcontrast;
Rows = info.Rows
Columns = info.Columns
Pixel_Spacing = info.PixelSpacing %in mm/pixel
Pixel_Spacing_x = info.PixelSpacing(1)
Pixel_Spacing_y = info.PixelSpacing(2)
Patient_Position = info.ImagePositionPatient
Sx = double(info.ImagePositionPatient(1))
Sy = double(info.ImagePositionPatient(2))
Sz = double(info.ImagePositionPatient(3))
Image_Orientation = info.ImageOrientationPatient
F12 = Image_Orientation(1)
F22 = Image_Orientation(2)
F32 = Image_Orientation(3)
F11 = Image_Orientation(4)
F21 = Image_Orientation(5)
F31 = Image_Orientation(6)
Delta_r = Rows*Pixel_Spacing_x %in mm
Delta_c = Columns*Pixel_Spacing_y %in mm
%r: Row index to the image plane. The first row index is zero.
%c: Column index to the image plane. The first column is index zero.
r = 0.0
c = 0.0
A = double([(F11*Delta_r) (F12*Delta_c) 0 Sx; F21*Delta_r F22*Delta_c 0 Sy; F31*Delta_r F32*Delta_c 0 Sz;0 0 0 1])
B = double([r;c;0.0;1.0])
P = double(A)*double(B)
>> Sy
Sy =
-27.721523479739002
>> A
A =
0 0 0 175
0 222 0 0
0 0 0 192
0 0 0 1
The value of Sy should be in the second row the fourth column.
What can I do to stop the rounding to 0? also, despite having double, in the matrix there is always rounding to nearest integer. I changed the formats but the problem is still there.

Akzeptierte Antwort

Dehua Kang
Dehua Kang am 18 Mai 2016
Hi ,Hoda Hatoum I think you may make a mistake. I think that F12 = Image_Orientation(4); F22 = Image_Orientation(5); F32 = Image_Orientation(6); F11 = Image_Orientation(1); F21 = Image_Orientation(2); F31 = Image_Orientation(3); cause the vector of ImageOrientationPatient is [1 0 0 0 1 0],so the A should be 500 0 0 -250 0 500 0 -140 0 0 0 -20 0 0 0 1 and P is -250 -140 -20 1

Weitere Antworten (3)

Walter Roberson
Walter Roberson am 15 Mai 2016
You used double() after you construct A. Some component that you are putting into A is one of the unsigned integer data types, and MATLAB is seeing that and converting everything around it to the same unsigned integer data type before double() is called.
For example, hypothetically info.ImageOrientationPatient could be unsigned integer, which would make all of your F* variables unsigned integer, and then the expression building the array would all be converted to unsigned integer before double() was called.
  3 Kommentare
Walter Roberson
Walter Roberson am 16 Mai 2016
read = dicomread('2.dcm')
[X, map] = dicomread('2.dcm');
%montage(X, map, 'Size', [2 5]);
info = dicominfo('2.dcm');
Y = dicomread(info);
%figure, imshow(Y);
%imcontrast;
Rows = double(info.Rows);
Columns = double(info.Columns);
Pixel_Spacing = double(info.PixelSpacing); %in mm/pixel
Pixel_Spacing_x = info.PixelSpacing(1)
Pixel_Spacing_y = info.PixelSpacing(2)
Patient_Position = double(info.ImagePositionPatient);
Sx = info.ImagePositionPatient(1);
Sy = info.ImagePositionPatient(2);
Sz = info.ImagePositionPatient(3);
Image_Orientation = double(info.ImageOrientationPatient);
F12 = Image_Orientation(1);
F22 = Image_Orientation(2);
F32 = Image_Orientation(3);
F11 = Image_Orientation(4);
F21 = Image_Orientation(5);
F31 = Image_Orientation(6);
Delta_r = Rows*Pixel_Spacing_x; %in mm
Delta_c = Columns*Pixel_Spacing_y; %in mm
%r: Row index to the image plane. The first row index is zero.
%c: Column index to the image plane. The first column is index zero.
r = 0.0;
c = 0.0;
A = [(F11*Delta_r) (F12*Delta_c) 0 Sx; F21*Delta_r F22*Delta_c 0 Sy; F31*Delta_r F32*Delta_c 0 Sz;0 0 0 1]
B = [r;c;0.0;1.0]
P = A*B

Melden Sie sich an, um zu kommentieren.


Dehua Kang
Dehua Kang am 18 Mai 2016
And here :Delta_r = Rows*Pixel_Spacing_x; %in mm Delta_c = Columns*Pixel_Spacing_y; %in mm
It may be wrong ,it should be :Delta_r=Pixel_Spacing_x;Delta_c = Pixel_Spacing_y; It is none of the Columns and Rows business.

Dehua Kang
Dehua Kang am 18 Mai 2016
This is my value of p :P =
42.9688
152.9688
-20.0000
1.0000
is not integer, it is double.
  1 Kommentar
Steven Lord
Steven Lord am 18 Mai 2016
1) Please stop posting comments that offer additional information or clarification as answers to the question. Post them as comments using the "Comment on this Question" or "Comment on this Answer" links under the main question or the answer to which you want to respond, respectively.
2) Set a breakpoint on the line where you define the variable A then execute your code. When you reach the breakpoint, look at the classes of the variables you use on that line to define A. The whos function will give you that information. If any of those variables are of an integer type (int8, int16, uint32, uint64, etc.) then the combined matrix will be of that integer type.
You can convert that combined matrix into double all you want after that point, but the data has already been lost in the conversion process. Once you crack an egg into a cake batter, remembering that you wanted to hard boil it for breakfast instead won't put it back in its shell.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by