MITK Tutorial (三)
Step 2: Use the template with the plugins to read a image
在exampleplugin插件中QmitkAwesomeView.cpp中添加头文件
//Mitk
#include "mitkImageCast.h"
//Itk
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkMeanImageFilter.h"
在DoImageProcessing函数中 修改如下:用ITK::image 从文件中读图 经过中值滤波器处理并转成mitk::image加到DATA note 中
void QmitkAwesomeView::DoImageProcessing()
{
const unsigned int Dimension = 3;
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
typedef itk::Image< InputPixelType, Dimension > InputImageType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
QList<mitk::DataNode::Pointer> nodes = this->GetDataManagerSelection();
if (nodes.empty()) return;
mitk::DataNode::Pointer node = nodes.front();
if (!node)
{
// Nothing selected. Inform the user and return
QMessageBox::information( NULL, "Template", "Please load and select an image before starting image processing.");
return;
}
// here we have a valid mitk::DataNode
// a node itself is not very useful, we need its data item (the image)
mitk::BaseData* data = node->GetData();
if (data)
{
// test if this data item is an image or not (could also be a surface or something totally different)
mitk::Image* image = dynamic_cast<mitk::Image*>( data );
if (image)
{
std::stringstream message;
std::string name;
message << "Performing image processing for image ";
if (node->GetName(name))
{
// a property called "name" was found for this DataNode
message << "'" << name << "'";
}
message << ".";
MITK_INFO << message.str();
// actually do something here...
InputImageType::Pointer inputItkImage = InputImageType::New();
if(image)
{
CastToItkImage( image, inputItkImage );//OK, now you can use inputItkImage whereever you want
cout<<"this is normal itk image!"<<endl;
}
typedef itk::MeanImageFilter<
InputImageType, OutputImageType > FilterType;
FilterType::Pointer filter = FilterType::New();
InputImageType::SizeType indexRadius;
indexRadius[0] = 1; // radius along x
indexRadius[1] = 1; // radius along y
indexRadius[2] = 1;// radius along z
filter->SetRadius( indexRadius );
filter->SetInput( inputItkImage);
filter->Update();
// use the AwesomeImageFilter class from the MyAwesomeLib module
/*AwesomeImageFilter::Pointer awesomeFilter = AwesomeImageFilter::New();
awesomeFilter->SetInput(image);
awesomeFilter->SetOffset(m_Controls.spinboxOffset->value());
awesomeFilter->Update();
std::stringstream outputNodeName;
outputNodeName << node->GetName() << " offset by " << m_Controls.spinboxOffset->value();*/
mitk::Image::Pointer outputImage = mitk::Image::New();
mitk::CastToMitkImage(filter->GetOutput(), outputImage);
mitk::DataNode::Pointer outputNode = mitk::DataNode::New();
outputNode->SetData(outputImage);
outputNode->SetName("1");
this->GetDataStorage()->Add(outputNode);
}
}