├── .gitignore ├── CMakeLists.txt ├── GADFilterDialog.cpp ├── GADFilterDialog.h ├── GADFilterDialog.ui ├── MedianFilterDialog.ui ├── README ├── external ├── itkImageToVTKImageFilter.h ├── itkImageToVTKImageFilter.txx ├── itkVTKImageToImageFilter.h └── itkVTKImageToImageFilter.txx ├── imageviewer.cpp ├── imageviewer.h ├── imagewidget.cpp ├── imagewidget.h ├── main.cpp ├── medianFilterDialog.cpp └── medianFilterDialog.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.o 4 | *.so 5 | 6 | # Packages # 7 | ############ 8 | # it's better to unpack these files and commit the raw source 9 | # git has its own built in compression methods 10 | *.dmg 11 | *.gz 12 | *.iso 13 | *.rar 14 | *.tar 15 | *.zip 16 | 17 | # OS generated files # 18 | ###################### 19 | .DS_Store 20 | DS_Store 21 | Thumbs.db 22 | 23 | # netbeans generated directories # 24 | ###################### 25 | nbproject/ 26 | 27 | # CMake generated files and folders # 28 | ##################### 29 | CMakeFiles/ 30 | CMakeCache.txt 31 | ImageViewer 32 | Makefile 33 | cmake_install.cmake 34 | 35 | # Qt generated files # 36 | ###################### 37 | moc*.* 38 | 39 | # Build folders # 40 | ###################### 41 | build* 42 | 43 | # Other archives # 44 | ###################### 45 | .gitignore 46 | 47 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(ImageViewer) 2 | 3 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 4 | 5 | IF(COMMAND CMAKE_POLICY) 6 | CMAKE_POLICY(SET CMP0003 NEW) 7 | ENDIF(COMMAND CMAKE_POLICY) 8 | 9 | FIND_PACKAGE(ITK) 10 | IF(ITK_FOUND) 11 | INCLUDE(${ITK_USE_FILE}) 12 | ELSE(ITK_FOUND) 13 | MESSAGE(FATAL_ERROR "Cannot build InsightApplications without ITK. Please set ITK_DIR.") 14 | ENDIF(ITK_FOUND) 15 | 16 | FIND_PACKAGE (VTK) 17 | IF (VTK_FOUND) 18 | INCLUDE(${USE_VTK_FILE}) 19 | ENDIF(VTK_FOUND) 20 | 21 | 22 | # Find QT 23 | FIND_PACKAGE(Qt4 REQUIRED) 24 | INCLUDE( ${QT_USE_FILE} ) 25 | 26 | # support for out-of-source build 27 | INCLUDE_DIRECTORIES( 28 | ${CMAKE_CURRENT_BINARY_DIR} #this is where ui_ImageViewerUI.h is generated 29 | ${CMAKE_CURRENT_SOURCE_DIR} 30 | ) 31 | 32 | 33 | 34 | # Set your files and resources here 35 | SET(ImageViewerSrcs imageviewer.cpp imagewidget.cpp main.cpp MedianFilterDialog.cpp 36 | GADFilterDialog.cpp) 37 | 38 | SET(ImageViewerHeaders imageviewer.h imagewidget.h MedianFilterDialog.h GADFilterDialog.h) 39 | 40 | SET(ImageViewerUI MedianFilterDialog.ui GADFilterDialog.ui) 41 | 42 | 43 | # for generate qt aditional files 44 | QT4_WRAP_UI(UISrcs ${ImageViewerUI}) 45 | QT4_WRAP_CPP(MOCSrcs ${ImageViewerHeaders} ) 46 | 47 | 48 | # Packaging source code in same files 49 | SOURCE_GROUP("Forms" FILES 50 | ${ImageViewerUI} 51 | ) 52 | 53 | SOURCE_GROUP("Generated" FILES 54 | ${UISrcs} 55 | ${MOCSrcs} 56 | ) 57 | 58 | ADD_EXECUTABLE(ImageViewer ${ImageViewerSrcs} ${ImageViewerHeaders} ${UISrcs} ${MOCSrcs}) 59 | 60 | TARGET_LINK_LIBRARIES(ImageViewer QVTK ${VTK_LIBRARIES} ${ITK_LIBRARIES}) 61 | 62 | -------------------------------------------------------------------------------- /GADFilterDialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: GADFilterDialog.cpp 3 | * Author: zian 4 | * 5 | * Created on 22 de septiembre de 2011, 14:07 6 | */ 7 | 8 | #include "GADFilterDialog.h" 9 | 10 | GADFilterDialog::GADFilterDialog(QWidget *parent) : QDialog(parent) 11 | { 12 | this->setupUi(this); 13 | } 14 | 15 | GADFilterDialog::~GADFilterDialog() 16 | { 17 | } 18 | 19 | -------------------------------------------------------------------------------- /GADFilterDialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: GADFilterDialog.h 3 | * Author: zian 4 | * 5 | * Created on 22 de septiembre de 2011, 14:07 6 | */ 7 | 8 | #ifndef _GADFILTERDIALOG_H 9 | #define _GADFILTERDIALOG_H 10 | 11 | #include 12 | 13 | #include "ui_GADFilterDialog.h" 14 | 15 | class GADFilterDialog : public QDialog, public Ui::GADFilterDialog { 16 | Q_OBJECT 17 | 18 | public: 19 | 20 | GADFilterDialog(QWidget *parent = 0); 21 | 22 | virtual ~GADFilterDialog(); 23 | 24 | private: 25 | 26 | }; 27 | 28 | #endif /* _GADFILTERDIALOG_H */ 29 | 30 | 31 | -------------------------------------------------------------------------------- /GADFilterDialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | GADFilterDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 270 10 | 180 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | GADFilterDialog 21 | 22 | 23 | Gradient Anisotropic Diffusion Filter Options 24 | 25 | 26 | 27 | 28 | 16 29 | 11 30 | 241 31 | 156 32 | 33 | 34 | 35 | 36 | 37 | 38 | QFormLayout::FieldsStayAtSizeHint 39 | 40 | 41 | 42 | 43 | Time Step: 44 | 45 | 46 | 47 | 48 | 49 | 50 | 3 51 | 52 | 53 | 0.005000000000000 54 | 55 | 56 | 10.000000000000000 57 | 58 | 59 | 0.005000000000000 60 | 61 | 62 | 0.125000000000000 63 | 64 | 65 | 66 | 67 | 68 | 69 | Conductance: 70 | 71 | 72 | 73 | 74 | 75 | 76 | 0.010000000000000 77 | 78 | 79 | 0.010000000000000 80 | 81 | 82 | 0.500000000000000 83 | 84 | 85 | 86 | 87 | 88 | 89 | Number of Iterations: 90 | 91 | 92 | 93 | 94 | 95 | 96 | 1 97 | 98 | 99 | 5 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | Qt::Horizontal 109 | 110 | 111 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | buttonBox 122 | accepted() 123 | GADFilterDialog 124 | accept() 125 | 126 | 127 | 248 128 | 254 129 | 130 | 131 | 157 132 | 274 133 | 134 | 135 | 136 | 137 | buttonBox 138 | rejected() 139 | GADFilterDialog 140 | reject() 141 | 142 | 143 | 316 144 | 260 145 | 146 | 147 | 286 148 | 274 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /MedianFilterDialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MedianFilterDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 222 10 | 86 11 | 12 | 13 | 14 | Filter Intensity 15 | 16 | 17 | 18 | 19 | 10 20 | 50 21 | 192 22 | 32 23 | 24 | 25 | 26 | Qt::Horizontal 27 | 28 | 29 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 30 | 31 | 32 | 33 | 34 | 35 | 70 36 | 10 37 | 126 38 | 27 39 | 40 | 41 | 42 | 43 | 44 | 45 | Intensity: 46 | 47 | 48 | Qt::PlainText 49 | 50 | 51 | 52 | 53 | 54 | 55 | 1 56 | 57 | 58 | 50 59 | 60 | 61 | 62 | 63 | 64 | layoutWidget 65 | buttonBox 66 | 67 | 68 | 69 | 70 | buttonBox 71 | accepted() 72 | MedianFilterDialog 73 | accept() 74 | 75 | 76 | 248 77 | 254 78 | 79 | 80 | 157 81 | 274 82 | 83 | 84 | 85 | 86 | buttonBox 87 | rejected() 88 | MedianFilterDialog 89 | reject() 90 | 91 | 92 | 316 93 | 260 94 | 95 | 96 | 286 97 | 274 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Qt-ITK-VTK-Image-Viewer 2 | 3 | This software is a very basic Image Processing application. Build for demonstrative purposes, in the use of Qt VTK and ITK libraries together. 4 | 5 | This app, create a GUI with Qt, load an image from file using ITK and display the image using VTK in conjunction with Qt. Also you can apply an image filter with ITK and display the resulting image. 6 | 7 | In order to compile and run this example you need the following libraries: 8 | 9 | Cmake 2.8 10 | InsightToolkit-3.20.0 11 | VTK-5.6.1 12 | Qt 4.7.4 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /external/itkImageToVTKImageFilter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | #ifndef __itkImageToVTKImageFilter_h 19 | #define __itkImageToVTKImageFilter_h 20 | 21 | #include "itkVTKImageExport.h" 22 | #include "vtkImageImport.h" 23 | #include "vtkImageData.h" 24 | 25 | namespace itk 26 | { 27 | 28 | /** \class ImageToVTKImageFilter 29 | * \brief Converts an ITK image into a VTK image and plugs a 30 | * itk data pipeline to a VTK datapipeline. 31 | * 32 | * This class puts together an itkVTKImageExporter and a vtkImageImporter. 33 | * It takes care of the details related to the connection of ITK and VTK 34 | * pipelines. The User will perceive this filter as an adaptor to which 35 | * an itk::Image can be plugged as input and a vtkImage is produced as 36 | * output. 37 | * 38 | * \ingroup ImageFilters 39 | */ 40 | template 41 | class ITK_EXPORT ImageToVTKImageFilter : public ProcessObject 42 | { 43 | public: 44 | /** Standard class typedefs. */ 45 | typedef ImageToVTKImageFilter Self; 46 | typedef ProcessObject Superclass; 47 | typedef SmartPointer Pointer; 48 | typedef SmartPointer ConstPointer; 49 | 50 | /** Method for creation through the object factory. */ 51 | itkNewMacro(Self); 52 | 53 | /** Run-time type information (and related methods). */ 54 | itkTypeMacro(ImageToVTKImageFilter, ProcessObject); 55 | 56 | /** Some typedefs. */ 57 | typedef TInputImage InputImageType; 58 | typedef typename InputImageType::ConstPointer InputImagePointer; 59 | 60 | typedef VTKImageExport< InputImageType> ExporterFilterType; 61 | typedef typename ExporterFilterType::Pointer ExporterFilterPointer; 62 | 63 | /** Get the output in the form of a vtkImage. 64 | This call is delegated to the internal vtkImageImporter filter */ 65 | vtkImageData * GetOutput() const; 66 | 67 | /** Set the input in the form of an itk::Image */ 68 | void SetInput( const InputImageType * ); 69 | 70 | /** Return the internal VTK image importer filter. 71 | This is intended to facilitate users the access 72 | to methods in the importer */ 73 | vtkImageImport * GetImporter() const; 74 | 75 | /** Return the internal ITK image exporter filter. 76 | This is intended to facilitate users the access 77 | to methods in the exporter */ 78 | ExporterFilterType * GetExporter() const; 79 | 80 | /** This call delegate the update to the importer */ 81 | void Update(); 82 | 83 | protected: 84 | ImageToVTKImageFilter(); 85 | virtual ~ImageToVTKImageFilter(); 86 | 87 | private: 88 | ImageToVTKImageFilter(const Self&); //purposely not implemented 89 | void operator=(const Self&); //purposely not implemented 90 | 91 | ExporterFilterPointer m_Exporter; 92 | vtkImageImport * m_Importer; 93 | }; 94 | 95 | } // end namespace itk 96 | 97 | #ifndef ITK_MANUAL_INSTANTIATION 98 | #include "itkImageToVTKImageFilter.txx" 99 | #endif 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /external/itkImageToVTKImageFilter.txx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | * 3 | * Copyright Insight Software Consortium 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0.txt 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | *=========================================================================*/ 18 | #ifndef _itkImageToVTKImageFilter_txx 19 | #define _itkImageToVTKImageFilter_txx 20 | 21 | #include "itkImageToVTKImageFilter.h" 22 | 23 | namespace itk 24 | { 25 | 26 | /** 27 | * Constructor 28 | */ 29 | template 30 | ImageToVTKImageFilter 31 | ::ImageToVTKImageFilter() 32 | { 33 | m_Importer = vtkImageImport::New(); 34 | m_Exporter = ExporterFilterType::New(); 35 | 36 | m_Importer->SetUpdateInformationCallback(m_Exporter->GetUpdateInformationCallback()); 37 | m_Importer->SetPipelineModifiedCallback(m_Exporter->GetPipelineModifiedCallback()); 38 | m_Importer->SetWholeExtentCallback(m_Exporter->GetWholeExtentCallback()); 39 | m_Importer->SetSpacingCallback(m_Exporter->GetSpacingCallback()); 40 | m_Importer->SetOriginCallback(m_Exporter->GetOriginCallback()); 41 | m_Importer->SetScalarTypeCallback(m_Exporter->GetScalarTypeCallback()); 42 | m_Importer->SetNumberOfComponentsCallback(m_Exporter->GetNumberOfComponentsCallback()); 43 | m_Importer->SetPropagateUpdateExtentCallback(m_Exporter->GetPropagateUpdateExtentCallback()); 44 | m_Importer->SetUpdateDataCallback(m_Exporter->GetUpdateDataCallback()); 45 | m_Importer->SetDataExtentCallback(m_Exporter->GetDataExtentCallback()); 46 | m_Importer->SetBufferPointerCallback(m_Exporter->GetBufferPointerCallback()); 47 | m_Importer->SetCallbackUserData(m_Exporter->GetCallbackUserData()); 48 | 49 | } 50 | 51 | /** 52 | * Destructor 53 | */ 54 | template 55 | ImageToVTKImageFilter 56 | ::~ImageToVTKImageFilter() 57 | { 58 | if( m_Importer ) 59 | { 60 | m_Importer->Delete(); 61 | m_Importer = 0; 62 | } 63 | } 64 | 65 | /** 66 | * Set an itk::Image as input 67 | */ 68 | template 69 | void 70 | ImageToVTKImageFilter 71 | ::SetInput( const InputImageType * inputImage ) 72 | { 73 | m_Exporter->SetInput( inputImage ); 74 | } 75 | 76 | /** 77 | * Get a vtkImage as output 78 | */ 79 | template 80 | vtkImageData * 81 | ImageToVTKImageFilter 82 | ::GetOutput() const 83 | { 84 | return m_Importer->GetOutput(); 85 | } 86 | 87 | /** 88 | * Get the importer filter 89 | */ 90 | template 91 | vtkImageImport * 92 | ImageToVTKImageFilter 93 | ::GetImporter() const 94 | { 95 | return m_Importer; 96 | } 97 | 98 | /** 99 | * Get the exporter filter 100 | */ 101 | template 102 | typename ImageToVTKImageFilter::ExporterFilterType * 103 | ImageToVTKImageFilter 104 | ::GetExporter() const 105 | { 106 | return m_Exporter.GetPointer(); 107 | } 108 | 109 | /** 110 | * Delegate the Update to the importer 111 | */ 112 | template 113 | void 114 | ImageToVTKImageFilter 115 | ::Update() 116 | { 117 | m_Importer->Update(); 118 | } 119 | } // end namespace itk 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /external/itkVTKImageToImageFilter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Insight Segmentation & Registration Toolkit 4 | Module: $RCSfile: itkVTKImageToImageFilter.h,v $ 5 | Language: C++ 6 | Date: $Date: 2004-04-25 21:35:10 $ 7 | Version: $Revision: 1.5 $ 8 | 9 | Copyright (c) 2002 Insight Consortium. All rights reserved. 10 | See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 11 | 12 | This software is distributed WITHOUT ANY WARRANTY; without even 13 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | PURPOSE. See the above copyright notices for more information. 15 | 16 | =========================================================================*/ 17 | #ifndef __itkVTKImageToImageFilter_h 18 | #define __itkVTKImageToImageFilter_h 19 | 20 | #include "itkVTKImageImport.h" 21 | #include "vtkImageExport.h" 22 | #include "vtkImageData.h" 23 | 24 | #ifndef vtkFloatingPointType 25 | #define vtkFloatingPointType float 26 | #endif 27 | 28 | namespace itk 29 | { 30 | 31 | /** \class VTKImageToImageFilter 32 | * \brief Converts a VTK image into an ITK image and plugs a 33 | * vtk data pipeline to an ITK datapipeline. 34 | * 35 | * This class puts together an itkVTKImageImporter and a vtkImageExporter. 36 | * It takes care of the details related to the connection of ITK and VTK 37 | * pipelines. The User will perceive this filter as an adaptor to which 38 | * a vtkImage can be plugged as input and an itk::Image is produced as 39 | * output. 40 | * 41 | * \ingroup ImageFilters 42 | */ 43 | template 44 | class ITK_EXPORT VTKImageToImageFilter : public ProcessObject 45 | { 46 | public: 47 | /** Standard class typedefs. */ 48 | typedef VTKImageToImageFilter Self; 49 | typedef ProcessObject Superclass; 50 | typedef SmartPointer Pointer; 51 | typedef SmartPointer ConstPointer; 52 | 53 | /** Method for creation through the object factory. */ 54 | itkNewMacro(Self); 55 | 56 | /** Run-time type information (and related methods). */ 57 | itkTypeMacro(VTKImageToImageFilter, ProcessObject); 58 | 59 | /** Some typedefs. */ 60 | typedef TOutputImage OutputImageType; 61 | typedef typename OutputImageType::ConstPointer OutputImagePointer; 62 | typedef VTKImageImport< OutputImageType > ImporterFilterType; 63 | typedef typename ImporterFilterType::Pointer ImporterFilterPointer; 64 | 65 | /** Get the output in the form of a vtkImage. 66 | This call is delegated to the internal vtkImageImporter filter */ 67 | const OutputImageType * GetOutput() const; 68 | 69 | /** Set the input in the form of a vtkImageData */ 70 | void SetInput( vtkImageData * ); 71 | 72 | /** Return the internal VTK image exporter filter. 73 | This is intended to facilitate users the access 74 | to methods in the exporter */ 75 | vtkImageExport * GetExporter() const; 76 | 77 | /** Return the internal ITK image importer filter. 78 | This is intended to facilitate users the access 79 | to methods in the importer */ 80 | ImporterFilterType * GetImporter() const; 81 | 82 | /** This call delegate the update to the importer */ 83 | void Update(); 84 | 85 | protected: 86 | VTKImageToImageFilter(); 87 | virtual ~VTKImageToImageFilter(); 88 | 89 | private: 90 | VTKImageToImageFilter(const Self&); //purposely not implemented 91 | void operator=(const Self&); //purposely not implemented 92 | 93 | ImporterFilterPointer m_Importer; 94 | vtkImageExport * m_Exporter; 95 | 96 | }; 97 | 98 | } // end namespace itk 99 | 100 | #ifndef ITK_MANUAL_INSTANTIATION 101 | #include "itkVTKImageToImageFilter.txx" 102 | #endif 103 | 104 | #endif 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /external/itkVTKImageToImageFilter.txx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Insight Segmentation & Registration Toolkit 4 | Module: $RCSfile: itkVTKImageToImageFilter.txx,v $ 5 | Language: C++ 6 | Date: $Date: 2005-06-12 01:23:44 $ 7 | Version: $Revision: 1.4 $ 8 | 9 | Copyright (c) 2002 Insight Consortium. All rights reserved. 10 | See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 11 | 12 | This software is distributed WITHOUT ANY WARRANTY; without even 13 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 | PURPOSE. See the above copyright notices for more information. 15 | 16 | =========================================================================*/ 17 | #ifndef _itkVTKImageToImageFilter_txx 18 | #define _itkVTKImageToImageFilter_txx 19 | 20 | #include "itkVTKImageToImageFilter.h" 21 | 22 | namespace itk 23 | { 24 | 25 | 26 | 27 | /** 28 | * Constructor 29 | */ 30 | template 31 | VTKImageToImageFilter 32 | ::VTKImageToImageFilter() 33 | { 34 | 35 | m_Exporter = vtkImageExport::New(); 36 | 37 | m_Importer = ImporterFilterType::New(); 38 | 39 | m_Importer->SetUpdateInformationCallback( m_Exporter->GetUpdateInformationCallback()); 40 | m_Importer->SetPipelineModifiedCallback( m_Exporter->GetPipelineModifiedCallback()); 41 | m_Importer->SetWholeExtentCallback( m_Exporter->GetWholeExtentCallback()); 42 | m_Importer->SetSpacingCallback( m_Exporter->GetSpacingCallback()); 43 | m_Importer->SetOriginCallback( m_Exporter->GetOriginCallback()); 44 | m_Importer->SetScalarTypeCallback( m_Exporter->GetScalarTypeCallback()); 45 | m_Importer->SetNumberOfComponentsCallback( m_Exporter->GetNumberOfComponentsCallback()); 46 | m_Importer->SetPropagateUpdateExtentCallback( m_Exporter->GetPropagateUpdateExtentCallback()); 47 | m_Importer->SetUpdateDataCallback( m_Exporter->GetUpdateDataCallback()); 48 | m_Importer->SetDataExtentCallback( m_Exporter->GetDataExtentCallback()); 49 | m_Importer->SetBufferPointerCallback( m_Exporter->GetBufferPointerCallback()); 50 | m_Importer->SetCallbackUserData( m_Exporter->GetCallbackUserData()); 51 | 52 | } 53 | 54 | 55 | 56 | 57 | /** 58 | * Destructor 59 | */ 60 | template 61 | VTKImageToImageFilter 62 | ::~VTKImageToImageFilter() 63 | { 64 | if( m_Exporter ) 65 | { 66 | m_Exporter->Delete(); 67 | m_Exporter = 0; 68 | } 69 | } 70 | 71 | 72 | 73 | /** 74 | * Set a vtkImageData as input 75 | */ 76 | template 77 | void 78 | VTKImageToImageFilter 79 | ::SetInput( vtkImageData * inputImage ) 80 | { 81 | m_Exporter->SetInput( inputImage ); 82 | } 83 | 84 | 85 | 86 | /** 87 | * Get an itk::Image as output 88 | */ 89 | template 90 | const typename VTKImageToImageFilter::OutputImageType * 91 | VTKImageToImageFilter 92 | ::GetOutput() const 93 | { 94 | return m_Importer->GetOutput(); 95 | } 96 | 97 | 98 | 99 | 100 | /** 101 | * Get the exporter filter 102 | */ 103 | template 104 | vtkImageExport * 105 | VTKImageToImageFilter 106 | ::GetExporter() const 107 | { 108 | return m_Exporter; 109 | } 110 | 111 | 112 | 113 | /** 114 | * Get the importer filter 115 | */ 116 | template 117 | typename VTKImageToImageFilter::ImporterFilterType * 118 | VTKImageToImageFilter 119 | ::GetImporter() const 120 | { 121 | return m_Importer; 122 | } 123 | 124 | 125 | 126 | 127 | /** 128 | * Delegate the Update to the importer 129 | */ 130 | template 131 | void 132 | VTKImageToImageFilter 133 | ::Update() 134 | { 135 | m_Importer->Update(); 136 | } 137 | 138 | 139 | 140 | 141 | } // end namespace itk 142 | 143 | #endif 144 | 145 | -------------------------------------------------------------------------------- /imageviewer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "imageviewer.h" 4 | 5 | ImageViewer::ImageViewer(QWidget *parent) : QMainWindow(parent) 6 | { 7 | setAttribute(Qt::WA_DeleteOnClose); 8 | 9 | createActions(); 10 | createMenus(); 11 | createStatusBar(); 12 | } 13 | 14 | ImageViewer::~ImageViewer() 15 | { 16 | this->imageWidget = NULL; 17 | 18 | } 19 | 20 | void ImageViewer::open() 21 | { 22 | 23 | if (!imageWidget) { 24 | this->imageWidget = new ImageWidget(); 25 | // this->imageWidget->openWithITK(); 26 | this->imageWidget->open(); 27 | 28 | this->setCentralWidget(imageWidget); 29 | this->setWindowTitle(tr("Image Viewer")); 30 | this->resize(640, 480); 31 | } else { 32 | ImageViewer *viewer = new ImageViewer(); 33 | viewer->imageWidget = new ImageWidget(); 34 | // viewer->imageWidget->openWithITK(); 35 | viewer->imageWidget->open(); 36 | 37 | viewer->setCentralWidget(viewer->imageWidget); 38 | viewer->setWindowTitle(tr("Image Viewer")); 39 | viewer->resize(640, 480); 40 | viewer->show(); 41 | } 42 | } 43 | 44 | void ImageViewer::saveAs() 45 | { 46 | 47 | } 48 | 49 | void ImageViewer::medianFilter() 50 | { 51 | this->imageWidget->medianFilter(); 52 | } 53 | 54 | void ImageViewer::gradientAnisotropicDiffusionFilter() 55 | { 56 | this->imageWidget->gradientAnisotropicDiffusionFilter(); 57 | } 58 | 59 | void ImageViewer::about() 60 | { 61 | QMessageBox::about(this, tr("About Image Viewer"), 62 | tr("

