#include "RSGraphBased.h" #include #include #ifdef NICE_USELIB_OPENMP #include #endif #include "felzenszwalb/image.h" #include "felzenszwalb/misc.h" #include "felzenszwalb/segment-image.h" #include "felzenszwalb/pnmfile.h" using namespace std; using namespace NICE; using namespace OBJREC; using namespace felzenszwalb; RSGraphBased::RSGraphBased() { parameter_k = 500; parameter_min_size = 200; parameter_sigma = 1.5; } RSGraphBased::RSGraphBased(const Config *conf ) { //thr = conf->gD( "RSGraphBased", "threshold", 5.0); parameter_k = conf->gD("RSGraphBased", "k", 500); parameter_min_size = conf->gI("RSGraphBased", "min_size", 200); parameter_sigma = conf->gD("RSGraphBased", "sigma", 1.5); } RSGraphBased::~RSGraphBased() { } int RSGraphBased::segRegions ( const NICE::Image & img, NICE::Matrix & mask) const { cerr << "not implemented yet" << endl; return -1; } int RSGraphBased::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask) const { const unsigned int imageWidth = img.width(); const unsigned int imageHeight = img.height(); // Kopieren der Werte aus dem ColorImage -> image image *inputImage = new image( imageWidth, imageHeight, false ); #pragma omp parallel for for ( unsigned int y = 0; y < imageHeight; y++ ) { for ( unsigned int x = 0; x < imageWidth; x++ ) { imRef( inputImage, x, y ).r = img.getPixelQuick( x, y, 0 ); imRef( inputImage, x, y ).g = img.getPixelQuick( x, y, 1 ); imRef( inputImage, x, y ).b = img.getPixelQuick( x, y, 2 ); } } // Eingabebild segmentieren int num_ccs; // Anzahl der segmentierten Regionen image *tempResultImage = segment_image( inputImage, parameter_sigma, parameter_k, parameter_min_size, &num_ccs ); // Kopieren der Werte aus dem image -> ColorImage NICE::ColorImage resultImage( imageWidth, imageHeight ); #pragma omp parallel for for ( unsigned int y = 0; y < imageHeight; y++ ) { for ( unsigned int x = 0; x < imageWidth; x++ ) { resultImage.setPixelQuick( x, y, 0, imRef(tempResultImage, x, y ).r ); resultImage.setPixelQuick( x, y, 1, imRef(tempResultImage, x, y ).g ); resultImage.setPixelQuick( x, y, 2, imRef(tempResultImage, x, y ).b ); } } // Speicher freigeben delete inputImage; inputImage = NULL; delete tempResultImage; tempResultImage = NULL; transformSegmentedImg( resultImage, mask); return num_ccs; }