qq_33905610
赤坂
采纳率100%
2021-04-03 16:39

itk读取dicom文件转imagetype处理后转vtk在qvtkwidget显示问题

50

itk读取了dicom文件,存入imagetype进行二值化处理后有存入vtk中调用qvtkwidget显示,图片没有变化

 using ImageType = itk::Image<PixelType, Dimension>;
    using ReaderFileType = itk::ImageFileReader<ImageType>;
    ReaderFileType::Pointer DICOMReader = ReaderFileType::New();
    DICOMReader->SetFileName(file);
    using ImageIOType = itk::GDCMImageIO;
    ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
    DICOMReader->SetImageIO(gdcmImageIO);
    DICOMReader->Update();
ImageType::Pointer image = DICOMReader->GetOutput();
    ImageType::SizeType size = image->GetLargestPossibleRegion().GetSize();
    int dims[3];
    dims[0] = (int)(size[0]);
    dims[1] = (int)(size[1]);
    dims[2] = (int)(size[2]);
    for (int k = 0; k < dims[2]; k++)
    {
        for (int j = 0; j < dims[1]; j++)
        {
            for (int i = 0; i < dims[0]; i++)
            {
                ImageType::IndexType  point_temp;
                point_temp[0] = i;
                point_temp[1] = j;
                point_temp[2] = k;
                ImageType::PixelType value = image->GetPixel(point_temp);
                if (value != 0)
                {
                    image->SetPixel(point_temp, 255);
                }
                else
                {
                    image->SetPixel(point_temp, 0);
                }
            }
        }
    }
    image->Update();
    using ImageConnector = itk::ImageToVTKImageFilter<ImageType>;
    ImageConnector::Pointer VTKImage = ImageConnector::New();
    VTKImage->SetInput(image);
    VTKImage->Update();
    vtkImageFlip* FLIPImage = vtkImageFlip::New();
    FLIPImage->SetInputData(VTKImage->GetOutput());
    FLIPImage->SetFilteredAxis(1);//y轴为1,x轴为0,z轴为2;
    FLIPImage->Update();
    qvtkWidget->show();
    imgViewer->SetInputConnection(FLIPImage->GetOutputPort()); //将读取的对象显示出来
    imgViewer->SetColorWindow(atoi(valueWindowWidth.c_str()));//设置窗宽
    imgViewer->SetColorLevel(atoi(valueWindowCenter.c_str()));//设置窗位
    imgViewer->SetSliceOrientationToXY(); //设置切片方向为XY
    imgViewer->SetSlice((int)imgViewer->GetSliceMax() * 0.5); //将图片定位到中间切片
    imgViewer->GetRenderer()->SetBackground(0.0, 0.0, 0.0); //背景
    imgViewer->Render();
    imgViewer->GetRenderer()->ResetCamera();
    imgViewer->Render();

 qvtkWidget,imgViewer是.h文件中的变量,用来连接qt和显示

  • 点赞
  • 收藏
  • 复制链接分享

1条回答

  • qq_33905610 赤坂 13天前

    qvtk和imgviewer的定义

     

    点赞 评论 复制链接分享