Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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
Linux 如何编写qt应用程序来显示dcm图像?_Linux_Qt_Dicom - Fatal编程技术网

Linux 如何编写qt应用程序来显示dcm图像?

Linux 如何编写qt应用程序来显示dcm图像?,linux,qt,dicom,Linux,Qt,Dicom,我找到了一种使用vtk显示dcm图像的方法。但是vtk对我来说太多了,我只想显示一个dcm图像。dcmtk将为我处理dcm图像。 那么,有没有一种简单的方法来显示dcm图像呢? 提前感谢。最小的学习曲线和代码需求可能是使用基层DICOM。()此库将链接到Qt,并为您提供一种快速加载图像的方法。唯一需要记住的是,DICOM图像文件不包含Qt(或任何其他)可以直接显示的图像。您必须加载DICOM数据并转换图像以显示它 这些是要添加到项目文件中的行。请注意,路径必须匹配您的机器和版本,而不是我的

我找到了一种使用vtk显示dcm图像的方法。但是vtk对我来说太多了,我只想显示一个dcm图像。dcmtk将为我处理dcm图像。 那么,有没有一种简单的方法来显示dcm图像呢?
提前感谢。

最小的学习曲线和代码需求可能是使用基层DICOM。()此库将链接到Qt,并为您提供一种快速加载图像的方法。唯一需要记住的是,DICOM图像文件不包含Qt(或任何其他)可以直接显示的图像。您必须加载DICOM数据并转换图像以显示它

这些是要添加到项目文件中的行。请注意,路径必须匹配您的机器和版本,而不是我的

    #INCLUDEPATH += /usr/local/include/gdcm-2.4/
    #LIBS += -L"/usr/local/lib/" -lgdcmCommon -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMEXD -lgdcmMSFF -lgdcmjpeg12 -lgdcmjpeg16 -lgdcmopenjpeg -lgdcmjpeg8
    #LIBS += -L"/usr/local/lib/" -lgdcmcharls -lexpat -lgdcmzlib
这是一个示例转换器,一旦加载了dicom图像,它就会将其转换为Qt QImage

