我在将.dcm图像从dcmtk格式转换为opencv时遇到问题。我的代码:
DicomImage dcmImage(in_file.c_str());
int depth = dcmImage.getDepth();
std::cout << "bit-depth: " << depth << "\n"; //this outputs 10
Uint8* imgData = (uchar*)dcmImage.getOutputData(depth);
std::cout << "size: " << dcmImage.getOutputDataSize() << "\n"; //this outputs 226100
cv::Mat image(int(dcmImage.getWidth()), int(dcmImage.getHeight()), CV_32S, imgData);
std::cout << dcmImage.getWidth() << " " << dcmImage.getHeight() << "\n"; //this outputs 266 and 425
imshow("image view", image); //this shows malformed image所以我对CV_32S和getOutputData参数不是很确定。我应该把什么放在那里?也是226100/(266x425) == 2,所以它应该是像素前2个字节(?)
发布于 2017-08-09 14:02:37
当getDepth()返回10时,这意味着每个像素有10位(很可能是灰度级)。
根据DICOM图像的像素表示(0x0028,0x0103),必须为矩阵类型指定带符号或无符号的16位整数: CV_16UC2或CV_16SC2。
注意:由于只使用了2字节的10位,您可能会在高6位中发现垃圾,在将缓冲区传递到垫子之前应该将其屏蔽掉。
更新:关于您的评论和源代码的:
-1
发布于 2017-08-10 21:50:16
问题是您是否真的需要DicomImage::getOutputData()返回的渲染像素数据,还是需要来自DICOM图像的原始像素数据(另请参阅@kritzel_sw的答案)。使用getOutputData()时,您应该将请求的位深度作为参数传递(例如,每个样本8位),而不是getDepth()返回的值。
在处理CT图像时,您可能希望使用Hounsfield单位(这是Modality LUT转换结果的有符号整数值)中的像素数据。
https://stackoverflow.com/questions/45579404
复制相似问题