当前位置: 首页>>代码示例>>C++>>正文


C++ Pointer::GetPixel方法代码示例

本文整理汇总了C++中inputimagetype::Pointer::GetPixel方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::GetPixel方法的具体用法?C++ Pointer::GetPixel怎么用?C++ Pointer::GetPixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inputimagetype::Pointer的用法示例。


在下文中一共展示了Pointer::GetPixel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: erosionOperation

//腐蚀操作
void segmentation::erosionOperation()//未用到
{
    const unsigned int Dimension = 3;
    typedef unsigned char   InputPixelType;
    typedef unsigned char   OutputPixelType;
    typedef itk::Image< InputPixelType,  Dimension >   InputImageType;
    typedef itk::Image< OutputPixelType, Dimension >   OutputImageType;
    typedef itk::ImageFileReader< InputImageType  >  ReaderType;
    typedef itk::ImageFileWriter< OutputImageType >  WriterType;
    typedef itk::BinaryThresholdImageFilter< InputImageType, InputImageType >  ThresholdFilterType;
    typedef itk::BinaryBallStructuringElement< 
        InputPixelType,
        Dimension  >             StructuringElementType;
    typedef itk::BinaryErodeImageFilter<
        InputImageType, 
        OutputImageType,
        StructuringElementType >  ErodeFilterType;
    ReaderType::Pointer reader = ReaderType::New();
    WriterType::Pointer writerErosion  = WriterType::New();
    ThresholdFilterType::Pointer thresholder = ThresholdFilterType::New();
    ErodeFilterType::Pointer  binaryErode  = ErodeFilterType::New();
    StructuringElementType  structuringElementErosion;
    reader->SetFileName( initFileName );//读入二值图
    reader->Update();
    InputImageType::Pointer inputImage = InputImageType::New();
    InputImageType::IndexType voxelIndex;
    inputImage = reader->GetOutput();
    InputImageType::SizeType imgSize = inputImage->GetLargestPossibleRegion().GetSize();
    long vol = 0;
    unsigned char temp;
    float r;
    for(int z = 0; z < imgSize[2]; z++)
        for(int y = 0; y < imgSize[1]; y++)
            for(int x = 0; x < imgSize[0]; x++)
            {
                voxelIndex[0] = x;
                voxelIndex[1] = y;
                voxelIndex[2] = z;
                temp = inputImage->GetPixel(voxelIndex);
                if(temp == 255)// 255 for PED
                    vol += 1;
            }
            r = pow((3 * vol) / (4 * PI), (1.0 / 3)) ;
            r = r / 20;//experiment data
            structuringElementErosion.SetRadius( r );  // 3x3 structuring element
            structuringElementErosion.CreateStructuringElement();
            binaryErode->SetKernel(  structuringElementErosion );
            //文件前缀名
            filePrefix = inputFileName;//char* to string
            filePrefix = filePrefix.substr(0, filePrefix.length() - 4);
            string erosionFileName;
            erosionFileName = filePrefix + "_erosionResult.mhd";
            strcpy(outputFileName, erosionFileName.c_str());//string to char*
            writerErosion->SetFileName(outputFileName);
            const InputPixelType lowerThreshold = 255;
            const InputPixelType upperThreshold = 255;
            thresholder->SetInput( reader->GetOutput() );
            InputPixelType background =   0;
            InputPixelType foreground = 255;
            thresholder->SetOutsideValue( background );
            thresholder->SetInsideValue(  foreground );
            thresholder->SetLowerThreshold( lowerThreshold );
            thresholder->SetUpperThreshold( upperThreshold );
            binaryErode->SetInput( thresholder->GetOutput() );
            binaryErode->SetErodeValue( foreground );
            writerErosion->SetInput( binaryErode->GetOutput() );
            writerErosion->Update();
            //binaryErode->GetOutput()->GetPixel(index);//获取像素值失败

            //腐蚀结果叠加到原图
            typedef itk::Image< unsigned short,  Dimension >   OriginalImageType;
            typedef itk::ImageFileReader<OriginalImageType>OriginalReaderType;
            OriginalReaderType::Pointer orignalImgreader = OriginalReaderType::New();
            OriginalImageType::Pointer originalImage = OriginalImageType::New();
            OriginalReaderType::IndexType originalImgVoxelIndex;
            reader->SetFileName(outputFileName);//读入腐蚀结果图像
            reader->Update();
            inputImage = reader->GetOutput();
            orignalImgreader->SetFileName(inputFileName);//读入原图像
            orignalImgreader->Update();
            originalImage = orignalImgreader->GetOutput();
            for(int z = 0; z < imgSize[2]; z++)
                for(int y = 0; y < imgSize[1]; y++)
                    for(int x = 0; x < imgSize[0]; x++)
                    {
                        voxelIndex[0] = x;
                        voxelIndex[1] = y;
                        voxelIndex[2] = z;
                        originalImgVoxelIndex[0] = x;
                        originalImgVoxelIndex[1] = y;
                        originalImgVoxelIndex[2] = z;
                        temp = inputImage->GetPixel(voxelIndex);
                        if(temp == 255)
                            originalImage->SetPixel(originalImgVoxelIndex, 65535);
                    }
                    //输出结果
                    typedef itk::ImageFileWriter<OriginalImageType>NewWriterType;
                    NewWriterType::Pointer writer = NewWriterType::New();
                    //文件前缀名
//.........这里部分代码省略.........
开发者ID:zlsunsuda,项目名称:QT-DEMO,代码行数:101,代码来源:segmentation.cpp

示例2: CastToItkImage

void mitk::SetRegionTool::OnMousePressed(StateMachineAction *, InteractionEvent *interactionEvent)
{
  auto *positionEvent = dynamic_cast<mitk::InteractionPositionEvent *>(interactionEvent);
  if (!positionEvent)
    return;

  m_LastEventSender = positionEvent->GetSender();
  m_LastEventSlice = m_LastEventSender->GetSlice();

  // 1. Get the working image
  Image::Pointer workingSlice = FeedbackContourTool::GetAffectedWorkingSlice(positionEvent);
  if (workingSlice.IsNull())
    return; // can't do anything without the segmentation

  // if click was outside the image, don't continue
  const BaseGeometry *sliceGeometry = workingSlice->GetGeometry();
  itk::Index<3> projectedPointIn2D;
  sliceGeometry->WorldToIndex(positionEvent->GetPositionInWorld(), projectedPointIn2D);
  if (!sliceGeometry->IsIndexInside(projectedPointIn2D))
  {
    MITK_ERROR << "point apparently not inside segmentation slice" << std::endl;
    return; // can't use that as a seed point
  }

  typedef itk::Image<DefaultSegmentationDataType, 2> InputImageType;
  typedef InputImageType::IndexType IndexType;
  typedef itk::ConnectedThresholdImageFilter<InputImageType, InputImageType> RegionGrowingFilterType;
  RegionGrowingFilterType::Pointer regionGrower = RegionGrowingFilterType::New();

  // convert world coordinates to image indices
  IndexType seedIndex;
  sliceGeometry->WorldToIndex(positionEvent->GetPositionInWorld(), seedIndex);

  // perform region growing in desired segmented region
  InputImageType::Pointer itkImage = InputImageType::New();
  CastToItkImage(workingSlice, itkImage);
  regionGrower->SetInput(itkImage);
  regionGrower->AddSeed(seedIndex);

  InputImageType::PixelType bound = itkImage->GetPixel(seedIndex);

  regionGrower->SetLower(bound);
  regionGrower->SetUpper(bound);
  regionGrower->SetReplaceValue(1);

  itk::BinaryFillholeImageFilter<InputImageType>::Pointer fillHolesFilter =
    itk::BinaryFillholeImageFilter<InputImageType>::New();

  fillHolesFilter->SetInput(regionGrower->GetOutput());
  fillHolesFilter->SetForegroundValue(1);

  // Store result and preview
  mitk::Image::Pointer resultImage = mitk::GrabItkImageMemory(fillHolesFilter->GetOutput());
  resultImage->SetGeometry(workingSlice->GetGeometry());
  // Get the current working color
  DataNode *workingNode(m_ToolManager->GetWorkingData(0));
  if (!workingNode)
    return;

  mitk::ImageToContourModelFilter::Pointer contourextractor = mitk::ImageToContourModelFilter::New();
  contourextractor->SetInput(resultImage);
  contourextractor->Update();

  mitk::ContourModel::Pointer awesomeContour = contourextractor->GetOutput();
  FeedbackContourTool::SetFeedbackContour(awesomeContour);
  FeedbackContourTool::SetFeedbackContourVisible(true);
  mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow());
}
开发者ID:liu3xing3long,项目名称:MITK,代码行数:68,代码来源:mitkSetRegionTool.cpp

