天天看点

《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();