|
@@ -42,14 +42,30 @@ int main( int argc, char **argv )
|
|
|
|
|
|
Config * conf = new Config ( argc, argv );
|
|
|
|
|
|
- bool showTrainingImages= conf->gB( "featureLearning", "showTrainingImages", false );
|
|
|
- bool showTestImages= conf->gB( "featureLearning", "showTestImages", false );
|
|
|
+ bool showTrainingImages = conf->gB( "featureLearning", "showTrainingImages", false );
|
|
|
+ bool showTestImages = conf->gB( "featureLearning", "showTestImages", false );
|
|
|
+ bool showResults = conf->gB( "featureLearning", "showResults", false );
|
|
|
|
|
|
ResourceStatistics rs;
|
|
|
std::string resultdir;
|
|
|
resultdir = conf->gS( "featureLearning", "resultdir", "/tmp/");
|
|
|
|
|
|
|
|
|
+ NICE::ImageT<int> noveltyScale ( 20, 100 );
|
|
|
+ for (int j = 0; j < 100; j++)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < 20; i++)
|
|
|
+ noveltyScale(i,j) = 99-j;
|
|
|
+ }
|
|
|
+
|
|
|
+ NICE::ColorImage noveltyScaleRGB (noveltyScale.width(), noveltyScale.height() );
|
|
|
+ imageToPseudoColor( noveltyScale, noveltyScaleRGB );
|
|
|
+
|
|
|
+ std::string destinationNoveltyScale ( resultdir + "_" + "_noveltyScale.ppm");
|
|
|
+ noveltyScaleRGB.writePPM( destinationNoveltyScale );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//**********************************************
|
|
|
//
|
|
|
// READ INITIAL TRAINING SET TO COMPUTE
|
|
@@ -112,7 +128,16 @@ int main( int argc, char **argv )
|
|
|
std::cerr << "now do image To pseude color and show the initial cluster assignments" << std::endl;
|
|
|
NICE::ColorImage imgClusterAssignmentsRGB (imgClusterAssignments.width(), imgClusterAssignments.height() );
|
|
|
imageToPseudoColor( imgClusterAssignments, imgClusterAssignmentsRGB );
|
|
|
- showImage(imgClusterAssignmentsRGB, "cluster Assignments" ) ;
|
|
|
+
|
|
|
+ if ( showResults )
|
|
|
+ showImage(imgClusterAssignmentsRGB, "cluster Assignments" ) ;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::vector< std::string > list2;
|
|
|
+ StringTools::split ( filename, '/', list2 );
|
|
|
+ std::string destination ( resultdir + NICE::intToString(0) + "_" + list2.back() + "_00_initialClusterAssignments.ppm");
|
|
|
+ imgClusterAssignmentsRGB.writePPM( destination );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//**********************************************
|
|
@@ -152,9 +177,31 @@ int main( int argc, char **argv )
|
|
|
|
|
|
NICE::ColorImage orig( filename );
|
|
|
|
|
|
+ NICE::ImageT< int > imgClusterAssignments;
|
|
|
+ imgClusterAssignments = featureLearning->evaluateCurrentCodebookByAssignments(filename , false /* beforeComputingNewFeatures */, false /* _binaryShowLatestPrototype*/ );
|
|
|
+
|
|
|
+ NICE::ColorImage imgClusterAssignmentsRGB (imgClusterAssignments.width(), imgClusterAssignments.height() );
|
|
|
+ imageToPseudoColor( imgClusterAssignments, imgClusterAssignmentsRGB );
|
|
|
+
|
|
|
NICE::FloatImage noveltyImageBefore;
|
|
|
noveltyImageBefore = featureLearning->evaluateCurrentCodebookByDistance( filename , true /* beforeComputingNewFeatures */ );
|
|
|
|
|
|
+ NICE::ColorImage noveltyImageBeforeRGB (noveltyImageBefore.width(), noveltyImageBefore.height() );
|
|
|
+ imageToPseudoColor( noveltyImageBefore, noveltyImageBeforeRGB );
|
|
|
+
|
|
|
+ if ( showResults )
|
|
|
+ showImage(imgClusterAssignmentsRGB, "cluster Assignments" ) ;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::vector< std::string > list2;
|
|
|
+ StringTools::split ( filename, '/', list2 );
|
|
|
+ std::string destination ( resultdir + NICE::intToString(0) + "_" + list2.back() + "_00_initialClusterAssignments.ppm");
|
|
|
+ imgClusterAssignmentsRGB.writePPM( destination );
|
|
|
+
|
|
|
+ std::string destinationNovelty ( resultdir + NICE::intToString(0) + "_" + list2.back() + "_01_initialClusterDistances.ppm");
|
|
|
+ noveltyImageBeforeRGB.writePPM( destinationNovelty );
|
|
|
+ }
|
|
|
+
|
|
|
//**********************************************
|
|
|
//
|
|
|
// IS THIS IMAGE NOVEL?
|
|
@@ -175,81 +222,109 @@ int main( int argc, char **argv )
|
|
|
std::cerr << " --- NOVEL --- " << std::endl;
|
|
|
}
|
|
|
|
|
|
- //**********************************************
|
|
|
- //
|
|
|
- // LEARN NEW FEATURE FOR A NOVEL IMAGE
|
|
|
- //
|
|
|
- //**********************************************
|
|
|
-
|
|
|
- featureLearning->learnNewFeatures( filename );
|
|
|
-
|
|
|
- //and update the codebook pointer within our novelty detection algorithm
|
|
|
- //TODO this should be done, but currently we do not care about
|
|
|
-// novDetector->setCodebook( featureLearning->getCurrentCodebook() );
|
|
|
-
|
|
|
- //**********************************************
|
|
|
- //
|
|
|
- // EVALUATE HOW WELL THE CURRENT IMAGE
|
|
|
- // CAN BE EXPLAINED AFTER
|
|
|
- // COMPUTING A NEW FEATURE
|
|
|
- //
|
|
|
- // SHOULD WE REPEAT THIS UNTIL THE IMAGE
|
|
|
- // IS NOT CLASSIFIED AS "NOVEL" ANYMORE?
|
|
|
- //
|
|
|
- //**********************************************
|
|
|
-
|
|
|
- NICE::FloatImage noveltyImageAfter;
|
|
|
- noveltyImageAfter = featureLearning->evaluateCurrentCodebookByDistance( filename , false /* beforeComputingNewFeatures */ );
|
|
|
-
|
|
|
- NICE::FloatImage noveltyImageDifference ( noveltyImageAfter.width(), noveltyImageAfter.height());
|
|
|
- for ( uint y = 0 ; y < ( uint ) noveltyImageAfter.height() ; y++ )
|
|
|
+ while ( b_isImageNovel )
|
|
|
{
|
|
|
- for ( uint x = 0 ; x < ( uint ) noveltyImageAfter.width(); x++ )
|
|
|
+
|
|
|
+ //**********************************************
|
|
|
+ //
|
|
|
+ // LEARN NEW FEATURE FOR A NOVEL IMAGE
|
|
|
+ //
|
|
|
+ //**********************************************
|
|
|
+
|
|
|
+ featureLearning->learnNewFeatures( filename );
|
|
|
+
|
|
|
+ //and update the codebook pointer within our novelty detection algorithm
|
|
|
+ //TODO this should be done, but currently we do not care about
|
|
|
+ // novDetector->setCodebook( featureLearning->getCurrentCodebook() );
|
|
|
+
|
|
|
+ //**********************************************
|
|
|
+ //
|
|
|
+ // EVALUATE HOW WELL THE CURRENT IMAGE
|
|
|
+ // CAN BE EXPLAINED AFTER
|
|
|
+ // COMPUTING A NEW FEATURE
|
|
|
+ //
|
|
|
+ // SHOULD WE REPEAT THIS UNTIL THE IMAGE
|
|
|
+ // IS NOT CLASSIFIED AS "NOVEL" ANYMORE?
|
|
|
+ //
|
|
|
+ //**********************************************
|
|
|
+
|
|
|
+ NICE::FloatImage noveltyImageAfter;
|
|
|
+ noveltyImageAfter = featureLearning->evaluateCurrentCodebookByDistance( filename , false /* beforeComputingNewFeatures */ );
|
|
|
+
|
|
|
+ NICE::FloatImage noveltyImageDifference ( noveltyImageAfter.width(), noveltyImageAfter.height());
|
|
|
+ for ( uint y = 0 ; y < ( uint ) noveltyImageAfter.height() ; y++ )
|
|
|
{
|
|
|
- noveltyImageDifference(x,y) = fabs ( noveltyImageBefore(x,y) - noveltyImageAfter(x,y) );
|
|
|
+ for ( uint x = 0 ; x < ( uint ) noveltyImageAfter.width(); x++ )
|
|
|
+ {
|
|
|
+ noveltyImageDifference(x,y) = fabs ( noveltyImageBefore(x,y) - noveltyImageAfter(x,y) );
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- std::cerr << "min diff: " << noveltyImageDifference.min() << " and max diff: " << noveltyImageDifference.max() << std::endl;
|
|
|
-
|
|
|
- NICE::ColorImage noveltyImageDifferenceRGB (noveltyImageAfter.width(), noveltyImageAfter.height() );
|
|
|
- imageToPseudoColor( noveltyImageDifference, noveltyImageDifferenceRGB );
|
|
|
-
|
|
|
- std::vector< std::string > list2;
|
|
|
- StringTools::split ( filename, '/', list2 );
|
|
|
+
|
|
|
+ std::cerr << "min diff: " << noveltyImageDifference.min() << " and max diff: " << noveltyImageDifference.max() << std::endl;
|
|
|
+
|
|
|
+ NICE::ColorImage noveltyImageDifferenceRGB (noveltyImageAfter.width(), noveltyImageAfter.height() );
|
|
|
+ imageToPseudoColor( noveltyImageDifference, noveltyImageDifferenceRGB );
|
|
|
+
|
|
|
+ std::vector< std::string > list2;
|
|
|
+ StringTools::split ( filename, '/', list2 );
|
|
|
|
|
|
- std::string destination ( resultdir + NICE::intToString(imageCnt) + "_" + list2.back() + "_4_differenceOfNovelties.ppm");
|
|
|
- noveltyImageDifferenceRGB.writePPM( destination );
|
|
|
+ if ( showResults )
|
|
|
+ {
|
|
|
+ showImage( noveltyImageDifferenceRGB, "Difference of novelty images" );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::string destination ( resultdir + NICE::intToString(imageCnt) + "_" + list2.back() + "_02_initialLoopClusterAssignments.ppm");
|
|
|
+ imgClusterAssignmentsRGB.writePPM( destination );
|
|
|
|
|
|
- NICE::ImageT< int > imgClusterAssignmentsBinary;
|
|
|
- imgClusterAssignmentsBinary = featureLearning->evaluateCurrentCodebookByAssignments(filename , true, true /* _binaryShowLatestPrototype*/ );
|
|
|
-
|
|
|
- NICE::ImageT< int > imgClusterAssignments;
|
|
|
- imgClusterAssignments = featureLearning->evaluateCurrentCodebookByAssignments(filename , true, false /* _binaryShowLatestPrototype*/ );
|
|
|
+ std::string destinationNoveltyDifference ( resultdir + NICE::intToString(imageCnt) + "_" + list2.back() + "_03_noveltyDifferences.ppm");
|
|
|
+ noveltyImageDifferenceRGB.writePPM( destinationNoveltyDifference );
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- NICE::ColorImage imgClusterAssignmentsBinaryRGB (imgClusterAssignmentsBinary.width(), imgClusterAssignmentsBinary.height() );
|
|
|
- imageToPseudoColor( imgClusterAssignmentsBinary, imgClusterAssignmentsBinaryRGB );
|
|
|
-
|
|
|
- NICE::ColorImage imgClusterAssignmentsRGB (imgClusterAssignments.width(), imgClusterAssignments.height() );
|
|
|
- imageToPseudoColor( imgClusterAssignments, imgClusterAssignmentsRGB );
|
|
|
-
|
|
|
- if ( false )
|
|
|
- {
|
|
|
- showImage(imgClusterAssignmentsBinaryRGB, "cluster Assignments Binary (latest prototype)" ) ;
|
|
|
- showImage(imgClusterAssignmentsRGB, "cluster Assignments" ) ;
|
|
|
+ NICE::ImageT< int > imgClusterAssignmentsBinary;
|
|
|
+ imgClusterAssignmentsBinary = featureLearning->evaluateCurrentCodebookByAssignments(filename , true, true /* _binaryShowLatestPrototype*/ );
|
|
|
+
|
|
|
+ NICE::ImageT< int > imgClusterAssignments;
|
|
|
+ imgClusterAssignments = featureLearning->evaluateCurrentCodebookByAssignments(filename , true, false /* _binaryShowLatestPrototype*/ );
|
|
|
+
|
|
|
+
|
|
|
+ NICE::ColorImage imgClusterAssignmentsBinaryRGB (imgClusterAssignmentsBinary.width(), imgClusterAssignmentsBinary.height() );
|
|
|
+ imageToPseudoColor( imgClusterAssignmentsBinary, imgClusterAssignmentsBinaryRGB );
|
|
|
+
|
|
|
+ NICE::ColorImage imgClusterAssignmentsRGB (imgClusterAssignments.width(), imgClusterAssignments.height() );
|
|
|
+ imageToPseudoColor( imgClusterAssignments, imgClusterAssignmentsRGB );
|
|
|
+
|
|
|
+ if ( showResults )
|
|
|
+ {
|
|
|
+ showImage(imgClusterAssignmentsBinaryRGB, "cluster Assignments Binary (latest prototype)" ) ;
|
|
|
+ showImage(imgClusterAssignmentsRGB, "cluster Assignments" ) ;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::string destination ( resultdir + NICE::intToString(imageCnt) + "_" + list2.back() + "_5_clusterAssignments.ppm");
|
|
|
+ std::string destinationBinary ( resultdir + NICE::intToString(imageCnt) + "_" + list2.back() + "_6_clusterAssignmentsBinary.ppm");
|
|
|
+
|
|
|
+ imgClusterAssignmentsRGB.writePPM( destination );
|
|
|
+ imgClusterAssignmentsBinaryRGB.writePPM( destinationBinary );
|
|
|
+ }
|
|
|
+
|
|
|
+ //check, whether the image will still be seen as novel or not
|
|
|
+ // i.e., are we able to "explain" the image with the lately computed codebook entry?
|
|
|
+ b_isImageNovel = novDetector->evaluateNoveltyOfImage( noveltyImageAfter ) ;
|
|
|
+
|
|
|
+ if ( ! b_isImageNovel )
|
|
|
+ {
|
|
|
+ std::cerr << " --- NOT NOVEL ANYMORE --- " << std::endl << std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << " --- STILL NOVEL --- " << std::endl;
|
|
|
+ noveltyImageBefore = noveltyImageAfter;
|
|
|
+ }
|
|
|
+
|
|
|
+ //artifial break for the moment
|
|
|
+ break;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- std::string destination ( resultdir + NICE::intToString(imageCnt) + "_" + list2.back() + "_5_clusterAssignments.ppm");
|
|
|
- std::string destinationBinary ( resultdir + NICE::intToString(imageCnt) + "_" + list2.back() + "_6_clusterAssignmentsBinary.ppm");
|
|
|
-
|
|
|
- imgClusterAssignmentsRGB.writePPM( destination );
|
|
|
- imgClusterAssignmentsBinaryRGB.writePPM( destinationBinary );
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
imageCnt++;
|