The Image Viewer example shows how to combine QLabel " 63 | "and QScrollArea to display an image. QLabel is typically used " 64 | "for displaying a text, but it can also display an image. " 65 | "QScrollArea provides a scrolling view around another widget. " 66 | "If the child widget exceeds the size of the frame, QScrollArea " 67 | "automatically provides scroll bars.

The example " 68 | "demonstrates how QLabel's ability to scale its contents " 69 | "(QLabel::scaledContents), and QScrollArea's ability to " 70 | "automatically resize its contents " 71 | "(QScrollArea::widgetResizable), can be used to implement " 72 | "zooming and scaling features.

In addition the example " 73 | "shows how to use QPainter to print an image.

")); 74 | } 75 | 76 | void ImageViewer::createActions() 77 | { 78 | openAct = new QAction(tr("&Open..."), this); 79 | openAct->setShortcut(tr("Ctrl+O")); 80 | connect(openAct, SIGNAL(triggered()), this, SLOT(open())); 81 | 82 | saveAsAct = new QAction(tr("Save As..."), this); 83 | saveAsAct->setShortcut(tr("Ctrl+Shift+S")); 84 | connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); 85 | 86 | exitAct = new QAction(tr("E&xit"), this); 87 | exitAct->setShortcut(tr("Ctrl+Q")); 88 | exitAct->setStatusTip(tr("Exit the application")); 89 | connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); 90 | 91 | medianFilterAct = new QAction(tr("Median Filter"), this); 92 | medianFilterAct->setStatusTip(tr("Apply a median filter to image")); 93 | connect(medianFilterAct, SIGNAL(triggered()), this, SLOT(medianFilter())); 94 | 95 | GADFilterAct = new QAction(tr("Gradient Anisotropic Filter"), this); 96 | connect(GADFilterAct, SIGNAL(triggered()), this, SLOT(gradientAnisotropicDiffusionFilter())); 97 | 98 | aboutAct = new QAction(tr("&About"), this); 99 | connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); 100 | 101 | aboutQtAct = new QAction(tr("About &Qt"), this); 102 | connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); 103 | } 104 | 105 | void ImageViewer::createMenus() 106 | { 107 | fileMenu = new QMenu(tr("&File"), this); 108 | fileMenu->addAction(openAct); 109 | fileMenu->addAction(saveAsAct); 110 | fileMenu->addSeparator(); 111 | fileMenu->addAction(exitAct); 112 | 113 | filterMenu = new QMenu(tr("&Filter"), this); 114 | filterMenu->addAction(medianFilterAct); 115 | filterMenu->addAction(GADFilterAct); 116 | 117 | helpMenu = new QMenu(tr("&Help"), this); 118 | helpMenu->addAction(aboutAct); 119 | helpMenu->addAction(aboutQtAct); 120 | 121 | menuBar()->addMenu(fileMenu); 122 | menuBar()->addMenu(filterMenu); 123 | menuBar()->addMenu(helpMenu); 124 | } 125 | 126 | void ImageViewer::createStatusBar() 127 | { 128 | statusLabel = new QLabel("Basic Image Viewer"); 129 | statusLabel->setAlignment(Qt::AlignHCenter); 130 | statusLabel->setMaximumSize(statusLabel->sizeHint()); 131 | 132 | statusBar()->addWidget(statusLabel); 133 | } -------------------------------------------------------------------------------- /imageviewer.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEVIEWER_H 2 | #define IMAGEVIEWER_H 3 | 4 | #include 5 | 6 | #include "imagewidget.h" 7 | 8 | class QAction; 9 | class QMenu; 10 | class QMenuBar; 11 | class QScrollArea; 12 | class QScrollBar; 13 | class QVBoxLayout; 14 | 15 | class ImageViewer : public QMainWindow { 16 | Q_OBJECT 17 | 18 | public: 19 | 20 | ImageViewer(QWidget* parent = 0); 21 | ~ImageViewer(); 22 | 23 | protected: 24 | // void closeEvent(QCloseEvent *event); 25 | 26 | 27 | private slots: 28 | 29 | /** 30 | * Load and display an image from file 31 | */ 32 | void open(); 33 | 34 | /** 35 | * Save as, to the disk, displayed image 36 | */ 37 | void saveAs(); 38 | 39 | /** 40 | * Apply median filter to image 41 | */ 42 | void medianFilter(); 43 | 44 | /** 45 | * apply an Anisotropic diffusion filter to image 46 | */ 47 | void gradientAnisotropicDiffusionFilter(); 48 | 49 | /** 50 | * 51 | */ 52 | void about(); 53 | 54 | private: 55 | 56 | void createActions(); 57 | void createMenus(); 58 | void createStatusBar(); 59 | 60 | ImageWidget *imageWidget; 61 | 62 | QAction *openAct; 63 | QAction *saveAsAct; 64 | QAction *exitAct; 65 | QAction *aboutAct; 66 | QAction *aboutQtAct; 67 | 68 | QAction *medianFilterAct; 69 | QAction *GADFilterAct; 70 | 71 | QMenu *fileMenu; 72 | QMenu *filterMenu; 73 | QMenu *helpMenu; 74 | 75 | QLabel *statusLabel; 76 | }; 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /imagewidget.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: imagewidget.cpp 3 | * Author: zian fanti 4 | * 5 | * Created on 19 de septiembre de 2011, 19:34 6 | */ 7 | #include "QVBoxLayout" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include "imagewidget.h" 25 | #include "medianFilterDialog.h" 26 | #include "GADFilterDialog.h" 27 | 28 | ImageWidget::ImageWidget(QWidget *parent) : QWidget(parent) 29 | { 30 | 31 | this->setAttribute(Qt::WA_DeleteOnClose); 32 | 33 | qvtkWidget = new QVTKWidget(this); 34 | // qvtkWidget->resize(640, 480); 35 | 36 | QVBoxLayout *layout = new QVBoxLayout; 37 | layout->setContentsMargins(0, 0, 0, 0); 38 | layout->setSpacing(0); 39 | layout->addWidget(qvtkWidget); 40 | this->setLayout(layout); 41 | 42 | 43 | // Create image actor 44 | actor = vtkSmartPointer::New(); 45 | 46 | // Create a camera 47 | camera = vtkSmartPointer::New(); 48 | 49 | // A renderer and render window 50 | renderer = vtkSmartPointer::New(); 51 | renderWindow = vtkSmartPointer::New(); 52 | renderWindow->AddRenderer(renderer); 53 | 54 | } 55 | 56 | ImageWidget::~ImageWidget() 57 | { 58 | renderWindow->Finalize(); 59 | qvtkWidget = NULL; 60 | itkImage = NULL; 61 | vtkImage = NULL; 62 | } 63 | 64 | void ImageWidget::open() 65 | { 66 | QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath()); 67 | 68 | if (!fileName.isEmpty()) { 69 | 70 | // Obtain image information 71 | this->setImageProperties(fileName.toAscii().data(), true); 72 | 73 | // set itk image depending on the image type 74 | // if image type is grayscale 75 | if (imageType.compare("scalar") == 0) { 76 | // read the image 77 | typedef itk::ImageFileReader ReaderType; 78 | ReaderType::Pointer reader = ReaderType::New(); 79 | reader->SetFileName(fileName.toAscii().data()); 80 | reader->Update(); 81 | 82 | // set the image data provided bye the reader 83 | itkImage = reader->GetOutput(); 84 | 85 | } else { 86 | // if the image is RGB 87 | typedef itk::ImageFileReader ReaderType; 88 | ReaderType::Pointer reader = ReaderType::New(); 89 | reader->SetFileName(fileName.toAscii().data()); 90 | reader->Update(); 91 | 92 | // set the image data provided bye the reader 93 | rgbItkImage = reader->GetOutput(); 94 | } 95 | 96 | // reads a vtkImage for display purposes 97 | vtkSmartPointer readerFactory = 98 | vtkSmartPointer ::New(); 99 | vtkSmartPointer reader = 100 | readerFactory->CreateImageReader2(fileName.toAscii().data()); 101 | 102 | reader->SetFileName(fileName.toAscii().data()); 103 | reader->Update(); 104 | 105 | vtkImage = reader->GetOutput(); 106 | 107 | this->isFliped = true; 108 | this->displayImage(vtkImage); 109 | 110 | 111 | readerFactory = NULL; 112 | reader = NULL; 113 | 114 | } else { 115 | QErrorMessage errorMessage; 116 | errorMessage.showMessage("No file specified for loading"); 117 | errorMessage.exec(); 118 | return; 119 | } 120 | } 121 | 122 | void ImageWidget::openWithITK() 123 | { 124 | QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath()); 125 | 126 | if (!fileName.isEmpty()) { 127 | 128 | // read the image 129 | typedef itk::ImageFileReader ReaderType; 130 | ReaderType::Pointer reader = ReaderType::New(); 131 | reader->SetFileName(fileName.toAscii().data()); 132 | reader->Update(); 133 | 134 | // set the image data provided bye the reader 135 | itkImage = reader->GetOutput(); 136 | 137 | // setup and connect itk with vtk 138 | vtkConnectorType::Pointer connector = vtkConnectorType::New(); 139 | connector->GetExporter()->SetInput(itkImage); 140 | connector->GetImporter()->Update(); 141 | 142 | // flip image in Y axis 143 | vtkSmartPointer flipYFilter = vtkSmartPointer::New(); 144 | flipYFilter->SetFilteredAxis(1); // flip Y axis 145 | flipYFilter->SetInput(connector->GetImporter()->GetOutput()); 146 | flipYFilter->Update(); 147 | 148 | // create vtk image 149 | vtkImage = vtkSmartPointer::New(); 150 | vtkImage->DeepCopy(flipYFilter->GetOutput()); 151 | vtkImage->SetScalarTypeToUnsignedChar(); 152 | vtkImage->Update(); 153 | 154 | this->displayImage(vtkImage); 155 | 156 | reader = NULL; 157 | flipYFilter = NULL; 158 | connector = NULL; 159 | } 160 | } 161 | 162 | void ImageWidget::medianFilter() 163 | { 164 | // create and show the median filter dialog 165 | MedianFilterDialog filterDialog(this); 166 | 167 | // if the user don't cancel the action 168 | if (filterDialog.exec()) { 169 | // get selected value from dialog 170 | int intensity = filterDialog.spinBox->value(); 171 | 172 | // if the itkImage is not loaded, then vtkImage is converted to itkImage 173 | if (itkImage.IsNull()) { 174 | this->setITKImageFromVTK(); 175 | } 176 | 177 | // setup the itk median filter 178 | typedef itk::MedianImageFilter FilterType; 179 | 180 | FilterType::Pointer filter = FilterType::New(); 181 | FilterType::InputSizeType radius; 182 | radius.Fill(intensity); 183 | 184 | filter->SetRadius(radius); 185 | filter->SetInput(itkImage); 186 | filter->Update(); 187 | 188 | 189 | // setup and connect itk with vtk, to transform the itkImage to vtkImage 190 | vtkConnectorType::Pointer vtkConnector = vtkConnectorType::New(); 191 | vtkConnector->GetExporter()->SetInput(filter->GetOutput()); 192 | vtkConnector->GetImporter()->Update(); 193 | 194 | itkImage = filter->GetOutput(); 195 | // clear previous vtkImage 196 | vtkImage = NULL; 197 | 198 | // create new vtk image 199 | vtkImage = vtkSmartPointer ::New(); 200 | vtkImage->Initialize(); 201 | vtkImage->DeepCopy(vtkConnector->GetImporter()->GetOutput()); 202 | vtkImage->Update(); 203 | 204 | isFliped = false; 205 | this->displayImage(vtkImage); 206 | 207 | filter = NULL; 208 | vtkConnector = NULL; 209 | } 210 | } 211 | 212 | void ImageWidget::gradientAnisotropicDiffusionFilter() 213 | { 214 | // create and show the median filter dialog 215 | GADFilterDialog filterDialog(this); 216 | if (filterDialog.exec()) { 217 | 218 | // if the image is in grayscale 219 | if (imageType.compare("scalar") == 0) { 220 | // set up gradient anisotropic diffusion filter 221 | typedef itk::GradientAnisotropicDiffusionImageFilter< ImageType, FloatImageType > FilterType; 222 | FilterType::Pointer filter = FilterType::New(); 223 | filter->SetInput(itkImage); 224 | 225 | filter->SetNumberOfIterations(filterDialog.iterationsSpinBox->value()); 226 | filter->SetTimeStep(filterDialog.timeStepSpinBox->value()); 227 | filter->SetConductanceParameter(filterDialog.conductanceSpinBox->value()); 228 | filter->Update(); 229 | 230 | // cast the float image to scalar image in order to display 231 | typedef itk::CastImageFilter< FloatImageType, ImageType > CastFilterType; 232 | CastFilterType::Pointer castFilter = CastFilterType::New(); 233 | castFilter->SetInput(filter->GetOutput()); 234 | 235 | itkImage = castFilter->GetOutput(); 236 | 237 | // setup and connect itk with vtk, to transform the itkImage to vtkImage 238 | vtkConnectorType::Pointer vtkConnector = vtkConnectorType::New(); 239 | vtkConnector->GetExporter()->SetInput(castFilter->GetOutput()); 240 | vtkConnector->GetImporter()->Update(); 241 | 242 | // clear previous vtkImage 243 | vtkImage = NULL; 244 | 245 | // create new vtk image 246 | vtkImage = vtkSmartPointer ::New(); 247 | vtkImage->Initialize(); 248 | vtkImage->DeepCopy(vtkConnector->GetImporter()->GetOutput()); 249 | vtkImage->Update(); 250 | 251 | isFliped = false; 252 | this->displayImage(vtkImage); 253 | 254 | filter = NULL; 255 | vtkConnector = NULL; 256 | } else { 257 | // if the image is RGB 258 | typedef itk::RGBPixel< float > FloatPixelType; 259 | typedef itk::Image< FloatPixelType, 2 > FloatRGBImageType; 260 | typedef itk::VectorGradientAnisotropicDiffusionImageFilter< RGBImageType, FloatRGBImageType > FilterType; 261 | 262 | 263 | FilterType::Pointer filter = FilterType::New(); 264 | filter->SetInput(rgbItkImage); 265 | 266 | filter->SetNumberOfIterations(filterDialog.iterationsSpinBox->value()); 267 | filter->SetTimeStep(filterDialog.timeStepSpinBox->value()); 268 | filter->SetConductanceParameter(filterDialog.conductanceSpinBox->value()); 269 | filter->Update(); 270 | 271 | typedef itk::CastImageFilter< FloatRGBImageType, RGBImageType > CastFilterType; 272 | CastFilterType::Pointer castFilter = CastFilterType::New(); 273 | castFilter->SetInput(filter->GetOutput()); 274 | 275 | rgbItkImage = castFilter->GetOutput(); 276 | 277 | // setup and connect itk with vtk, to transform the itkImage to vtkImage 278 | RGBVtkConnectorType::Pointer vtkConnector = RGBVtkConnectorType::New(); 279 | vtkConnector->GetExporter()->SetInput(castFilter->GetOutput()); 280 | vtkConnector->GetImporter()->Update(); 281 | 282 | // clear previous vtkImage 283 | vtkImage = NULL; 284 | 285 | // create new vtk image 286 | vtkImage = vtkSmartPointer ::New(); 287 | vtkImage->Initialize(); 288 | vtkImage->DeepCopy(vtkConnector->GetImporter()->GetOutput()); 289 | vtkImage->Update(); 290 | 291 | isFliped = false; 292 | this->displayImage(vtkImage); 293 | 294 | filter = NULL; 295 | vtkConnector = NULL; 296 | } 297 | } 298 | } 299 | 300 | void ImageWidget::displayImage(vtkImageData *image) 301 | { 302 | 303 | int *dim= image->GetDimensions(); 304 | double *spacing = image->GetSpacing(); 305 | double *origin = image->GetOrigin(); 306 | 307 | float Cx = (dim[0] * spacing[0])/2. + origin[0]; 308 | float Cy = (dim[1] * spacing[1])/2. + origin[1]; 309 | camera->ParallelProjectionOn(); 310 | camera->SetFocalPoint(Cx,Cy,0); 311 | camera->SetPosition(Cx,Cy,1); 312 | // 313 | // // to flip de image 314 | // camera->SetViewUp (0, 1, 0); 315 | // 316 | // set actor properties 317 | actor->SetInput(image); 318 | actor->InterpolateOff(); 319 | 320 | renderer->AddActor(actor); 321 | renderer->SetActiveCamera(camera); 322 | renderer->ResetCamera(); 323 | 324 | qvtkWidget->SetRenderWindow(renderWindow); 325 | 326 | // window interactor style for display images 327 | vtkSmartPointer style = vtkSmartPointer::New(); 328 | // set interactor style to the qvtkWidget Interactor 329 | qvtkWidget->GetInteractor()->SetInteractorStyle(style); 330 | 331 | this->update(); 332 | } 333 | 334 | void ImageWidget::setITKImageFromVTK() 335 | { 336 | itkConnectorType::Pointer itkConnector = itkConnectorType::New(); 337 | 338 | if (imageType.compare("rgb") == 0) { 339 | // Must convert image to grayscale because itkVTKImageToImageFilter only accepts single channel images 340 | vtkSmartPointer luminanceFilter = 341 | vtkSmartPointer::New(); 342 | luminanceFilter->SetInput(vtkImage); 343 | luminanceFilter->Update(); 344 | 345 | //get itkImage from vtkImage; vtkImageData is unsigned char and single channel 346 | itkConnector->SetInput(luminanceFilter->GetOutput()); 347 | luminanceFilter = NULL; 348 | } else { 349 | itkConnector->SetInput(vtkImage); 350 | } 351 | 352 | itkConnector->Update(); 353 | 354 | itkImage = ImageType::New(); 355 | itkImage->Graft(itkConnector->GetOutput()); 356 | 357 | itkConnector = NULL; 358 | } 359 | 360 | void ImageWidget::setImageProperties(std::string fileName, bool vervose) 361 | { 362 | // Obtain image information 363 | typedef itk::ImageIOBase::IOComponentType ScalarPixelType; 364 | 365 | itk::ImageIOBase::Pointer imageIO = 366 | itk::ImageIOFactory::CreateImageIO(fileName.c_str(), itk::ImageIOFactory::ReadMode); 367 | 368 | imageIO->SetFileName(fileName); 369 | imageIO->ReadImageInformation(); 370 | 371 | pixelType = imageIO->GetComponentTypeAsString(imageIO->GetComponentType()); 372 | numDimensions = imageIO->GetNumberOfDimensions(); 373 | imageType = imageIO->GetPixelTypeAsString(imageIO->GetPixelType()); 374 | 375 | if (vervose) { 376 | std::cout << "Pixels type: " << pixelType << std::endl; 377 | std::cout << "Image type: " << imageType << std::endl; 378 | std::cout << "Num of Dimensions: " << numDimensions << std::endl; 379 | } 380 | } 381 | -------------------------------------------------------------------------------- /imagewidget.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: imagewidget.h 3 | * Author: zian 4 | * 5 | * Created on 19 de septiembre de 2011, 19:34 6 | */ 7 | 8 | #ifndef IMAGEWIDGET_H 9 | #define IMAGEWIDGET_H 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include "external/itkVTKImageToImageFilter.h" 26 | #include "external/itkImageToVTKImageFilter.h" 27 | 28 | 29 | typedef itk::RGBPixel< unsigned char > RGBPixelType; 30 | 31 | typedef itk::Image< unsigned char, 2 > ImageType; 32 | typedef itk::Image< float, 2 > FloatImageType; 33 | typedef itk::Image< RGBPixelType, 2 > RGBImageType; 34 | 35 | typedef itk::VTKImageToImageFilter itkConnectorType; 36 | typedef itk::ImageToVTKImageFilter vtkConnectorType; 37 | typedef itk::ImageToVTKImageFilter RGBVtkConnectorType; 38 | typedef itk::ImageToVTKImageFilter vtkFloatConnectorType; 39 | 40 | 41 | 42 | 43 | class ImageWidget : public QWidget { 44 | Q_OBJECT 45 | 46 | public: 47 | /** 48 | * Constructor for this ImageWidget 49 | */ 50 | ImageWidget(QWidget *parent = 0); 51 | 52 | /** 53 | * Destructor for this ImageWidget 54 | */ 55 | virtual ~ImageWidget(); 56 | 57 | /** 58 | * load an display an image from file 59 | */ 60 | void open(); 61 | 62 | /** 63 | * load an display an image from file 64 | */ 65 | void openWithITK(); 66 | 67 | /** 68 | * Apply a median fiter to the itkImage 69 | */ 70 | void medianFilter(); 71 | 72 | /** 73 | * Apply a gradient anisotropic diffusion filter to an itkImage 74 | */ 75 | void gradientAnisotropicDiffusionFilter(); 76 | 77 | 78 | private: 79 | 80 | QVTKWidget *qvtkWidget; 81 | 82 | /** The image displayed for this window */ 83 | ImageType::Pointer itkImage; 84 | RGBImageType::Pointer rgbItkImage; 85 | 86 | 87 | /** The VTK image to display in this window */ 88 | vtkSmartPointer vtkImage; 89 | 90 | vtkSmartPointer actor; 91 | vtkSmartPointer renderer; 92 | vtkSmartPointer renderWindow; 93 | vtkSmartPointer interactor; 94 | vtkSmartPointer camera; 95 | 96 | /** The type of the image components RGB, scalar, etc */ 97 | std::string pixelType; 98 | 99 | /** The type of the image pixels */ 100 | std::string imageType; 101 | 102 | /** The number of the image dimensions */ 103 | size_t numDimensions; 104 | 105 | /** flag for a flipped image */ 106 | bool isFliped; 107 | 108 | /** 109 | * to display the loaded image in the QVTKwidget 110 | * @param image vtkImageData 111 | */ 112 | void displayImage(vtkImageData *image); 113 | 114 | /** 115 | * Set itkImage converting the vtkImage to a ITK image 116 | */ 117 | void setITKImageFromVTK(); 118 | 119 | /** 120 | * extract some image properties as, pixel type, image type and number of dimensions 121 | * @param fileName path to the file 122 | * @param vervose if print the standar out 123 | */ 124 | void setImageProperties(std::string fileName, bool vervose); 125 | 126 | }; 127 | 128 | #endif /* IMAGEWIDGET_H */ 129 | 130 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "imageviewer.h" 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication app(argc, argv); 7 | ImageViewer *imageViewer = new ImageViewer; 8 | imageViewer->show(); 9 | return app.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /medianFilterDialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * File: medianFilterDialog.cpp 3 | * Author: zian fanti 4 | * 5 | * Created on 14 de septiembre de 2011, 16:52 6 | */ 7 | 8 | #include "medianFilterDialog.h" 9 | 10 | MedianFilterDialog::MedianFilterDialog(QWidget *parent) : QDialog(parent) 11 | { 12 | this->setupUi(this); 13 | 14 | } 15 | 16 | MedianFilterDialog::~MedianFilterDialog() { 17 | } 18 | 19 | -------------------------------------------------------------------------------- /medianFilterDialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: medianFilterDialog.h 3 | * Author: zian 4 | * 5 | * Created on 14 de septiembre de 2011, 16:52 6 | */ 7 | 8 | #ifndef MEDIANFILTERDIALOG_H 9 | #define MEDIANFILTERDIALOG_H 10 | 11 | #include 12 | 13 | #include "ui_MedianFilterDialog.h" 14 | 15 | class MedianFilterDialog : public QDialog, public Ui::MedianFilterDialog { 16 | Q_OBJECT 17 | 18 | public: 19 | 20 | MedianFilterDialog(QWidget *parent = 0); 21 | virtual ~MedianFilterDialog(); 22 | 23 | private: 24 | 25 | }; 26 | 27 | #endif /* MEDIANFILTERDIALOG_H */ 28 | 29 | --------------------------------------------------------------------------------