天天看點

《itk實用demo》-寫位圖

寫位圖
typedef itk::Image<unsigned char, >  UnsignedCharImageType;
    typedef itk::CastImageFilter< ImageType, UnsignedCharImageType> CastFilterType;
    CastFilterType::Pointer castFilter = CastFilterType::New();
    castFilter->SetInput(flipFilter->GetOutput());
    castFilter->Update();
    //cout<<"獲得灰階區間"<<endl;
    typedef itk::StatisticsImageFilter<ImageType> StatisticsImageFilterType;
    StatisticsImageFilterType::Pointer statisticsImageFilter = StatisticsImageFilterType::New ();
    statisticsImageFilter->SetInput(castFilter->GetOutput());
    statisticsImageFilter->Update();
    signed int pRange[]; //這裡會有負值
    pRange[] = statisticsImageFilter->GetMinimum();
    pRange[] = statisticsImageFilter->GetMaximum();
    std::cout<<"pRange[0] "<<pRange[]<<endl;
    std::cout<<"pRange[1]"<<pRange[]<<endl;
    typedef  itk::ImageFileWriter< UnsignedCharImageType  > CharWriterType;
    CharWriterType::Pointer writer = CharWriterType::New();
    writer->SetFileName("D:\\img\\333result.png");
    writer->SetInput(castFilter->GetOutput());
    writer->Update();