[Insight-users] unexpectided error using extract image filter

john smith mkitkinsightuser at gmail.com
Tue May 31 09:02:14 EDT 2011


I am using vs 2010 but , I found my mistake. In the declaration of global
variable QString

Thanks

2011/5/31 Dženan Zukić <dzenanz at gmail.com>

> Your reader has TPixel=unsigned short and your filter has TPixel=unsigned
> char. It has to be the same (both either char or short). Which compiler are
> you using? VS2008 and VS2010 report these types in the error message.
>
> HTH
>
> On Tue, May 31, 2011 at 10:49, john smith <mkitkinsightuser at gmail.com>wrote:
>
>> Hello, I am running the extract image filter, but I use two functions, one
>> for loading the reader and one for use the ExtractImageFilter. The error and
>> the cofe follows. I hope somebody could help me as I can't understand what
>> is wrong. I also use Qt, but the problem I think in  ITK code.
>>
>> error (the error point is highlighted) :
>>
>> *error C2664: 'void
>> itk::ImageToImageFilter<TInputImage,TOutputImage>::SetInput(const
>> itk::Image<TPixel,VImageDimension> *)' : cannot convert parameter 1 from
>> 'itk::Image<TPixel,VImageDimension> *' to 'const
>> itk::Image<TPixel,VImageDimension> *
>>
>> ////////// mainwindow.cpp //////////////////
>> #include "mainwindow.h"
>> #include "ui_mainwindow.h"
>> #include "canvas.h"
>>
>> #include "itkImage.h"
>> #include "itkImageFileReader.h"
>> #include "itkImageFileWriter.h"
>> #include "itkExtractImageFilter.h"
>> #include <itkSize.h>
>>
>> QString fileName;
>>
>>   unsigned long size_x;
>>   unsigned long size_y;
>>   unsigned long size_z;
>>
>>
>>       typedef unsigned short PixelType;
>>      const unsigned int Dimension = 3;
>>     typedef itk::Image< PixelType, Dimension > InputImageType;
>>
>>     typedef itk::ImageFileReader< InputImageType > ReaderType;
>>     ReaderType::Pointer reader;
>>
>>
>> MainWindow::MainWindow(QWidget *parent) :
>>     QMainWindow(parent),
>>     ui(new Ui::MainWindow)
>> {
>>     ui->setupUi(this);
>>
>>     ui->graphicsView_inputImage->setScene(scene=new Canvas());
>>
>>
>> connect(scene,SIGNAL(mousejustpressed(int,int)),this,SLOT(mousejustpressed(int,int)));
>>
>>     QObject::connect(ui->pushButton_openFile, SIGNAL(clicked()), this,
>> SLOT(push_button_File()));
>>
>>     QObject::connect(ui->pushButton_slice_z, SIGNAL(clicked()), this,
>> SLOT(z_slice_extract()));
>>
>>     connect(ui->verticalScrollBar_z, SIGNAL(valueChanged()), this,
>> SLOT(()));
>>
>>
>>    typedef unsigned char        InputPixelType;
>>   typedef itk::Image< InputPixelType,  3 >    InputImageType;
>>   typedef itk::ImageFileReader< InputImageType  >  ReaderType;
>>   ReaderType::Pointer reader = ReaderType::New();
>> }
>>
>> void MainWindow::push_button_File()
>> {
>>
>> ///unsigned char to display in .png format
>>
>>   reader->SetFileName("C:/Users/......../test.png");
>>   reader->Update();
>> }
>>
>>
>> void MainWindow::z_slice_extract()
>> {
>>
>>
>> ///unsigned char to display in .png format
>>   typedef unsigned char        InputPixelType;
>>   typedef unsigned char        OutputPixelType;
>>
>>   typedef itk::Image< InputPixelType,  3 >    InputImageType;
>>   typedef itk::Image< OutputPixelType, 2 >    OutputImageType;
>>
>>   typedef itk::ImageFileReader< InputImageType  >  ReaderType;
>>   typedef itk::ImageFileWriter< OutputImageType >  WriterType;
>>
>>
>>   WriterType::Pointer writer = WriterType::New();
>>
>>   writer->SetFileName( "2D.png" );
>>
>>
>>   typedef itk::ExtractImageFilter< InputImageType, OutputImageType >
>> FilterType;
>>   FilterType::Pointer filter = FilterType::New();
>>
>>
>>   InputImageType::RegionType inputRegion =
>>            reader->GetOutput()->GetLargestPossibleRegion();
>>
>>   InputImageType::SizeType size = inputRegion.GetSize();
>>
>>   // get the size of the hole 3D image
>>   unsigned long size_x = size[0];
>>   unsigned long size_y = size[1];
>>   unsigned long size_z = size[2];
>>
>>   // get slices of z coordiante
>>   size[2] = 0;
>>
>>
>>   InputImageType::IndexType start = inputRegion.GetIndex();
>>   ui->verticalScrollBar_z->setRange(1,size_z);
>>   unsigned int sliceNumber = ui->verticalScrollBar_z->value();
>>   start[2] = sliceNumber;
>>
>>
>>
>>   InputImageType::RegionType desiredRegion;
>>   desiredRegion.SetSize( size );
>>   desiredRegion.SetIndex( start );
>>
>>   filter->SetExtractionRegion( desiredRegion );
>>
>>   filter->SetInput( reader->GetOutput() );
>>   writer->SetInput( filter->GetOutput() );
>>
>>       try
>>     {
>>     writer->Update();
>>     }
>>     catch( itk::ExceptionObject & err )
>>     {
>>     std::cerr << "ExceptionObject caught !" << std::endl;
>>     std::cerr << err << std::endl;
>>     }
>>
>>
>>      scene->addPixmap(QPixmap("2D.png"));
>>           ui->graphicsView_inputImage->setScene(scene);
>>
>>
>>
>>     // taking the size of the loaded image
>>     ui->label_4->setText(QString("size x:%1").arg(size_x));
>>     ui->label_5->setText(QString("size y:%1").arg(size_y));
>>     ui->label_6->setText(QString("size z:%1").arg(size_z));
>>
>>     return;
>> }
>>
>>
>>
>>
>>
>> void MainWindow::mousejustpressed(int x,int y)
>> {
>>     int k1=256-y;
>>
>>
>>     unsigned char value;
>>
>>     QImage image(scene->sceneRect().size().toSize(),
>>     QImage::Format_RGB32);
>>
>>     QPainter painter(&image);
>>     scene->render(&painter);
>>
>>     value=image.pixel(x,k1);
>>
>>
>>     /**QImage buffer = QImage(1,1, QImage::Format_RGB32);
>>     QPainter painter(&buffer);
>>     scene->render(&painter, QRectF(0.0, 0.0, 1.0, 1.0), QRectF(x, y, 1.0,
>> 1.0));
>>     int value = qGray(buffer.pixel(0,0));
>>     */
>>
>>     ui->label->setText(QString("x:%1").arg(x));
>>     ui->label_2->setText(QString("y:%1").arg(k1));
>>     ui->label_3->setText(QString("pixel value:%1").arg(value));
>>
>>
>> }
>>
>>
>> MainWindow::~MainWindow()
>> {
>>     delete ui;
>> }
>>
>>
>>
>> ////////////////// mainwindow.h //////////////
>> #ifndef MAINWINDOW_H
>> #define MAINWINDOW_H
>>
>> #include <QMainWindow>
>> #include <QGraphicsScene>
>> #include "canvas.h"
>>
>> #include "itkImage.h"
>> #include "itkImageFileReader.h"
>>
>> #include <qstring.h>
>> #include <qdir.h>
>> #include <qfiledialog.h>
>> #include <qmessagebox.h>
>> #include <qlabel.h>
>> #include <qgraphicsScene.h>
>>
>> #include <QGraphicsPixmapItem>
>>
>>
>>
>>
>> namespace Ui {
>>     class MainWindow;
>> }
>>
>> class MainWindow : public QMainWindow
>> {
>>     Q_OBJECT
>>
>>      Canvas *scene;
>>
>>
>> public:
>>     explicit MainWindow(QWidget *parent = 0);
>>     ~MainWindow();
>>
>> private:
>>     Ui::MainWindow *ui;
>>
>>     public slots:
>>     void mousejustpressed(int x,int y);
>>
>>         public slots:
>>         void push_button_File();
>>         void z_slice_extract();
>>
>>
>> };
>>
>> #endif // MAINWINDOW_H
>>
>>
>>
>>
>>
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110531/5e969ef0/attachment.htm>


More information about the Insight-users mailing list