diff --git a/Plugins/org.mitk.gui.qt.regiongrowing/files.cmake b/Plugins/org.mitk.gui.qt.regiongrowing/files.cmake index 958140b28d..0218a186f1 100644 --- a/Plugins/org.mitk.gui.qt.regiongrowing/files.cmake +++ b/Plugins/org.mitk.gui.qt.regiongrowing/files.cmake @@ -1,35 +1,36 @@ set(SRC_CPP_FILES ) set(INTERNAL_CPP_FILES org_mitk_gui_qt_regiongrowing_Activator.cpp QmitkRegionGrowingView.cpp + MitkRegionIterator.cpp ) set(UI_FILES src/internal/QmitkRegionGrowingViewControls.ui ) set(MOC_H_FILES src/internal/org_mitk_gui_qt_regiongrowing_Activator.h src/internal/QmitkRegionGrowingView.h ) set(CACHED_RESOURCE_FILES resources/icon.png plugin.xml ) set(QRC_FILES ) foreach(file ${SRC_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/${file}) endforeach(file ${SRC_CPP_FILES}) foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.cpp b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.cpp new file mode 100644 index 0000000000..e1a36cdadc --- /dev/null +++ b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.cpp @@ -0,0 +1 @@ +#include "MitkRegionIterator.h" diff --git a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.h b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.h new file mode 100644 index 0000000000..ac7a7476ea --- /dev/null +++ b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.h @@ -0,0 +1,145 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MitkRegionIterator_h +#define MitkRegionIterator_h + +template +class MitkRegionIterator +{ +private: + ImageType* m_Image; + int m_Radius; + +public: + MitkRegionIterator(ImageType* image, int radius) + :m_Image(image), + m_Radius(radius) + {} + + void SetRadius(int radius) + { + m_Radius = radius; + } + + int GetMeanPixelValueForRegion(IndexType seedIndex) + { + int mean = 0; + int sum = 0; + int count = 0; + + //x-Direction + for (int i = -m_Radius; i <= m_Radius; i++) + { + IndexType localSeedIndex; + localSeedIndex[0] = seedIndex[0] + i; + + //y-Direction + for (int j = -m_Radius; j <= m_Radius; j++) + { + localSeedIndex[1] = seedIndex[1] + j; + + //z-Direction + for (int k = -m_Radius; k <= m_Radius; k++) + { + localSeedIndex[2] = seedIndex[2] + k; + //MITK_INFO << m_Image->GetPixel(localSeedIndex); + sum += m_Image->GetPixel(localSeedIndex); + count++; + } + + } + } + mean = sum / count; + return mean; + } + + int GetThresholdByMeanMethod(IndexType seedIndex) + { + int thresholdRange = 130; + + //x-Direction + for (int i = -m_Radius; i <= m_Radius; i++) + { + IndexType localSeedIndex; + localSeedIndex[0] = seedIndex[0] + i; + + //y-Direction + for (int j = -m_Radius; j <= m_Radius; j++) + { + localSeedIndex[1] = seedIndex[1] + j; + + //z-Direction + for (int k = -m_Radius; k <= m_Radius; k++) + { + localSeedIndex[2] = seedIndex[2] + k; + MITK_INFO << m_Image->GetPixel(localSeedIndex); + } + + } + } + + return thresholdRange; + } + + int GetThresholdByStdDivMethod(IndexType seedIndex) + { + int thresholdRange = 0; + double* pixelValueVector = new double[1000]; + int count = 0; + double sum = 0; + + //x-Direction + for (int i = -m_Radius; i <= m_Radius; i++) + { + IndexType localSeedIndex; + localSeedIndex[0] = seedIndex[0] + i; + + //y-Direction + for (int j = -m_Radius; j <= m_Radius; j++) + { + localSeedIndex[1] = seedIndex[1] + j; + + //z-Direction + for (int k = -m_Radius; k <= m_Radius; k++) + { + localSeedIndex[2] = seedIndex[2] + k; + int currentValue = m_Image->GetPixel(localSeedIndex); + sum += currentValue; + pixelValueVector[count++] = currentValue; + //MITK_INFO << m_Image->GetPixel(localSeedIndex); + } + } + } + + int mean = sum / count; + int quadraticSum = 0; + + for (int i = 0; i < count; i++) + { + double helper = (pixelValueVector[i] - mean)*(pixelValueVector[i] - mean); + quadraticSum += helper; + } + + double SD = std::sqrt(quadraticSum / count); + + thresholdRange = SD; + return thresholdRange; + } + +}; + +#endif //MitkRegionIterator_h \ No newline at end of file