Commit b7cb5cfb authored by saubatn's avatar saubatn
Browse files

FEATURE 193 All CamiTK::Property.

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@1609 ec899d31-69d1-42ba-9299-647d76f65fb3
parent c1cd56eb
......@@ -36,6 +36,10 @@
#include <itkRescaleIntensityImageFilter.h>
#include <itkGradientAnisotropicDiffusionImageFilter.h>
#include <itkCurvatureAnisotropicDiffusionImageFilter.h>
#include <QVariant>
// CamiTK includes
#include <Property.h>
using namespace camitk;
......@@ -48,7 +52,7 @@ AnisotropicDiffusion::AnisotropicDiffusion(ActionExtension * extension) : Action
<p>The numberOfIterations parameter specifies the number of iterations (time-step updates) that the solver will perform to produce a solution image. The appropriate number of iterations is dependent on the application and the image being processed. As a general rule, the more iterations performed, the more diffused the image will become.</p> \
<p>The conductance parameter controls the sensitivity of the conductance term in the basic anisotropic diffusion equation. It affect the conductance term in different ways depending on the particular variation on the basic equation. As a general rule, the lower the value, the more strongly the diffusion equation preserves image features (such as high gradients or curvature). A high value for conductance will cause the filter to diffuse image features more readily. Typical values range from 0.5 to 2.0 for data like the Visible Human color data, but the correct value for your application is wholly dependent on the results you want from a specific data set and the number or iterations you perform.</p> \
<p>The <i>Gradient</i> anisotropic diffusion implements an N-dimensional version of the classic Perona-Malik anisotropic diffusion equation for scal-valued images.</p> \
<p>The <i>Curvature</i> anisotrpic diffusion performs anisotropic diffusion on an image using a modified curvature diffusion equation (MCDE). MCDE does not exhibit the edge enhancing properties of classic anisotropic diffusion, which can under certain conditions undergo a <i>negative</i> diffusion, which enhances the contrast of edges. Equations of the form MCDE always undergo positive diffusion, with the conductance term only varying the stregth of that diffusion.</p> \
<p>The <i>Curvature</i> anisotropic diffusion performs anisotropic diffusion on an image using a modified curvature diffusion equation (MCDE). MCDE does not exhibit the edge enhancing properties of classic anisotropic diffusion, which can under certain conditions undergo a <i>negative</i> diffusion, which enhances the contrast of edges. Equations of the form MCDE always undergo positive diffusion, with the conductance term only varying the stregth of that diffusion.</p> \
");
setComponent("ImageComponent");
......@@ -59,12 +63,31 @@ AnisotropicDiffusion::AnisotropicDiffusion(ActionExtension * extension) : Action
this->addTag("Blur");
this->addTag("Perona and Malik");
// Setting parameters default values
setProperty("keepOriginalImageVoxelType", QVariant(true));
keepOrgVoxelType = true;
setProperty("numberOfIterations", QVariant(5));
setProperty("conductance", QVariant(1.0));
this->implementation = Curvature;
// Setting parameters default values by using properties
this->addParameter(new Property(tr("Keep original image voxel type"), true,
tr("Keep the original image voxel type ?"), ""));
Property* nbIterationProperty = new Property(tr("Number of iterations"), 5,
tr("The more iterations, the more smoothing. \nEach iteration takes the same amount of time. \nIf it takes 10 seconds for one iteration, then it will take 100 seconds for 10 iterations. \nNote that the conductance controls how much each iteration smooths across edges. "), "");
nbIterationProperty->setAttribute("minimum", 1);
nbIterationProperty->setAttribute("maximum", 100);
nbIterationProperty->setAttribute("singleStep", 1);
this->addParameter(nbIterationProperty);
Property* conductanceProperty = new Property(tr("Conductance"), 1.0,
tr("Conductance controls the sensitivity of the conductance term. \nAs a general rule, the lower the value, the more strongly the filter preserves edges. \nA high value will cause diffusion (smoothing) across edges. \nNote that the number of iterations controls how much smoothing is done within regions bounded by edges."), "");
conductanceProperty->setAttribute("minimum", 0.10);
conductanceProperty->setAttribute("maximum", 10.00);
conductanceProperty->setAttribute("singleStep", 0.05);
this->addParameter(conductanceProperty);
Property* implementationProperty = new Property("Diffusion type", AnisotropicDiffusion::GRADIENT,
"The type of diffusion to use.", "");
implementationProperty->setEnumTypeName("AnisoDiffType");
QStringList possibleValues;
possibleValues << "Gradient" << "Curvature";
implementationProperty->setAttribute("enumNames", possibleValues);
this->addParameter(implementationProperty);
}
// --------------- destructor -------------------
......@@ -72,12 +95,8 @@ AnisotropicDiffusion::~AnisotropicDiffusion() {
// do not delete the widget has it might have been used in the ActionViewer (i.e. the ownership might have been taken by the stacked widget)
}
AnisotropicDiffusion::AnisoDiffType AnisotropicDiffusion::getMethod() {
return this->implementation;
}
void AnisotropicDiffusion::setMethod(AnisotropicDiffusion::AnisoDiffType implementation) {
this->implementation = implementation;
AnisotropicDiffusion::AnisoDiffType AnisotropicDiffusion::getDiffusionType() {
return (AnisotropicDiffusion::AnisoDiffType) property("Diffusion type").toInt();
}
......@@ -90,11 +109,13 @@ Action::ApplyStatus AnisotropicDiffusion::apply() {
return SUCCESS;
}
// --------------- process -------------------
void AnisotropicDiffusion::process(ImageComponent * comp) {
// Get the parameters
keepOrgVoxelType = property("keepOriginalImageVoxelType").toBool();
numberOfIterations = property("numberOfIterations").toInt();
conductance = property("conductance").toDouble();
this->keepOrgVoxelType = property("Keep original image voxel type").toBool();
std::cout << "AnisotropicDiffusion::process : reading properties " << keepOrgVoxelType << std::endl;
this->numberOfIterations = property("Number of iterations").toInt();
this->conductance = property("Conductance").toDouble();
// ITK filter implementation using templates
vtkSmartPointer<vtkImageData> inputImage = comp->getImageData();
......@@ -103,7 +124,6 @@ void AnisotropicDiffusion::process(ImageComponent * comp) {
QTextStream(&newName) << comp->getName() << "_anisoDiff";
new ImageComponent(outputImage, newName);
Application::refresh();
}
#include "AnisotropicDiffusion.impl"
......@@ -113,12 +133,12 @@ template <class InputPixelType, class OutputPixelType, const int dim>
vtkSmartPointer<vtkImageData> AnisotropicDiffusion::itkProcess(vtkSmartPointer<vtkImageData> img) {
vtkSmartPointer<vtkImageData> outputImage = vtkSmartPointer<vtkImageData>::New();
switch (getMethod()) {
switch (this->getDiffusionType()) {
default:
case AnisotropicDiffusion::Gradient:
case AnisotropicDiffusion::GRADIENT:
outputImage = itkProcessGradientAnisotropicDiffusion<InputPixelType, OutputPixelType, dim>(img);
break;
case AnisotropicDiffusion::Curvature:
case AnisotropicDiffusion::CURVATURE:
outputImage = itkProcessCurvatureAnisotropicDiffusion<InputPixelType, OutputPixelType, dim>(img);
break;
}
......@@ -323,3 +343,5 @@ vtkSmartPointer<vtkImageData> AnisotropicDiffusion::itkProcessCurvatureAnisotrop
return result;
}
......@@ -44,12 +44,9 @@ class AnisotropicDiffusion : public camitk::Action {
/// Enumerations
Q_ENUMS( AnisoDiffType )
Q_PROPERTY( AnisoDiffType implementation READ getMethod WRITE setMethod)
public:
/// Define the possible implementations of Gaussian filtering
enum AnisoDiffType {Gradient, Curvature };
enum AnisoDiffType {GRADIENT, CURVATURE};
/// Default Constructor
AnisotropicDiffusion(camitk::ActionExtension * );
......@@ -65,8 +62,12 @@ public slots:
*/
virtual ApplyStatus apply();
AnisoDiffType getMethod();
void setMethod(AnisoDiffType implementation);
/**
* @brief Get the diffusion type to be used by the algorithm.
* @return The diffusion type as an enum.
* @note The diffusion type uses camitk::Property with its ENUM.
*/
AnisoDiffType getDiffusionType();
private:
......@@ -91,4 +92,6 @@ protected:
AnisoDiffType implementation;
};
Q_DECLARE_METATYPE(AnisotropicDiffusion::AnisoDiffType);
#endif // ANISOTROPICDIFFUSION_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment