Hello, I tried to add region-grow feature, but I couldn't embed it in the software.
CheerfulMinions opened this issue · 2 comments
First of all, thank you very much for your last reply!
I've been trying to add region-grow for a while now, but I'm having a bit of a problem.
As you can see, in my code below, I was forced to load the image file by reading the file name.
Of course, I tried to map the file by using the GuidedNativeImageIO pointer, and then using CastNativeImage as a CurvatureFlowImageFilter input. But this can only be used when reading the main image. When the main image is loaded, the IO pointer is removed... I wouldn't be able to use it as a CurvatureFlowImageFilter input.
I read the relevant source code, but I don't know how to transform m_mainImageWrapper CurvatureFlowImageFilterType: : Pointer input at the same time how to shows on the screen? Do I need to convert the data format?
I am looking forward to your reply.
Here is my complete code:
#include "itkConfidenceConnectedImageFilter.h"
#include "itkImage.h"
#include "itkCastImageFilter.h"
#include "itkCurvatureFlowImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "ImageWrapperBase.h"
static void testFunc(std::string filename) {
typedef float InternalPixelType;
// 3 or 4
const unsigned int Dimension = 3;
typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::CastImageFilter< InternalImageType, OutputImageType > CastingFilterType;
CastingFilterType::Pointer caster = CastingFilterType::New();
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
typedef itk::ImageFileReader< InternalImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);
writer->SetFileName("E:\\DATA\\tmp\\output001.mha");
typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType > CurvatureFlowImageFilterType;
CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New();
typedef itk::ConfidenceConnectedImageFilter<InternalImageType, InternalImageType> ConnectedFilterType;
ConnectedFilterType::Pointer confidenceConnected = ConnectedFilterType::New();
ImageWrapperBase::FloatImageType* tmp = reader->GetOutput();
smoothing->SetInput(tmp);
//smoothing->SetInput(filename);
confidenceConnected->SetInput(smoothing->GetOutput());
caster->SetInput(confidenceConnected->GetOutput());
writer->SetInput(caster->GetOutput());
smoothing->SetNumberOfIterations(2);
smoothing->SetTimeStep(0.05);
confidenceConnected->SetMultiplier(2.5);
confidenceConnected->SetNumberOfIterations(5);
confidenceConnected->SetInitialNeighborhoodRadius(2);
confidenceConnected->SetReplaceValue(6);
InternalImageType::IndexType indexSeed1;
// m_Driver->GetCursorPosition()
indexSeed1[0] = atoi("56");
indexSeed1[1] = atoi("116");
indexSeed1[2] = atoi("118");
confidenceConnected->AddSeed(indexSeed1);
try
{
writer->Update();
}
catch (itk::ExceptionObject& excep)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
}
You shouldn't be worrying about reading images since it should be done by the snap IO logic. Please see this line and the file for how to use image data loaded by snap.
Any UI feature should be done in the "Application-Model-UI" framework. In your case, the image should already be loaded to the Application
layer. And your backend logic should be created in the Model
layer, providing API's for the UI
layer to complete tasks.
Your Model
layer is responsible to reference the Application
layer object IRISApplication
to retrieve loaded data and complete tasks, and present the result by pushing it back to the application.