123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #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 = 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<rgb>
- 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;
- }
|