Commit 6b11504e authored by saubatn's avatar saubatn
Browse files

FEATURE 193 Partial derivative properties updated.

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@1613 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 687d10a2
...@@ -64,21 +64,21 @@ AnisotropicDiffusion::AnisotropicDiffusion(ActionExtension * extension) : Action ...@@ -64,21 +64,21 @@ AnisotropicDiffusion::AnisotropicDiffusion(ActionExtension * extension) : Action
this->addTag("Perona and Malik"); this->addTag("Perona and Malik");
// Setting parameters default values by using properties // Setting parameters default values by using properties
this->addParameter(new Property(tr("Keep original image voxel type"), true, addParameter(new Property(tr("Keep original image voxel type"), true,
tr("Keep the original image voxel type ?"), "")); tr("Keep the original image voxel type ?"), ""));
Property* nbIterationProperty = new Property(tr("Number of iterations"), 5, 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. "), ""); 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("minimum", 1);
nbIterationProperty->setAttribute("maximum", 100); nbIterationProperty->setAttribute("maximum", 100);
nbIterationProperty->setAttribute("singleStep", 1); nbIterationProperty->setAttribute("singleStep", 1);
this->addParameter(nbIterationProperty); addParameter(nbIterationProperty);
Property* conductanceProperty = new Property(tr("Conductance"), 1.0, 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."), ""); 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("minimum", 0.10);
conductanceProperty->setAttribute("maximum", 10.00); conductanceProperty->setAttribute("maximum", 10.00);
conductanceProperty->setAttribute("singleStep", 0.05); conductanceProperty->setAttribute("singleStep", 0.05);
this->addParameter(conductanceProperty); addParameter(conductanceProperty);
Property* implementationProperty = new Property("Diffusion type", AnisotropicDiffusion::GRADIENT, Property* implementationProperty = new Property("Diffusion type", AnisotropicDiffusion::GRADIENT,
"The type of diffusion to use.", ""); "The type of diffusion to use.", "");
...@@ -86,7 +86,7 @@ AnisotropicDiffusion::AnisotropicDiffusion(ActionExtension * extension) : Action ...@@ -86,7 +86,7 @@ AnisotropicDiffusion::AnisotropicDiffusion(ActionExtension * extension) : Action
QStringList possibleValues; QStringList possibleValues;
possibleValues << "Gradient" << "Curvature"; possibleValues << "Gradient" << "Curvature";
implementationProperty->setAttribute("enumNames", possibleValues); implementationProperty->setAttribute("enumNames", possibleValues);
this->addParameter(implementationProperty); addParameter(implementationProperty);
} }
......
...@@ -91,5 +91,5 @@ protected: ...@@ -91,5 +91,5 @@ protected:
double conductance; double conductance;
}; };
Q_DECLARE_METATYPE(AnisotropicDiffusion::AnisoDiffType); Q_DECLARE_METATYPE(AnisotropicDiffusion::AnisoDiffType)
#endif // ANISOTROPICDIFFUSION_H #endif // ANISOTROPICDIFFUSION_H
...@@ -60,21 +60,21 @@ CannyEdgeDetection::CannyEdgeDetection(ActionExtension * extension) : Action(ext ...@@ -60,21 +60,21 @@ CannyEdgeDetection::CannyEdgeDetection(ActionExtension * extension) : Action(ext
// Setting parameters default values // Setting parameters default values
Property* keepOrgVoxelTypeProperty = new Property(tr("Keep original voxel type?"), true, tr("Does the output image have the same voxel type as the input one?"), ""); Property* keepOrgVoxelTypeProperty = new Property(tr("Keep original voxel type?"), true, tr("Does the output image have the same voxel type as the input one?"), "");
this->addParameter(keepOrgVoxelTypeProperty); addParameter(keepOrgVoxelTypeProperty);
Property* varianceProperty = new Property(tr("Variance"), 2.0, tr("The variance is used in the gaussian preprocessing step. \nThe higher the variance is, the less the edges detection will be noise sensitive."), ""); Property* varianceProperty = new Property(tr("Variance"), 2.0, tr("The variance is used in the gaussian preprocessing step. \nThe higher the variance is, the less the edges detection will be noise sensitive."), "");
varianceProperty->setAttribute("minimum", 0); varianceProperty->setAttribute("minimum", 0);
varianceProperty->setAttribute("maximum", 100); varianceProperty->setAttribute("maximum", 100);
varianceProperty->setAttribute("singleStep", 0.05); varianceProperty->setAttribute("singleStep", 0.05);
this->addParameter(varianceProperty); addParameter(varianceProperty);
Property* upperThresholdProperty = new Property(tr("Upper threshold"), 0.0, tr("The upper threshold is used at step 3 to determine whether a voxel belongs an edge or not. \nAbove, the voxel is detected as an edge.\nBelow and upper the low threshold, the voxel is accepted if it is connected to an edge voxel neighbor."), ""); Property* upperThresholdProperty = new Property(tr("Upper threshold"), 0.0, tr("The upper threshold is used at step 3 to determine whether a voxel belongs an edge or not. \nAbove, the voxel is detected as an edge.\nBelow and upper the low threshold, the voxel is accepted if it is connected to an edge voxel neighbor."), "");
upperThresholdProperty->setAttribute("singleStep", 0.1); upperThresholdProperty->setAttribute("singleStep", 0.1);
this->addParameter(upperThresholdProperty); addParameter(upperThresholdProperty);
Property* lowerThresholdProperty = new Property(tr("Lower threshold"), 0.0, tr("The lower threshold is used at step 3 to determine whether a voxel belongs an edge or not. \nAbove, and under the upper threshold the voxel is detected as an edge if it is connected to an edge voxel neighbor. \nBelow, the voxel is rejected."), ""); Property* lowerThresholdProperty = new Property(tr("Lower threshold"), 0.0, tr("The lower threshold is used at step 3 to determine whether a voxel belongs an edge or not. \nAbove, and under the upper threshold the voxel is detected as an edge if it is connected to an edge voxel neighbor. \nBelow, the voxel is rejected."), "");
lowerThresholdProperty->setAttribute("singleStep", 0.1); lowerThresholdProperty->setAttribute("singleStep", 0.1);
this->addParameter(lowerThresholdProperty); addParameter(lowerThresholdProperty);
} }
// --------------- destructor ------------------- // --------------- destructor -------------------
......
...@@ -24,17 +24,24 @@ ...@@ -24,17 +24,24 @@
****************************************************************************/ ****************************************************************************/
#include "Derivative.h" #include "Derivative.h"
// CamiTK includes
#include <Application.h> #include <Application.h>
#include <ItkProgressObserver.h> #include <ItkProgressObserver.h>
#include <QMessageBox> #include <Property.h>
#include <QString>
#include <QTextStream> // ITK includes
#include <itkImageToVTKImageFilter.h> #include <itkImageToVTKImageFilter.h>
#include <itkVTKImageToImageFilter.h> #include <itkVTKImageToImageFilter.h>
#include <itkCastImageFilter.h> #include <itkCastImageFilter.h>
#include <itkRescaleIntensityImageFilter.h> #include <itkRescaleIntensityImageFilter.h>
#include <itkDerivativeImageFilter.h> #include <itkDerivativeImageFilter.h>
// Qt includes
#include <QMessageBox>
#include <QString>
#include <QTextStream>
using namespace camitk; using namespace camitk;
...@@ -43,15 +50,19 @@ Derivative::Derivative(ActionExtension * extension) : Action(extension) { ...@@ -43,15 +50,19 @@ Derivative::Derivative(ActionExtension * extension) : Action(extension) {
// Setting name, description and input component // Setting name, description and input component
setName("Partial Derivative"); setName("Partial Derivative");
setDescription("<br><b>This filter is used for computing the <i>partial derivative</i> of an image.</b><br>\ setDescription("<br><b>This filter is used for computing the <i>partial derivative</i> of an image.</b><br>\
Choose the order of the derivative <br> \ <br><br> \
(0) Zero order: no derivation, <br> \ Choose the order of the derivative:\
(1) First order derivative <br> \ <ul> \
(2) Second order derivative, etc.<br> \ <li> Zero order: no derivation \
<br>\ <li> First order derivative \
Choose the direction of the derivative: <br> \ <li> Second order derivative \
(0): Derivative along X axis <br> \ </ul> \
(1): Derivative along Y axis <br> \ Choose the direction of the derivative:\
(2): Derivative along Z axis <br>\ <ul> \
<li> Derivative along X axis \
<li> Derivative along Y axis \
<li> Derivative along Z axis \
</ul> \
"); ");
setComponent("ImageComponent"); setComponent("ImageComponent");
...@@ -62,14 +73,22 @@ Derivative::Derivative(ActionExtension * extension) : Action(extension) { ...@@ -62,14 +73,22 @@ Derivative::Derivative(ActionExtension * extension) : Action(extension) {
this->addTag("Contours"); this->addTag("Contours");
// Setting parameters default values // Setting parameters default values
setProperty("keepOriginalImageVoxelType", QVariant(true)); Property* keepOrgVoxelTypeProperty = new Property(tr("Keep original voxel type?"), true, tr("Does the output image have the same voxel type as the input one?"), "");
setProperty("derivativeOrder", QVariant(1)); addParameter(keepOrgVoxelTypeProperty);
setProperty("direction", QVariant(0));
Property* derivativeOrderProperty = new Property(tr("Derivative order"), ORDER_0, tr("The derivative order of the partial derivative along the selected direction (x, y, z)."), "");
keepOrgVoxelType = true; derivativeOrderProperty->setEnumTypeName("derivativeOrder");
derivativeOrder = 1; QStringList derivativeOrderValues;
direction = 0; derivativeOrderValues << "0th order: no derivation" << "1st order derivative" << "2nd order derivative";
derivativeOrderProperty->setAttribute("enumNames", derivativeOrderValues);
addParameter(derivativeOrderProperty);
Property* directionProperty = new Property(tr("Direction"), DIRECTION_X, tr("The direction of the partial derivative."), "");
directionProperty->setEnumTypeName("derivativeDirection");
QStringList directionValues;
directionValues << "Along X axis" << "Along Y axis" << "Along Z axis";
directionProperty->setAttribute("enumNames", directionValues);
addParameter(directionProperty);
} }
// --------------- destructor ------------------- // --------------- destructor -------------------
...@@ -81,27 +100,16 @@ Derivative::~Derivative() { ...@@ -81,27 +100,16 @@ Derivative::~Derivative() {
Action::ApplyStatus Derivative::apply() { Action::ApplyStatus Derivative::apply() {
foreach (Component *comp, getTargets()) { foreach (Component *comp, getTargets()) {
ImageComponent * input = dynamic_cast<ImageComponent *> ( comp ); ImageComponent * input = dynamic_cast<ImageComponent *> ( comp );
process(input); this->process(input);
} }
return SUCCESS; return SUCCESS;
} }
void Derivative::process(ImageComponent * comp) { void Derivative::process(ImageComponent * comp) {
// Get the parameters // Get the parameters
keepOrgVoxelType = property("keepOriginalImageVoxelType").toBool(); this->keepOrgVoxelType = property("Keep original voxel type?").toBool();
derivativeOrder = property("derivativeOrder").toInt(); this->order = property("Derivative order").toInt();
direction = property("direction").toInt(); this->direction = property("Direction").toInt();
if (((derivativeOrder < 0) || (derivativeOrder > 5)) ||
((direction < 0) || (direction > 2 ))) {
QString msg;
QTextStream in(&msg);
in << "Derivative order should be positive and most reasonnably sammler to 5." << endl;
in << "direction should be 0 (x), 1 (y) or 2(z). " << endl;
QMessageBox::warning(NULL, "Action Called", msg);
return;
}
// ITK filter implementation using templates // ITK filter implementation using templates
vtkSmartPointer<vtkImageData> inputImage = comp->getImageData(); vtkSmartPointer<vtkImageData> inputImage = comp->getImageData();
...@@ -110,7 +118,6 @@ void Derivative::process(ImageComponent * comp) { ...@@ -110,7 +118,6 @@ void Derivative::process(ImageComponent * comp) {
QTextStream(&newName) << comp->getName() << "_processed"; QTextStream(&newName) << comp->getName() << "_processed";
new ImageComponent(outputImage, newName); new ImageComponent(outputImage, newName);
Application::refresh(); Application::refresh();
} }
#include "Derivative.impl" #include "Derivative.impl"
...@@ -169,8 +176,8 @@ vtkSmartPointer<vtkImageData> Derivative::itkProcess(vtkSmartPointer<vtkImageDat ...@@ -169,8 +176,8 @@ vtkSmartPointer<vtkImageData> Derivative::itkProcess(vtkSmartPointer<vtkImageDat
observer->Reset(); observer->Reset();
derivativeFilter->SetInput(toDoubleFilter->GetOutput()); derivativeFilter->SetInput(toDoubleFilter->GetOutput());
derivativeFilter->SetOrder(derivativeOrder); derivativeFilter->SetOrder(this->order);
derivativeFilter->SetDirection(direction); derivativeFilter->SetDirection(this->direction);
derivativeFilter->AddObserver(itk::ProgressEvent(), observer); derivativeFilter->AddObserver(itk::ProgressEvent(), observer);
derivativeFilter->Update(); derivativeFilter->Update();
observer->Reset(); observer->Reset();
......
...@@ -39,8 +39,19 @@ ...@@ -39,8 +39,19 @@
* *
**/ **/
class Derivative : public camitk::Action { class Derivative : public camitk::Action {
Q_OBJECT
/// Enumerations
Q_ENUMS( derivativeOrder )
Q_ENUMS( derivativeDirection )
public: public:
/// The 3 different possible derivative orders
enum derivativeOrder { ORDER_0, ORDER_1, ORDER_2 };
/// The direction of the derivative
enum derivativeDirection { DIRECTION_X, DIRECTION_Y, DIRECTION_Z };
/// Default Constructor /// Default Constructor
Derivative(camitk::ActionExtension *); Derivative(camitk::ActionExtension *);
...@@ -82,7 +93,10 @@ protected: ...@@ -82,7 +93,10 @@ protected:
int direction; int direction;
/// The order of the derivative. /// The order of the derivative.
int derivativeOrder; int order;
}; };
Q_DECLARE_METATYPE(Derivative::derivativeOrder)
Q_DECLARE_METATYPE(Derivative::derivativeDirection)
#endif // DERIVATIVE_H #endif // DERIVATIVE_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