// -*- C++ -*- // Copyright 2006 Deutsches Forschungszentrum fuer Kuenstliche Intelligenz // or its licensors, as applicable. // Copyright 1995-2005 by Thomas M. Breuel // // You may not use this file except under the terms of the accompanying license. // // Licensed under the Apache License, Version 2.0 (the "License"); you // may not use this file except in compliance with the License. You may // obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // Project: segeval - Color based evaluation of page segmentation // File: seg-eval.cc // Purpose: Color based segmentation evaluation using graph matching // Responsible: Faisal Shafait (faisal.shafait@dfki.de) // Reviewer: Yves Rangoni (rangoni@iupr.org) // Primary Repository: // Web Sites: www.iupr.org, www.dfki.de #include "seg-eval.h" namespace ocropus { int normalize_image(intarray &image, int &noiseval, bool allow_dont_care) { Enumerator enumerator(1); for(int i=0;i=0); ASSERT(max(model)<1000); ASSERT(max(image)<1000); ASSERT(model.length1d()==image.length1d()); int mmodel = max(model)+1; int mimage = max(image)+1; //printf("Model length= %d, Image length = %d\n",mmodel,mimage); table.resize(mmodel,mimage); fill(table,0); for(int i=0;ithreshold || table(i,j)>=absthresh) { mover++; splits++; } } if(splits>1) {movercount++; ioverseg.push(i);} } for(int j=1;jthreshold || table(i,j)>=absthresh) { iover++; splits++; } } if(splits>1) {iovercount++; iunderseg.push(j); } } } void Evaluator::calc_correct() { intarray rowsum,colsum; int ncols = table.dim(0); int nrows = table.dim(1); colsum.resize(ncols); rowsum.resize(nrows); fill(colsum,0); fill(rowsum,0); for(int i=1;i=(1-threshold)*colsum[i]) && //Edge incident to the image is significant (table(i,j)>=(1-threshold)*rowsum[j]) && (table(i,j)>=absthresh)){ //Model has no other significant edge for(int n=1;n=absthresh) extraedges = true; } //Image has no other significant edge for(int n=1;n=absthresh) extraedges = true; } //Image has no other significant edge if(!extraedges) correct ++; } } } } void Evaluator::calc_accuracy() { int ncols = table.dim(0); int nrows = table.dim(1); float sum = 0; float maxi = 0; float effi = 0; int gt_seg_counter=0; intarray rowsum,colsum; colsum.resize(ncols); rowsum.resize(nrows); fill(colsum,0); fill(rowsum,0); for(int i=1;imaxi) maxi = table(i,j); //sum += table(i,j); } if(sum) effi += maxi/sum; } accuracy = effi / gt_seg_counter; } int segeval_full( intarray &model, intarray &image, Evaluator &eval, intarray &fmodel, intarray &fimage, int &num_over,int &num_under,int &num_miss,int &num_falarm, int athresh, float rthresh) { eval.clear(100); eval.set_thresh(athresh, rthresh); copy(fmodel, model); copy(fimage, image); int mnoiseval=-1, inoiseval=-1; eval.set_noiseval(mnoiseval, inoiseval); eval.add(fmodel, fimage); /*int mcolors = normalize_image(fmodel, mnoiseval); int icolors = normalize_image(fimage, inoiseval); printf("\nModel Colors = %d\t Image Colors = %d\n",mcolors,icolors); printf("\nModel Noise value = %d\t Image Noise value = %d\n",mnoiseval,inoiseval); printf("groundtruth-components %d\n",eval.mcount); printf("segmentation-components %d\n",eval.icount-eval.falarm); printf("total-oversegmentation %d\n",eval.mover-eval.mcount); printf("total-undersegmentation %d\n",eval.iover-eval.icount); printf("oversegmented-comps %d\n",eval.movercount); printf("undersegmented-comps %d\n",eval.iovercount); printf("missed-components %d\n",eval.miss); printf("false alarms %d\n",eval.falarm); printf("total correct %d\n",eval.correct); printf("total accuracy %0.3f\n",eval.accuracy);*/ num_over = eval.ioverseg.length(); num_under = eval.iunderseg.length(); num_miss = eval.imissed.length(); num_falarm= eval.ifalarm.length(); for(int i=0;i