#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 = -1; regionsize = 50; compactness = 10.0; lab = true; } RSSlic::RSSlic(const Config *conf ) { spcount = conf->gI("RSSlic", "spcount", -1); regionsize = conf->gI("RSSlic", "regionsize", 50); compactness = conf->gD("RSSlic", "compactness", 10.0); lab = conf->gB("RSSlic", "useLAB", true); } 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[imageWidth*imageHeight]; unsigned long int counter = 0; for ( unsigned int y = 0; y < imageHeight; y++) { for ( unsigned int x = 0; x < imageWidth; x++, counter++) { uint tmp = 255; for (int c = 0; c < 3; c++) { tmp = tmp<<8; tmp+=(unsigned char)img.getPixelQuick( x, y, c ); } inputImage[counter] = tmp; } } int* labels = new int[imageWidth*imageHeight]; // Eingabebild segmentieren SLIC slic; int numlabels = 0; int superpixelsize = regionsize; if(spcount > 0) { superpixelsize = 0.5+double(imageWidth*imageHeight)/double(spcount); } slic.DoSuperpixelSegmentation_ForGivenSuperpixelSize(inputImage, imageWidth, imageHeight, labels, numlabels, superpixelsize, compactness, lab); 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; }