From fd7fe88962bece8d68d850acac8474ee440a1f7d Mon Sep 17 00:00:00 2001 From: bharath Date: Fri, 9 Apr 2010 09:47:58 +0000 Subject: [PATCH] *** empty log message *** --- filters/clitkMedianImageGenericFilter.cxx | 15 ++ filters/clitkMedianImageGenericFilter.h | 85 +++++++++++ filters/clitkMedianImageGenericFilter.txx | 126 ++++++++++++++++ tools/clitkMedianImageFilter.cxx | 47 ++++++ tools/clitkMedianImageFilter.ggo | 12 ++ vv/qt_ui/vvToolMedianFilter.ui | 82 ++++++++++ vv/vvToolMedianFilter.cxx | 174 ++++++++++++++++++++++ vv/vvToolMedianFilter.h | 77 ++++++++++ 8 files changed, 618 insertions(+) create mode 100644 filters/clitkMedianImageGenericFilter.cxx create mode 100644 filters/clitkMedianImageGenericFilter.h create mode 100644 filters/clitkMedianImageGenericFilter.txx create mode 100644 tools/clitkMedianImageFilter.cxx create mode 100644 tools/clitkMedianImageFilter.ggo create mode 100644 vv/qt_ui/vvToolMedianFilter.ui create mode 100644 vv/vvToolMedianFilter.cxx create mode 100644 vv/vvToolMedianFilter.h diff --git a/filters/clitkMedianImageGenericFilter.cxx b/filters/clitkMedianImageGenericFilter.cxx new file mode 100644 index 0000000..1a766a0 --- /dev/null +++ b/filters/clitkMedianImageGenericFilter.cxx @@ -0,0 +1,15 @@ +#ifndef clitkMedianImageGenericFilter_cxx +#define clitkMedianImageGenericFilter_cxx + +/* ================================================= + * @file clitkMedianImageGenericFilter.cxx + * @author Bharath Navalpakkam + * @date 20.03.2010 + * + * @brief + * + ===================================================*/ + +#include "clitkMedianImageGenericFilter.h" + +#endif //#define clitkMedianImageGenericFilter_cxx diff --git a/filters/clitkMedianImageGenericFilter.h b/filters/clitkMedianImageGenericFilter.h new file mode 100644 index 0000000..8dee470 --- /dev/null +++ b/filters/clitkMedianImageGenericFilter.h @@ -0,0 +1,85 @@ +/*========================================================================= + + Program: clitk + Module: $RCSfile: clitkMedianImageGenericFilter.h,v $ + Language: C++ + Date: $Date: 2010/04/09 09:50:04 $ + Version: $Revision: 1.1 $ + Author : Bharath Navalpakkam + Copyright (C) 2010 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + +#ifndef CLITKMEDIANIMAGEGENERICFILTER_H +#define CLITKMEDIANIMAGEGENERICFILTER_H + +// clitk include +#include "clitkIO.h" +#include "clitkCommon.h" +#include "clitkImageToImageGenericFilter.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + + template + class ITK_EXPORT MedianImageGenericFilter: + public ImageToImageGenericFilter > + { + + public: + + //-------------------------------------------------------------------- + MedianImageGenericFilter(); + + //-------------------------------------------------------------------- + typedef MedianImageGenericFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //-------------------------------------------------------------------- + // Method for creation through the object factory + // and Run-time type information (and related methods) + itkNewMacro(Self); + itkTypeMacro(MedianImageGenericFilter, LightObject); + + //-------------------------------------------------------------------- + void SetArgsInfo(const args_info_type & a); + + //-------------------------------------------------------------------- + // Main function called each time the filter is updated + template + void UpdateWithInputImageType(); + + + + + protected: + template void InitializeImageType(); + + args_info_type mArgsInfo; + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkMedianImageGenericFilter.txx" +#endif + +#endif // #define clitkMedianImageGenericFilter_h diff --git a/filters/clitkMedianImageGenericFilter.txx b/filters/clitkMedianImageGenericFilter.txx new file mode 100644 index 0000000..29a316c --- /dev/null +++ b/filters/clitkMedianImageGenericFilter.txx @@ -0,0 +1,126 @@ +#ifndef clitkMedianImageGenericFilter_txx +#define clitkMedianImageGenericFilter_txx + +/* ================================================= + * @file clitkMedianImageGenericFilter.txx + * @author Bharath Navalapakkam + * @date 20 March 2010 + * + * @brief + * + ===================================================*/ + +// itk include +#include "itkMedianImageFilter.h" +#include "itkImage.h" + +namespace clitk +{ + + //-------------------------------------------------------------------- + template + MedianImageGenericFilter::MedianImageGenericFilter(): + ImageToImageGenericFilter("MedianImage") { + InitializeImageType<2>(); + InitializeImageType<3>(); + InitializeImageType<4>(); + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + template + template + void MedianImageGenericFilter::InitializeImageType() { + ADD_IMAGE_TYPE(Dim, char); + ADD_IMAGE_TYPE(Dim, uchar); + ADD_IMAGE_TYPE(Dim, short); + ADD_IMAGE_TYPE(Dim, int); + ADD_IMAGE_TYPE(Dim, float); + ADD_IMAGE_TYPE(Dim, double); + ADD_IMAGE_TYPE(Dim, unsigned short); + + + } + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + template + void MedianImageGenericFilter::SetArgsInfo(const args_info_type & a) { + mArgsInfo=a; + SetIOVerbose(mArgsInfo.verbose_flag); + + + if (mArgsInfo.input_given) { + SetInputFilename(mArgsInfo.input_arg); + } + if (mArgsInfo.output_given) { + SetOutputFilename(mArgsInfo.output_arg); + } + + + } + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // Update with the number of dimensions and the pixeltype + //-------------------------------------------------------------------- + template + template + void + MedianImageGenericFilter::UpdateWithInputImageType() + { + // Reading input + typename InputImageType::Pointer input = this->template GetInput(0); +// Typedef + typedef typename InputImageType::PixelType PixelType; + + + + + // typedef itk::Image OutputImageType; + + // Main filter + + typedef itk::Image OutputImageType; + class InputImageType::SizeType indexRadius; + + // Filter + typedef itk::MedianImageFilter MedianImageFilterType; + + + typename MedianImageFilterType::Pointer thresholdFilter=MedianImageFilterType::New(); + thresholdFilter->SetInput(input); + + +indexRadius[0]=mArgsInfo.radius_arg[0]; +indexRadius[1]=mArgsInfo.radius_arg[1]; +indexRadius[2]=mArgsInfo.radius_arg[2]; + + + + +// indexRadius[0] = 1; + // indexRadius[1] = 1; + +thresholdFilter->SetRadius( indexRadius ); + + + typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput(); + thresholdFilter->Update(); + + // Write/Save results + this->template SetNextOutput(outputImage); + + + } + + //-------------------------------------------------------------------- + +}//end clitk + + + +#endif //#define clitkMedianImageGenericFilter_txx + diff --git a/tools/clitkMedianImageFilter.cxx b/tools/clitkMedianImageFilter.cxx new file mode 100644 index 0000000..7c8dcc8 --- /dev/null +++ b/tools/clitkMedianImageFilter.cxx @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + ------------------------------------------------------------------------*/ + +/* ================================================= + * @file clitkMedianImageGenericFilter.txx + * @author Bharath Navalpakkam + * @date 18 March 2010 + * + * @brief Apply Median Filter to an Image + * + ===================================================*/ + +// clitk +#include "clitkMedianImageFilter_ggo.h" +#include "clitkMedianImageGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkMedianImageFilter, args_info); + CLITK_INIT; + + // Filter + clitk::MedianImageGenericFilter::Pointer filter = + clitk::MedianImageGenericFilter::New(); + + + filter->SetOutputFilename(args_info.output_arg); + + filter->SetArgsInfo(args_info); + + filter->Update(); + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkMedianImageFilter.ggo b/tools/clitkMedianImageFilter.ggo new file mode 100644 index 0000000..ffa8228 --- /dev/null +++ b/tools/clitkMedianImageFilter.ggo @@ -0,0 +1,12 @@ +#File clitkMedianImageFilter.ggo +package "clitkMedianImageFilter" +version "1.0" +purpose "" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "radius" r "Radius in each Direction" int multiple no default="1" + + diff --git a/vv/qt_ui/vvToolMedianFilter.ui b/vv/qt_ui/vvToolMedianFilter.ui new file mode 100644 index 0000000..fe31b04 --- /dev/null +++ b/vv/qt_ui/vvToolMedianFilter.ui @@ -0,0 +1,82 @@ + + + vvToolMedianFilter + + + + 0 + 0 + 735 + 290 + + + + Mean Filter + + + + + + + + X Radius + + + + + + + Qt::Horizontal + + + + + + + + + + + + + Y Radius + + + + + + + Qt::Horizontal + + + + + + + + + + + + + Z Radius + + + + + + + Qt::Horizontal + + + + + + + + + + + + + diff --git a/vv/vvToolMedianFilter.cxx b/vv/vvToolMedianFilter.cxx new file mode 100644 index 0000000..0d69855 --- /dev/null +++ b/vv/vvToolMedianFilter.cxx @@ -0,0 +1,174 @@ + /*========================================================================= + + Program: vv + Module: $RCSfile: vvToolMedianFilter.cxx,v $ + Language: C++ + Date: $Date: 2010/04/09 09:53:27 $ + Version: $Revision: 1.1 $ + Author : Bharath Navalpakkam (Bharath.Navalpakkam@creatis.insa-lyon.fr) + + Copyright (C) 2010 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + + #include "vvToolMedianFilter.h" + #include "vvSlicerManager.h" + #include "vvSlicer.h" + #include "vvToolInputSelectorWidget.h" + #include + + + //------------------------------------------------------------------------------ + // Create the tool and automagically + ADD_TOOL(vvToolMedianFilter); + //------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ + vvToolMedianFilter::vvToolMedianFilter(vvMainWindowBase * parent, Qt::WindowFlags f) + :vvToolWidgetBase(parent,f), + vvToolBase(parent), + Ui::vvToolMedianFilter() + { + + // Setup the UI + + Ui_vvToolMedianFilter::setupUi(mToolWidget); + + mFilter = new clitk::MedianImageGenericFilter; + + + + // Main filter + + // Set how many inputs are needed for this tool + AddInputSelector("Select one image", mFilter); + } + + //------------------------------------------------------------------------------ + vvToolMedianFilter::~vvToolMedianFilter() { + } + //------------------------------------------------------------------------------ + + + + void vvToolMedianFilter::Initialize() { + SetToolName("MedianFilter"); + SetToolMenuName("MedianFilter"); + SetToolIconFilename(":/new/prefix1/icons/ducky.png"); + SetToolTip("Make 'MedianFilter' on an image."); + } + //------------------------------------------------------------------------------ + + void vvToolMedianFilter::apply() { + + GetArgsInfoFromGUI(); + + if (!mCurrentSlicerManager) close(); + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + // Main filter + clitk::MedianImageGenericFilter::Pointer filter = + clitk::MedianImageGenericFilter::New(); + + + filter->SetInputVVImage(mCurrentImage); + filter->SetArgsInfo(mArgsInfo); + + filter->EnableReadOnDisk(false); + filter->Update(); + + + // Output + vvImage::Pointer output = filter->GetOutputVVImage(); + std::ostringstream osstream; + osstream << "MedianFiltered_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd"; + AddImage(output,osstream.str()); + QApplication::restoreOverrideCursor(); + close(); + + + } + + //------------------------------------------------------------------------------ + + void vvToolMedianFilter::GetArgsInfoFromGUI() { + + /* //KEEP THIS FOR READING GGO FROM FILE + int argc=1; + std::string a = "toto"; + char * const* argv = new char*; + //a.c_str(); + struct cmdline_parser_params p; + p.check_required = 0; + int good = cmdline_parser_ext(argc, argv, &args_info, &p); + DD(good); + */ + mArgsInfo.radius_given=0; + mArgsInfo.verbose_flag = false; + // mArgsInfo.radius_arg = new int[3]; + + // Required (even if not used) + mArgsInfo.input_given = 0; + mArgsInfo.output_given = 0; + + mArgsInfo.input_arg=new char; + mArgsInfo.output_arg = new char; + + + mArgsInfo.config_given=0; + mArgsInfo.verbose_given=0; + + + // mArgsInfo.radius_arg[0]=1; + // mArgsInfo.radius_arg[1]=1; + // mArgsInfo.radius_arg[2]=1; + + } + //------------------------------------------------------------------------------ +void vvToolMedianFilter::InputIsSelected(vvSlicerManager *m){ + mCurrentSlicerManager =m; + // Specific for this gui + + mArgsInfo.radius_arg = new int[3]; + connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(UpdatevalueH1())); + connect(horizontalSlider_2, SIGNAL(valueChanged(int)), this, SLOT(UpdatevalueH2())); + connect(horizontalSlider_3, SIGNAL(valueChanged(int)), this, SLOT(UpdatevalueH3())); + + + +} + + //----------------------------------------------------------------------------- + +void vvToolMedianFilter::UpdatevalueH1() +{ + mArgsInfo.radius_arg[0]=horizontalSlider->value(); + QString string1 = QString::number(mArgsInfo.radius_arg[0]); + lineEdit->setText(string1); +} +void vvToolMedianFilter::UpdatevalueH2() +{ + mArgsInfo.radius_arg[1]=horizontalSlider_2->value(); + QString string2 = QString::number(mArgsInfo.radius_arg[1]); + lineEdit_2->setText(string2); +} +void vvToolMedianFilter::UpdatevalueH3() +{ + mArgsInfo.radius_arg[2]=horizontalSlider_3->value(); + QString string3 = QString::number(mArgsInfo.radius_arg[2]); + lineEdit_3->setText(string3); + +} diff --git a/vv/vvToolMedianFilter.h b/vv/vvToolMedianFilter.h new file mode 100644 index 0000000..c569a19 --- /dev/null +++ b/vv/vvToolMedianFilter.h @@ -0,0 +1,77 @@ + /*========================================================================= + + Program: vv + Module: $RCSfile: vvToolMedianFilter.h,v $ + Language: C++ + Date: $Date: 2010/04/09 09:53:50 $ + Version: $Revision: 1.1 $ + Author : Bharath Navalpakkam (Bharath.Navalpakkam@creatis.insa-lyon.fr) + + Copyright (C) 2010 + Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + CREATIS http://www.creatis.insa-lyon.fr + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + =========================================================================*/ + + #ifndef VVTOOLMedianFilter_H + #define VVTOOLMedianFilter_H + + #include + #include "vvToolBase.h" + #include "QDialog" + #include "vvToolWidgetBase.h" + #include "ui_vvToolMedianFilter.h" + #include "clitkMedianImageFilter_ggo.h" + #include + + + //------------------------------------------------------------------------------ + class vvToolMedianFilter: + public vvToolWidgetBase, + public vvToolBase, + private Ui::vvToolMedianFilter + { + Q_OBJECT + public: + vvToolMedianFilter(vvMainWindowBase* parent=0, Qt::WindowFlags f=0); + ~vvToolMedianFilter(); + + static void Initialize(); + virtual void GetArgsInfoFromGUI(); + virtual void InputIsSelected(vvSlicerManager * m); + virtual void apply(); + + + public slots: + void UpdatevalueH1(); + void UpdatevalueH2(); + void UpdatevalueH3(); + + + + + + + protected: + + Ui::vvToolMedianFilter ui; + args_info_clitkMedianImageFilter mArgsInfo; + + + }; // end class vvToolMedianFilter + //------------------------------------------------------------------------------ + + #endif + -- 2.45.2