我将.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 /(266 * 425)== 2,所以它应该是2个字节的前置像素(?) 最佳答案
问题是您是否真的需要DicomImage::getOutputData()返回的渲染像素数据,或者是否需要DICOM图像中的原始像素数据(另请参阅@kritzel_sw的答案)。使用getOutputData()时,应将请求的位深度作为参数传递(例如,每个样本8位),而不是getDepth()返回的值。
处理CT图像时,您可能希望使用Hounsfield单位的像素数据(这是模态LUT转换的结果,是一个有符号整数值)。
关于image - 如何将Dicom图像正确转换为OpenCV,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45579404/