2017-03-01 106 views
0

我读了DICOM图像,并提取了它的一些特征,例如宽度和高度。 现在我想保存一个变量图像的总像素数。 这是代码:整数乘法不正确的结果

info = dicominfo(filename); 

width = info.Width; 
height = info.Height; 
colorType = info.ColorType; 
format = info.Format; 
size = info.FileSize; 
numberOfPixels = width*height; 
k = info.BitDepth; 

而且这些都是打印:

Size: 256 x 256 
    Color type: grayscale 
    Format: DICOM 
    Size: 137024 bytes 
    NumberOfPixels: 65535 

numberOfPixels值是错误的。为什么?

我认为这是一个演员问题,所以我也尝试加入uint32(width*height)但没有,我得到65535而不是65536. 为什么?

谢谢

+3

宽度和高度是什么类型? 256 * 256只是给出65536 .....顺便说一句,你应该在投入乘数'uint32(width)* uint32(height)' – JHBonarius

+0

谢谢!这是一个容易犯的错误,我感到有点愚蠢,非常感谢你! – beth

+2

一个重要的注意事项:不要给也是matlab函数名称的变量提供名称。它可能会导致很多问题,有时甚至不知道。这里有'高度','宽度','格式','尺寸'。 – Adiel

回答

1

你应该例如乘以前投uint32(width)*uint32(height)