bool imageConverters::convertToFormat_RGB888(gdcm::Image const & gimage, char *buffer, QImage* &imageQt)
{
    unsigned int dimX;
    unsigned int dimY;
    int         photoInterp;

  const unsigned int* dimension = gimage.GetDimensions();

  if (dimension == 0)
  {
      dimX = 800;
      dimY = 600;
  }
    else
    {
        dimX = dimension[0];
        dimY = dimension[1];
   }
    gimage.GetBuffer(buffer);
    photoInterp = gimage.GetPhotometricInterpretation();

   qDebug() << "photo interp = " << photoInterp;
   qDebug() << "pixel format = " << gimage.GetPixelFormat();
    // Let's start with the easy case:

    if( photoInterp == gdcm::PhotometricInterpretation::RGB )
    {
        if( gimage.GetPixelFormat() != gdcm::PixelFormat::UINT8 )
        {
            return false;
        }
        unsigned char *ubuffer = (unsigned char*)buffer;
        // QImage::Format_RGB888  13  The image is stored using a 24-bit RGB format (8-8-8).Format_RGB888 Format_ARGB32
        imageQt = new QImage((unsigned char *)ubuffer, dimX, dimY, 3*dimX, QImage::Format_RGB888);
        //imageQt = &imageQt->rgbSwapped();
    }
    else
    if( photoInterp == gdcm::PhotometricInterpretation::MONOCHROME2 ||
            photoInterp == gdcm::PhotometricInterpretation::MONOCHROME1
            )
    {
        if( gimage.GetPixelFormat() == gdcm::PixelFormat::UINT8 || gimage.GetPixelFormat() == gdcm::PixelFormat::INT8
                || gimage.GetPixelFormat() == gdcm::PixelFormat::UINT16)
        {
            // We need to copy each individual 8bits into R / G and B:
            unsigned char *ubuffer = new unsigned char[dimX*dimY*3];
            unsigned char *pubuffer = ubuffer;
            for(unsigned int i = 0; i < dimX*dimY; i++)
            {
                *pubuffer++ = *buffer;
                *pubuffer++ = *buffer;
                *pubuffer++ = *buffer++;
            }

        imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);
    }
    else
    if( gimage.GetPixelFormat() == gdcm::PixelFormat::INT16 )
    {
      // We need to copy each individual 16bits into R / G and B (truncate value)
      short *buffer16 = (short*)buffer;
      unsigned char *ubuffer = new unsigned char[dimX*dimY*3];
      unsigned char *pubuffer = ubuffer;
      for(unsigned int i = 0; i < dimX*dimY; i++)
        {
        // Scalar Range of gdcmData/012345.002.050.dcm is [0,192], we could simply do:
        // *pubuffer++ = *buffer16;
        // *pubuffer++ = *buffer16;
        // *pubuffer++ = *buffer16;
        // instead do it right:
        *pubuffer++ = (unsigned char)std::min(255, (32768 + *buffer16) / 255);
        *pubuffer++ = (unsigned char)std::min(255, (32768 + *buffer16) / 255);
        *pubuffer++ = (unsigned char)std::min(255, (32768 + *buffer16) / 255);
        buffer16++;
        }

      imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);
      }
    else
      {
      std::cerr << "Pixel Format is: " << gimage.GetPixelFormat() << std::endl;
      return false;
      }
    }
  else
    {
    std::cerr << "Unhandled PhotometricInterpretation: " << gimage.GetPhotometricInterpretation() << std::endl;
    return false;
    }

  return true;
}
bool-imageConverters::convertToFormat_RGB888(gdcm::Image-const&gimage、char*buffer、QImage*&imageQt)
{
无符号整数dimX;
无符号整数dimY;
int photoInterp;
常量unsigned int*dimension=gimage.GetDimensions();
如果(维度==0)
{
dimX=800;
dimY=600;
}
其他的
{
dimX=尺寸[0];
dimY=尺寸[1];
}
gimage.GetBuffer(buffer);
photoInterp=gimage.GetPhotometricInterpretation();

qDebug()最小的学习曲线和代码要求可能是使用草根DICOM。()此库将链接到Qt,并为您提供一种快速加载图像的方法。唯一需要记住的是,DICOM图像文件不包含Qt(或任何其他)支持的图像可以直接显示。您必须加载DICOM数据并转换图像以显示它

这些是要添加到项目文件的行

    #INCLUDEPATH += /usr/local/include/gdcm-2.4/
    #LIBS += -L"/usr/local/lib/" -lgdcmCommon -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMEXD -lgdcmMSFF -lgdcmjpeg12 -lgdcmjpeg16 -lgdcmopenjpeg -lgdcmjpeg8
    #LIBS += -L"/usr/local/lib/" -lgdcmcharls -lexpat -lgdcmzlib
这是一个示例转换器,一旦加载了dicom图像,它就会将其转换为Qt QImage

bool imageConverters::convertToFormat_RGB888(gdcm::Image const & gimage, char *buffer, QImage* &imageQt)
{
    unsigned int dimX;
    unsigned int dimY;
    int         photoInterp;

  const unsigned int* dimension = gimage.GetDimensions();

  if (dimension == 0)
  {
      dimX = 800;
      dimY = 600;
  }
    else
    {
        dimX = dimension[0];
        dimY = dimension[1];
   }
    gimage.GetBuffer(buffer);
    photoInterp = gimage.GetPhotometricInterpretation();

   qDebug() << "photo interp = " << photoInterp;
   qDebug() << "pixel format = " << gimage.GetPixelFormat();
    // Let's start with the easy case:

    if( photoInterp == gdcm::PhotometricInterpretation::RGB )
    {
        if( gimage.GetPixelFormat() != gdcm::PixelFormat::UINT8 )
        {
            return false;
        }
        unsigned char *ubuffer = (unsigned char*)buffer;
        // QImage::Format_RGB888  13  The image is stored using a 24-bit RGB format (8-8-8).Format_RGB888 Format_ARGB32
        imageQt = new QImage((unsigned char *)ubuffer, dimX, dimY, 3*dimX, QImage::Format_RGB888);
        //imageQt = &imageQt->rgbSwapped();
    }
    else
    if( photoInterp == gdcm::PhotometricInterpretation::MONOCHROME2 ||
            photoInterp == gdcm::PhotometricInterpretation::MONOCHROME1
            )
    {
        if( gimage.GetPixelFormat() == gdcm::PixelFormat::UINT8 || gimage.GetPixelFormat() == gdcm::PixelFormat::INT8
                || gimage.GetPixelFormat() == gdcm::PixelFormat::UINT16)
        {
            // We need to copy each individual 8bits into R / G and B:
            unsigned char *ubuffer = new unsigned char[dimX*dimY*3];
            unsigned char *pubuffer = ubuffer;
            for(unsigned int i = 0; i < dimX*dimY; i++)
            {
                *pubuffer++ = *buffer;
                *pubuffer++ = *buffer;
                *pubuffer++ = *buffer++;
            }

        imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);
    }
    else
    if( gimage.GetPixelFormat() == gdcm::PixelFormat::INT16 )
    {
      // We need to copy each individual 16bits into R / G and B (truncate value)
      short *buffer16 = (short*)buffer;
      unsigned char *ubuffer = new unsigned char[dimX*dimY*3];
      unsigned char *pubuffer = ubuffer;
      for(unsigned int i = 0; i < dimX*dimY; i++)
        {
        // Scalar Range of gdcmData/012345.002.050.dcm is [0,192], we could simply do:
        // *pubuffer++ = *buffer16;
        // *pubuffer++ = *buffer16;
        // *pubuffer++ = *buffer16;
        // instead do it right:
        *pubuffer++ = (unsigned char)std::min(255, (32768 + *buffer16) / 255);
        *pubuffer++ = (unsigned char)std::min(255, (32768 + *buffer16) / 255);
        *pubuffer++ = (unsigned char)std::min(255, (32768 + *buffer16) / 255);
        buffer16++;
        }

      imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);
      }
    else
      {
      std::cerr << "Pixel Format is: " << gimage.GetPixelFormat() << std::endl;
      return false;
      }
    }
  else
    {
    std::cerr << "Unhandled PhotometricInterpretation: " << gimage.GetPhotometricInterpretation() << std::endl;
    return false;
    }

  return true;
}
bool-imageConverters::convertToFormat_RGB888(gdcm::Image-const&gimage、char*buffer、QImage*&imageQt)
{
无符号整数dimX;
无符号整数dimY;
int photoInterp;
常量unsigned int*dimension=gimage.GetDimensions();
如果(维度==0)
{
dimX=800;
dimY=600;
}
其他的
{
dimX=尺寸[0];
dimY=尺寸[1];
}
gimage.GetBuffer(buffer);
photoInterp=gimage.GetPhotometricInterpretation();
qDebug()@john elemans

如果我使用你给我的代码,它似乎是工作的。我的图像的像素格式是UINT16,因此程序将执行以下语句

        unsigned char *ubuffer = new unsigned char[dimX*dimY*3];
        unsigned char *pubuffer = ubuffer;
        for(unsigned int i = 0; i < dimX*dimY; i++)
        {
            *pubuffer++ = *buffer;
            *pubuffer++ = *buffer;
            *pubuffer++ = *buffer++;
        }

        imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);
