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.<br>
<br>error (the error point is highlighted) :<br><br><i>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> </i><br>
<br>////////// mainwindow.cpp //////////////////<br>#include "mainwindow.h"<br>#include "ui_mainwindow.h"<br>#include "canvas.h"<br><br>#include "itkImage.h"<br>#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>#include "itkExtractImageFilter.h"<br>#include <itkSize.h><br><br>QString fileName;<br><br> unsigned long size_x;<br> unsigned long size_y;<br> unsigned long size_z;<br>
<br><br> typedef unsigned short PixelType;<br> const unsigned int Dimension = 3;<br> typedef itk::Image< PixelType, Dimension > InputImageType;<br><br> typedef itk::ImageFileReader< InputImageType > ReaderType;<br>
ReaderType::Pointer reader;<br><br><br>MainWindow::MainWindow(QWidget *parent) :<br> QMainWindow(parent),<br> ui(new Ui::MainWindow)<br>{<br> ui->setupUi(this);<br><br> ui->graphicsView_inputImage->setScene(scene=new Canvas());<br>
<br> connect(scene,SIGNAL(mousejustpressed(int,int)),this,SLOT(mousejustpressed(int,int)));<br><br> QObject::connect(ui->pushButton_openFile, SIGNAL(clicked()), this, SLOT(push_button_File()));<br><br> QObject::connect(ui->pushButton_slice_z, SIGNAL(clicked()), this, SLOT(z_slice_extract()));<br>
<br> connect(ui->verticalScrollBar_z, SIGNAL(valueChanged()), this, SLOT(()));<br><br> <br> typedef unsigned char InputPixelType;<br> typedef itk::Image< InputPixelType, 3 > InputImageType;<br>
typedef itk::ImageFileReader< InputImageType > ReaderType;<br> ReaderType::Pointer reader = ReaderType::New();<br>}<br><br>void MainWindow::push_button_File()<br>{<br> <br>///unsigned char to display in .png format<br>
<br> reader->SetFileName("C:/Users/......../test.png");<br> reader->Update();<br>}<br><br><br>void MainWindow::z_slice_extract()<br>{<br><br> <br>///unsigned char to display in .png format<br> typedef unsigned char InputPixelType;<br>
typedef unsigned char OutputPixelType;<br><br> typedef itk::Image< InputPixelType, 3 > InputImageType;<br> typedef itk::Image< OutputPixelType, 2 > OutputImageType;<br><br> typedef itk::ImageFileReader< InputImageType > ReaderType;<br>
typedef itk::ImageFileWriter< OutputImageType > WriterType;<br><br> <br> WriterType::Pointer writer = WriterType::New();<br><br> writer->SetFileName( "2D.png" );<br><br> <br> typedef itk::ExtractImageFilter< InputImageType, OutputImageType > FilterType;<br>
FilterType::Pointer filter = FilterType::New();<br><br><br> InputImageType::RegionType inputRegion =<br> reader->GetOutput()->GetLargestPossibleRegion();<br><br> InputImageType::SizeType size = inputRegion.GetSize();<br>
<br> // get the size of the hole 3D image<br> unsigned long size_x = size[0];<br> unsigned long size_y = size[1];<br> unsigned long size_z = size[2];<br> <br> // get slices of z coordiante<br> size[2] = 0; <br><br>
<br> InputImageType::IndexType start = inputRegion.GetIndex();<br> ui->verticalScrollBar_z->setRange(1,size_z);<br> unsigned int sliceNumber = ui->verticalScrollBar_z->value();<br> start[2] = sliceNumber;<br>
<br> <br><br> InputImageType::RegionType desiredRegion;<br> desiredRegion.SetSize( size );<br> desiredRegion.SetIndex( start );<br><br> filter->SetExtractionRegion( desiredRegion );<br><br> <span style="background-color: rgb(255, 255, 51);"> filter->SetInput( reader->GetOutput() );</span><br>
writer->SetInput( filter->GetOutput() );<br><br> try<br> {<br> writer->Update(); <br> }<br> catch( itk::ExceptionObject & err )<br> {<br> std::cerr << "ExceptionObject caught !" << std::endl;<br>
std::cerr << err << std::endl;<br> }<br><br><br> scene->addPixmap(QPixmap("2D.png"));<br> ui->graphicsView_inputImage->setScene(scene);<br> <br><br><br> // taking the size of the loaded image<br>
ui->label_4->setText(QString("size x:%1").arg(size_x));<br> ui->label_5->setText(QString("size y:%1").arg(size_y));<br> ui->label_6->setText(QString("size z:%1").arg(size_z));<br>
<br> return;<br>}<br><br><br><br><br><br>void MainWindow::mousejustpressed(int x,int y)<br>{<br> int k1=256-y;<br><br><br> unsigned char value;<br><br> QImage image(scene->sceneRect().size().toSize(), <br> QImage::Format_RGB32);<br>
<br> QPainter painter(&image);<br> scene->render(&painter);<br> <br> value=image.pixel(x,k1);<br> <br><br> /**QImage buffer = QImage(1,1, QImage::Format_RGB32);<br> QPainter painter(&buffer);<br>
scene->render(&painter, QRectF(0.0, 0.0, 1.0, 1.0), QRectF(x, y, 1.0, 1.0));<br> int value = qGray(buffer.pixel(0,0));<br> */<br><br> ui->label->setText(QString("x:%1").arg(x));<br> ui->label_2->setText(QString("y:%1").arg(k1));<br>
ui->label_3->setText(QString("pixel value:%1").arg(value));<br><br><br>}<br><br><br>MainWindow::~MainWindow()<br>{<br> delete ui;<br>}<br><br><br><br>////////////////// mainwindow.h //////////////<br>
#ifndef MAINWINDOW_H<br>#define MAINWINDOW_H<br><br>#include <QMainWindow><br>#include <QGraphicsScene><br>#include "canvas.h"<br><br>#include "itkImage.h"<br>#include "itkImageFileReader.h"<br>
<br>#include <qstring.h><br>#include <qdir.h><br>#include <qfiledialog.h><br>#include <qmessagebox.h><br>#include <qlabel.h><br>#include <qgraphicsScene.h><br><br>#include <QGraphicsPixmapItem><br>
<br><br><br><br>namespace Ui {<br> class MainWindow;<br>}<br><br>class MainWindow : public QMainWindow<br>{<br> Q_OBJECT<br><br> Canvas *scene;<br><br><br>public:<br> explicit MainWindow(QWidget *parent = 0);<br>
~MainWindow();<br><br>private:<br> Ui::MainWindow *ui;<br><br> public slots:<br> void mousejustpressed(int x,int y);<br><br> public slots:<br> void push_button_File();<br> void z_slice_extract();<br>
<br><br>};<br><br>#endif // MAINWINDOW_H<br><br><br><br><br><br>