소스 검색

added 3d functionality & minor code changes

Sven Sickert 11 년 전
부모
커밋
41f8935fea
5개의 변경된 파일58개의 추가작업 그리고 17개의 파일을 삭제
  1. 2 2
      RSGraphBased.cpp
  2. 3 3
      RSMarkovCluster.cpp
  3. 1 11
      RSMeanShift.cpp
  4. 39 0
      RegionSegmentationMethod.cpp
  5. 13 1
      RegionSegmentationMethod.h

+ 2 - 2
RSGraphBased.cpp

@@ -38,8 +38,8 @@ RSGraphBased::~RSGraphBased()
 
 int RSGraphBased::segRegions ( const NICE::Image & img, NICE::Matrix & mask) const
 {
-  cerr << "not implemented yet" << endl;
-  return -1;
+  NICE::ColorImage cimg(img, img, img);
+  return segRegions(cimg, mask);
 }
 
 int RSGraphBased::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask) const

+ 3 - 3
RSMarkovCluster.cpp

@@ -738,7 +738,7 @@ RSMarkovCluster::printMatrix ( const NodeCentricRepMatrix& L, const RSMarkovClus
         int indexP = y * n_x + x;
         int indexN = ( y + m ) * n_x + ( x + n );
 
-        if ( ( indexP >= 0 ) && ( indexP < ( n_y*n_x ) ) && ( indexN >= 0 ) && ( indexN < ( n_y*n_x ) ) )
+        if ( ( indexP >= 0 ) && ( indexP < (int)( n_y*n_x ) ) && ( indexN >= 0 ) && ( indexN < (int)( n_y*n_x ) ) )
           oMatrix ( indexP, indexN ) = value;
       }
     }
@@ -746,10 +746,10 @@ RSMarkovCluster::printMatrix ( const NodeCentricRepMatrix& L, const RSMarkovClus
 
   ofstream fout;
   fout.open ( filename.c_str() );
-  for ( int y = 0;y < ( n_y*n_x );y++ )
+  for ( int y = 0;y < (int)( n_y*n_x );y++ )
   {
     string line = "";
-    for ( int x = 0;x < ( n_y*n_x );x++ )
+    for ( int x = 0;x < (int)( n_y*n_x );x++ )
     {
       if ( oMatrix ( x, y ) == 0.0 ) line += "----\t";
       else

+ 1 - 11
RSMeanShift.cpp

@@ -46,17 +46,7 @@ RSMeanShift::~RSMeanShift()
 
 int RSMeanShift::segRegions ( const NICE::Image & img, NICE::Matrix & mask ) const
 {
-  ColorImage cimg ( img.width(), img.height() );
-  for(int y = 0; y < img.height(); y++)
-  {
-    for(int x = 0; x < img.width(); x++)
-    {
-      for(int c = 0; c < 3; c++)
-      {
-        cimg.setPixelQuick(x,y,c,img.getPixelQuick(x,y));
-      }
-    }
-  }
+  ColorImage cimg ( img, img, img );
   return segRegions ( cimg, mask );
 }
 

+ 39 - 0
RegionSegmentationMethod.cpp

@@ -201,6 +201,45 @@ int RegionSegmentationMethod::segRegions ( const NICE::ColorImage & cimg, NICE::
   return segRegions ( img, mask );
 }
 
+int RegionSegmentationMethod::segRegions (
+    const NICE::MultiChannelImage3DT<double> & img,
+    NICE::MultiChannelImageT<int> & mask,
+    const int isGray
+    ) const
+{
+	const int xsize = img.width();
+	const int ysize = img.height();
+	const int zsize = img.depth();
+
+	int amountRegions = -1;
+	mask.reInit( xsize, ysize, zsize );
+	for (int z = 0; z < zsize; z++)
+	{
+		NICE::Matrix reg;
+		int aR;
+    if ( isGray )
+		{
+      NICE::Image slice = img.getChannel(z);
+      aR = segRegions( slice, reg );
+		} else {
+      NICE::ColorImage slice = img.getColor(z);
+      aR = segRegions( slice, reg );
+		}
+
+		if ( aR > amountRegions ) amountRegions = aR;
+
+		for (int y = 0; y < ysize; y++)
+		{
+			for (int x = 0; x < xsize; x++)
+			{
+				mask.set( x, y, reg(x,y), (uint)z );
+			}
+		}
+	}
+
+  return amountRegions;
+}
+
 void RegionSegmentationMethod::markContours ( const NICE::ColorImage & cimg, NICE::Matrix & mask, std::vector<int> &color, NICE::ColorImage &marked )
 {
   // mark contours

+ 13 - 1
RegionSegmentationMethod.h

@@ -9,9 +9,12 @@
 
 #include "core/basics/Config.h"
 
+#include <vector>
+
 #undef DEBUGRS
 
 #include "RegionGraph.h"
+#include "core/image/MultiChannelImage3DT.h"
 
 
 namespace OBJREC {
@@ -49,7 +52,16 @@ class RegionSegmentationMethod
      */
     virtual int segRegions ( const NICE::ColorImage & cimg, NICE::Matrix & mask) const;
 
-    /**
+		/**
+     * returns the regions of a given 3d image
+     * @param img input 3d image data
+     * @param mask output regions for each image slice, each region has it own number
+     * @param isGray grayscale image or not
+     * @return amount of regions
+     */
+    virtual int segRegions (const NICE::MultiChannelImage3DT<double> & img, NICE::MultiChannelImageT<int> & mask, const int isGray) const;
+
+		/**
      * transform a segmented color image in a grayimage, where each region has its own label
      * @param img input image
      * @param mask output mask