unsigned char*ubuffer=新的unsigned char[dimX*dimY*3];
无符号字符*pubuffer=ubuffer;
for(无符号整数i=0;i
但在转换之后,结果是不正确的。
原始图像如下所示:
这是已转换的图像:
结果证明代码不正确。我还尝试了其他方法。我尝试过的代码之一是:

    short *buffer16 = (short*)buffer;
    unsigned char *ubuffer = new unsigned char[dimX*dimY*3];
    unsigned char *pubuffer = ubuffer;
    for (unsigned int i = 0; i < dimX*dimY; i++)
    {
         *pubuffer++ = *buffer16;
         *pubuffer++ = *buffer16;
         *pubuffer++ = *buffer16;
          buffer16++;
    }
    imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);
short*buffer16=(short*)缓冲区;
unsigned char*ubuffer=新的unsigned char[dimX*dimY*3];
无符号字符*pubuffer=ubuffer;
for(无符号整数i=0;i
在我用这个代码转换图像后,我几乎相信我已经成功了。但是结果是:对不起,我没有足够的声誉发布超过2个链接。
我只想将DICOM图像转换为位图,但不知道如何转换。 最后,谢谢你的帮助。

@john elemans
如果我使用你给我的代码,它似乎是工作的。我的图像的像素格式是UINT16,因此程序将执行以下语句

        unsigned char *ubuffer = new unsigned char[dimX*dimY*3];
        unsigned char *pubuffer = ubuffer;
        for(unsigned int i = 0; i < dimX*dimY; i++)
        {
            *pubuffer++ = *buffer;
            *pubuffer++ = *buffer;
            *pubuffer++ = *buffer++;
        }

        imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);
unsigned char*ubuffer=新的unsigned char[dimX*dimY*3];
无符号字符*pubuffer=ubuffer;
for(无符号整数i=0;i
但在转换之后,结果是不正确的。
原始图像如下所示:
这是已转换的图像:
结果证明代码不正确。我还尝试了其他方法。我尝试过的代码之一是:

    short *buffer16 = (short*)buffer;
    unsigned char *ubuffer = new unsigned char[dimX*dimY*3];
    unsigned char *pubuffer = ubuffer;
    for (unsigned int i = 0; i < dimX*dimY; i++)
    {
         *pubuffer++ = *buffer16;
         *pubuffer++ = *buffer16;
         *pubuffer++ = *buffer16;
          buffer16++;
    }
    imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);
short*buffer16=(short*)缓冲区;
unsigned char*ubuffer=新的unsigned char[dimX*dimY*3];
无符号字符*pubuffer=ubuffer;
for(无符号整数i=0;i
在我用这个代码转换图像后,我几乎相信我已经成功了。但是结果是:对不起,我没有足够的声誉发布超过2个链接。
我只想将DICOM图像转换为位图,但不知道如何转换。

最后,感谢您的帮助。

如果可能,请查看我自己的答案。谢谢。如果可能,请查看我自己的答案。谢谢。