#include "RSSlic.h" #include #include #ifdef NICE_USELIB_OPENMP #include #endif #include "SLIC/SLIC.h" using namespace std; using namespace NICE; using namespace OBJREC; RSSlic::RSSlic() { //spcount = 100000; spcount = 200; compactness = 10.0; } RSSlic::RSSlic(const Config *conf ) { spcount = conf->gI("RSSlic", "m_spcount", 2000); compactness = conf->gD("RSSlic", "compactness", 10.0); } RSSlic::~RSSlic() { } int RSSlic::segRegions ( const NICE::Image & img, NICE::Matrix & mask) const { cerr << "not implemented yet" << endl; return -1; } int RSSlic::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 uint *inputImage = new uint[3*imageWidth*imageHeight]; //#pragma omp parallel for unsigned long int counter = 0; for (int c = 0; c < 3; c++) { for ( unsigned int y = 0; y < imageHeight; y++ ) { for ( unsigned int x = 0; x < imageWidth; x++, counter++) { inputImage[counter] = img.getPixelQuick( x, y, c ); } } } int* labels = new int[imageWidth*imageHeight]; // Eingabebild segmentieren SLIC slic; int numlabels = 0; slic.DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels(inputImage, imageWidth, imageHeight, labels, numlabels, spcount, compactness); slic.DrawContoursAroundSegments(inputImage, labels, imageWidth, imageHeight, 0); NICE::ColorImage resultImage( imageWidth, imageHeight ); /* counter = 0; for (int c = 0; c < 3; c++) { for ( unsigned int y = 0; y < imageHeight; y++ ) { for ( unsigned int x = 0; x < imageWidth; x++, counter++ ) { resultImage.setPixelQuick( x, y, c, inputImage[counter] ); } } } resultImage.write("tmp.ppm"); */ mask.resize(imageWidth, imageHeight); counter = 0; for ( unsigned int y = 0; y < imageHeight; y++ ) { for ( unsigned int x = 0; x < imageWidth; x++, counter++ ) { mask(x, y) = labels[counter]; } } /* counter = 0; for ( unsigned int y = 0; y < imageHeight; y++ ) { for ( unsigned int x = 0; x < imageWidth; x++, counter++ ) { for(int c = 0; c < 3; c++) { resultImage.setPixelQuick( x, y, c, labels[counter]); } } } transformSegmentedImg( resultImage, mask);*/ // Speicher freigeben delete inputImage; inputImage = NULL; delete labels; labels = NULL; return numlabels -1; }