123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #include "RSSlic.h"
- #include <iostream>
- #include <fstream>
- #ifdef NICE_USELIB_OPENMP
- #include <omp.h>
- #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<rgb>
- 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;
- }
|