<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>Problem implementing GradientAnisotropicDiffusionImageFilter</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2> Hi,<BR>
I am new to ITK. I have just started changing some of my post-processing tools from MATLAB to ITK (Version 3.12). So far I have only had one issue that I cannot solve and that is implementing GradientAnisotropicDiffusionImageFilter. I can workaround this issue but would rather get to the bottom of my problem as I suspect that I am missing something fundamental about data type in ITK. I have read pertinent sections of ITK Software Guide 2nd Edition (dated 11/21/05) and template guide on www.itk.org.<BR>
I am processing data obtained on a prototype CT system and am processing in order to eventually segment between one tissue type (approx linear attenuation coefficient 0.024 per mm) from another (approx attenuation coefficient 0.031 per mm). Setting parameters of 5 iterations, timestep of 0.125 and conductance 0.003, there is minimal filtering when using following ITK program (i.e. not consistent with conductance parameter). Using same values and same test input file in MATLAB, I do get reasonable output. If I take another test input file scaled up by 10000 (both data values and conductance - i.e. approx data coefficients 240 per mm and 310 per mm and conductance 30), I do obtain reasonable results with the same ITK program (as well as MATLAB program with only change in conductance). <BR>
As pixel type is float in either case, I cannot understand why the GradientAnisotropicDiffusionImageFilter does not work with both range of data values in ITK as it does in MATLAB. While I can perform scaling to workaround my ITK issue, as stated, I suspect that I am doing something wrong in ITK and would rather correct my misunderstanding. I would greatly appreciate any comments or suggestions.<BR>
<BR>
Regards,<BR>
Michael O'Connor<BR>
<BR>
/*=========================================================================<BR>
<BR>
Program: ITKFilterTest<BR>
Module: ITKFilterTest.cxx<BR>
Language: C++<BR>
Date: 24 Nov 2009<BR>
Version: Revision: 1.0 Mike O'Connor<BR>
<BR>
=========================================================================*/<BR>
<BR>
// NOTE: much of this code and description is taken directly from ITK documentation. Module initially based<BR>
// on the Filter Example modules in ITK source code.<BR>
// The module runs one ITK filter.<BR>
//<BR>
// Filter 1: is ITK GradientAnisotropicDiffusionImageFilter. This filter implements an<BR>
// N-dimensional version of the classic Perona-Malik anisotropic diffusion<BR>
// equation for scalar-valued images (Perona 1990).<BR>
//<BR>
// The conductance term for this implementation is chosen as a function of the<BR>
// gradient magnitude of the image at each point, reducing the strength of<BR>
// diffusion at edge pixels.<BR>
//<BR>
// The numerical implementation of this equation is similar to that described<BR>
// in the Perona-Malik paper, but uses a more robust technique<BR>
// for gradient magnitude estimation and has been generalized to N-dimensions.<BR>
// Input Parameters for this implementation are passed using a 'config file'. Objects and methods for the<BR>
// config file are based on CBSS. There are booleans to determine if one or both of the filters are run.<BR>
// The input parameters for each filter as well as parameters for file reader.<BR>
<BR>
<BR>
#include "itkImage.h"<BR>
#include "itkImageFileReader.h"<BR>
#include "itkImageFileWriter.h"<BR>
#include "itkRawImageIO.h"<BR>
#include "itkGradientAnisotropicDiffusionImageFilter.h"<BR>
#include "FilterSystem.h"<BR>
#include "Filter.h"<BR>
#include "Files.h"<BR>
#include "Message.h"<BR>
<BR>
<BR>
<BR>
const unsigned int Dimension = 2;<BR>
<BR>
int main( int argc, char * argv[] )<BR>
{<BR>
// This is structure for our config file (used for parameter passing)<BR>
FilterSystem f_system;<BR>
WhatFunction function = Filter; <BR>
if(parseArgs(argc,argv) == UtilError) return EXIT_FAILURE;<BR>
if(f_system.initialize(function, usage) == UtilError)closeAndExit(EXIT_FAILURE);<BR>
<BR>
typedef float InputPixelType;<BR>
typedef float OutputPixelType;<BR>
<BR>
//<BR>
// Instatiate using input & output image types<BR>
//<BR>
typedef itk::Image<<BR>
InputPixelType, <BR>
Dimension > InputImageType;<BR>
typedef itk::Image<<BR>
OutputPixelType,<BR>
Dimension > OutputImageType;<BR>
typedef itk::ImageFileReader<<BR>
InputImageType > ReaderType;<BR>
typedef itk::GradientAnisotropicDiffusionImageFilter<<BR>
InputImageType,<BR>
OutputImageType > ADF_FilterType;<BR>
typedef itk::RawImageIO<<BR>
InputPixelType,<BR>
Dimension > ImageIOType;<BR>
typedef itk::ImageFileWriter<<BR>
OutputImageType > WriterType; <BR>
//<BR>
// Filter object, Image object and Reader & Writer object are created<BR>
//<BR>
ImageIOType::Pointer rawIO = ImageIOType::New();<BR>
ReaderType::Pointer reader = ReaderType::New();<BR>
ADF_FilterType::Pointer ADfilter = ADF_FilterType::New();<BR>
WriterType::Pointer writer2 = WriterType::New();<BR>
<BR>
// Get parameters from config file<BR>
rawIO->SetHeaderSize(f_system.m_cfg.header); <BR>
rawIO->SetDimensions(0, f_system.m_cfg.file_dim_x);<BR>
rawIO->SetDimensions(1, f_system.m_cfg.file_dim_y);<BR>
rawIO->SetByteOrderToLittleEndian();<BR>
<BR>
// Define Input file<BR>
writeMsg(DEBUG1, "Input File: %s \n",files.input);<BR>
reader->SetFileName( files.input );<BR>
reader->SetImageIO( rawIO );<BR>
// reader->Update(); //Read the file<BR>
//<BR>
//Get other parameters from Config file<BR>
const unsigned int numberOfIterations = f_system.m_cfg.iter;<BR>
const double timeStep = (double) f_system.m_cfg.timestep;<BR>
const double conductance = (double) f_system.m_cfg.conductance;<BR>
writeMsg(DEBUG1,"Version 2: Iterations = %i, Timestep = %f, Conductance = %f \n", numberOfIterations, timeStep, conductance);<BR>
<BR>
//Set Parameters in ADF Filter & invoke filter<BR>
ADfilter->SetInput( reader->GetOutput() );<BR>
ADfilter->SetNumberOfIterations( numberOfIterations );<BR>
ADfilter->SetTimeStep( timeStep );<BR>
ADfilter->SetConductanceParameter( conductance );<BR>
ADfilter->Update();<BR>
<BR>
//<BR>
// Write the output file<BR>
//<BR>
writer2->SetImageIO (rawIO);<BR>
writer2->SetFileName( files.output );<BR>
writer2->SetInput( ADfilter->GetOutput() );<BR>
writeMsg(DEBUG1, "Writing output of the AnisoDiff to output File: %s \n",files.output);<BR>
writer2->Update();<BR>
return EXIT_SUCCESS;<BR>
<BR>
}<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>