123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "RSGraphBased.h"
- #include <iostream>
- #include <fstream>
- #ifdef NICE_USELIB_OPENMP
- #include <omp.h>
- #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<rgb>
- image<rgb> *inputImage = new image<rgb>( 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<rgb> *tempResultImage = segment_image( inputImage, parameter_sigma, parameter_k, parameter_min_size, &num_ccs );
- // Kopieren der Werte aus dem image<rgb> -> 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;
- }
|