itkImageToVtkImageFilter returns ObjectBase

@tim-evain

I’m sorry that i ask you the same type question again…

Based on your explanation, I tried to use itk::Image as a member of class, but it cannot be displayed by QuickView.
This is my code:

constexpr unsigned int Dimension = 2;
using PixelType = unsigned char;
using ImageType = itk::Image< PixelType, Dimension >;

class Program {
public:
    Program();
    explicit Program(const std::string& filename);

    virtual ~Program();

    Program(const Program& other);
    Program& operator=(const Program& other);

    void ReadImage();
    itk::SmartPointer<ImageType> GetImage();

private:
    const std::string _filename;
    itk::SmartPointer<ImageType> _image;
};
void Program::ReadImage()
{
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName(this->_filename);

    this->_image = reader->GetOutput();
}

itk::SmartPointer<ImageType> Program::GetImage()
{
    return this->_image;
}

int main(int argc, char *argv[])
{

    if (argc < 2) {
        std::cerr << "Invalid Usage!" << std::endl;
        std::cerr << "Usage: " << argv[0] << ", {filename}.dcm" << std::endl;
        return EXIT_FAILURE;
    }

    Program program(argv[1]);
    program.ReadImage();
    QuickView q;
    q.AddImage(program.GetImage().GetPointer());
    q.Visualize();
    return EXIT_SUCCESS;
}

I tried

private:
    ImageType::Pointer _image;

But this also doesn’t work.

I’m so sorry to ask about same question, but i wanna your help
please help me