Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 如何正确地将dicom图像转换为opencv_Image_Opencv_Bitmap_Dicom_Dcmtk - Fatal编程技术网

Image 如何正确地将dicom图像转换为opencv

Image 如何正确地将dicom图像转换为opencv,image,opencv,bitmap,dicom,dcmtk,Image,Opencv,Bitmap,Dicom,Dcmtk,我无法将.dcm图像从dcmtk格式转换为opencv格式。 我的代码: DicomImage dcmImage(在_file.c_str()中); int depth=dcmImage.getDepth(); 当getDepth()返回10时,这意味着每像素有10位(很可能是灰度) 根据DICOM图像(0x0028,0x0103)的像素表示,必须为矩阵类型指定有符号或无符号16位整数: CV_16UC2或CV_16SC2 注意:由于只使用了2字节中的10位,您可能会在上面的6位中发现垃圾,在将

我无法将.dcm图像从dcmtk格式转换为opencv格式。 我的代码:

DicomImage dcmImage(在_file.c_str()中);
int depth=dcmImage.getDepth();
当getDepth()返回10时,这意味着每像素有10位(很可能是灰度)

根据DICOM图像(0x0028,0x0103)的像素表示,必须为矩阵类型指定有符号或无符号16位整数: CV_16UC2或CV_16SC2

注意:由于只使用了2字节中的10位,您可能会在上面的6位中发现垃圾,在将缓冲区传递到mat之前,这些垃圾应该被屏蔽掉

更新: 关于您的评论和源代码:

  • DicomImage::getInterData()::getPixelRepresentation()不返回DICOM标头中的像素表示,而是同时表示位深度和有符号/无符号的内部枚举。要获取标头中的值,请使用DcmDataset或DcmFileFormat
  • 我不是openCV专家,但我认为您正在对无法正常工作的16位图像应用8位位掩码
  • 位掩码应为(1>>11)-1

  • 问题是您是否真的需要由DICOM图像::getOutputData()返回的渲染像素数据,或者是否需要DICOM图像中的原始像素数据(另请参见@kritzel_sw的答案)。使用getOutputData()时,应将请求的位深度作为参数传递(例如,每个样本8位),而不是getDepth()返回的值


    使用CT图像时,您可能希望使用Hounsfield单位的像素数据(这是一个有符号整数值,是模态LUT变换的结果)。

    谢谢您的回答!好吧,我试着玩了一下,但是没有结果。我可能没有得到什么。我的代码:我不知道为什么,但表示形式是2,应该是0或1(未定义/签名)。我也不确定是否正确地将(1)和另一个问题:我是否将DICOM图像的像素表示提取为dcmImage.getInterData()->getRepresentation()?相应地更新了我的答案
    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