示例3: on_abnormalRegionSegButton_clicked


//.........这里部分代码省略.........
    reader->Update();
    inputImage = reader->GetOutput();
    InputImageType::IndexType voxelIndex;
    InitOutputImageType::IndexType initvoxelIndex;
    OutputImageType::IndexType newvoxelIndex;
    InputImageType::SizeType imgSize = inputImage->GetLargestPossibleRegion().GetSize();
    OutputImageType::IndexType index;
    index[0] = 0;
    index[1] = 0;
    index[2] = 0;
    OutputImageType::SizeType size;
    size[0] = imgSize[0];
    size[1] = imgSize[1];
    size[2] = imgSize[2];
    //create a region for initial result
    InitOutputImageType::RegionType initRegion;
    initRegion.SetIndex(index);
    initRegion.SetSize(size);
    initOutputImage->SetRegions( initRegion);
    initOutputImage->Allocate();
    //create a region for enhance result
    OutputImageType::RegionType region;
    region.SetIndex(index);
    region.SetSize(size);
    outputImage->SetRegions(region);
    outputImage->Allocate();
    //Initial result for PED segmentation  (a binary image)
    for(int z = 0; z < imgSize[2]; z++)
        for(int x = 0; x < imgSize[0]; x++)
        {
            initvoxelIndex[0] = x;
            initvoxelIndex[2] = z;
            for(int y = 0; y < imgSize[1]; y++)
            {
                //set all background a black region
                initvoxelIndex[1] = y;
                initOutputImage->SetPixel(initvoxelIndex, 0);
            }
            //set the same intensity for all PED region (empirical value)
            if(p[z][x] == 1)
            {
                for(int y = s11[z][x]; y <= s12[z][x]; y++) 
                {
                    initvoxelIndex[1] = y;
                    initOutputImage->SetPixel(initvoxelIndex, 255);//亮区域
                }
            }
        }
        //输出中间分割结果
        //文件前缀名
        filePrefix = inputFileName;//char* to string
        filePrefix = filePrefix.substr(0, filePrefix.length() - 4);
        string strInitFileName;
        strInitFileName = filePrefix + "_initBinaryImg.mhd";
        strcpy(initFileName, strInitFileName.c_str());//string to char*
        typedef itk::ImageFileWriter<InitOutputImageType>InitWriterType;
        InitWriterType::Pointer initWriter = InitWriterType::New();
        initWriter->SetFileName(initFileName);//生成二值图
        initWriter->SetInput(initOutputImage);
        initWriter->Update();
        //Enhance PED region and overlay it on the original image
        for(int z = 0; z < imgSize[2]; z++)
            for(int x = 0; x < imgSize[0]; x++)
            {
                voxelIndex[0] = x;
                voxelIndex[2] = z;
                newvoxelIndex[0] = x;
                newvoxelIndex[2] = z;
                for(int y = 0; y < imgSize[1]; y++)
                {
                    voxelIndex[1] = y;
                    newvoxelIndex[1] = y;
                    outputImage->SetPixel(newvoxelIndex, inputImage->GetPixel(voxelIndex));
                }
                //set the same intensity for all PED region (empirical value)
                if(p[z][x] == 1)
                {
                    for(int y = s11[z][x]; y <= s12[z][x]; y++) 
                    {
                        newvoxelIndex[1] = y;
                        outputImage->SetPixel(newvoxelIndex, 65535);//亮区域
                    }
                }
            }
            //释放内存不能缺省
            delete[]s11;
            delete[]s12;
            delete[]p;

            typedef itk::ImageFileWriter<OutputImageType>WriterType;
            WriterType::Pointer writer = WriterType::New();
            filePrefix = filePrefix + "_initResult.mhd";
            strcpy(outputFileName, filePrefix.c_str());//string to char*
            initResultFileName = outputFileName;//输出初始分割结果,二值图重叠在原图像上面
            writer->SetFileName(outputFileName);
            writer->SetInput(outputImage);
            writer->Update();

            emit returnOutputFileName(outputFileName);//发出信号
}
开发者ID:zlsunsuda,项目名称:QT-DEMO,代码行数:101,代码来源:segmentation.cpp


注:本文中的inputimagetype::Pointer::GetPixel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。