Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Modules/ImageProcessor/ImageProcessorTools/GT2004EdgeDetection.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file Modules/ImageProcessor/ImageProcessorTools/GT2004EdgeDetection.cpp
    00003 *
    00004 * Implementation of GT2004EdgeDetection.
    00005 *
    00006 * @author <A href="mailto:sadprofessor@web.de">Bernd Schmidt</A>
    00007 */
    00008
    00009 #include "GT2004EdgeDetection.h"
    00010 #include "Tools/Location.h"
    00011 #include <math.h>
    00012
    00013 enum{DEFAULT_EDGE_THRESHOLD = 12};
    00014
    00015 GT2004EdgeDetection::GT2004EdgeDetection(
    00016                      ImageProcessor& processor,
    00017                      MSH2004ColorCorrector& corrector)
    00018   :ip(processor),
    00019   corrector(corrector),
    00020   susanDetector(8),
    00021   threshold(DEFAULT_EDGE_THRESHOLD)
    00022 {
    00023
    00024 }
    00025
    00026 GT2004EdgeDetection::~GT2004EdgeDetection(){
    00027 }
    00028
    00029
    00030 bool GT2004EdgeDetection::scanEast(int& x, int& y){
    00031   if (!insideImage(x,y)) return false;
    00032   int voteBuffer = 0;
    00033   int vote = fastCrossEdgeVote(x,y);
    00034   int x2 = ip.image.cameraInfo.resolutionWidth-1;
    00035
    00036   while(x < x2){
    00037     if (vote > threshold || voteBuffer != 0){
    00038       if (voteBuffer < vote) voteBuffer = vote;
    00039       else{
    00040         x--;
    00041         return true; //edge found (found local maximum)
    00042       }
    00043     }
    00044     x++;
    00045     vote = fastCrossEdgeVote(x,y);
    00046   }
    00047
    00048   if (vote > threshold){
    00049     x--;
    00050     return true; //edgeFound (vote high enough, so found edge on Border)
    00051   }
    00052   else return false; // noEdgeFound
    00053 }
    00054
    00055 bool GT2004EdgeDetection::scanWest(int& x, int& y){
    00056   if (!insideImage(x,y)) return false;
    00057   int voteBuffer = 0;
    00058   int vote = fastCrossEdgeVote(x,y);
    00059
    00060   while(x > 1){
    00061     if (vote > threshold || voteBuffer != 0){
    00062       if (voteBuffer < vote) voteBuffer = vote;
    00063       else{
    00064         x++;
    00065         return true; //edge found (found local maximum)
    00066       }
    00067     }
    00068     x--;
    00069     vote = fastCrossEdgeVote(x,y);
    00070   }
    00071
    00072   if (vote > threshold){
    00073     x++;
    00074     return true; //edgeFound (vote high enough, so found edge on Border)
    00075   }
    00076   else return false; // noEdgeFound
    00077 }
    00078
    00079 bool GT2004EdgeDetection::scanNorth(int& x, int& y){
    00080   if(!insideImage(x,y)) return false;
    00081   int voteBuffer = 0;
    00082   int vote = fastCrossEdgeVote(x,y);
    00083
    00084   while(y > 1){
    00085     if (vote > threshold || voteBuffer != 0){
    00086       if (voteBuffer < vote) voteBuffer = vote;
    00087       else{
    00088         y++;
    00089         return true; //edge found (found local maximum)
    00090       }
    00091     }
    00092     y--;
    00093     vote = fastCrossEdgeVote(x,y);
    00094   }
    00095
    00096   if (vote > threshold){
    00097     y++;
    00098     return true; //edgeFound (vote high enough, so found edge on Border)
    00099   }
    00100   else return false; // noEdgeFound
    00101 }
    00102
    00103 bool GT2004EdgeDetection::scanSouth(int& x, int& y){
    00104   if (!insideImage(x,y)) return false;
    00105   int voteBuffer = 0;
    00106   int vote = fastCrossEdgeVote(x,y);
    00107   int y2 = ip.image.cameraInfo.resolutionHeight -2;
    00108
    00109   while(y < y2){
    00110     if (vote > threshold || voteBuffer != 0){
    00111       if (voteBuffer < vote) voteBuffer = vote;
    00112       else{
    00113         y--;
    00114         return true; //edge found (found local maximum)
    00115       }
    00116     }
    00117     y++;
    00118     vote = fastCrossEdgeVote(x,y);
    00119   }
    00120
    00121   if (vote > threshold){
    00122     y--;
    00123     return true; //edgeFound (vote high enough, so found edge on Border)
    00124   }
    00125   else return false; // noEdgeFound
    00126 }
    00127
    00128 bool GT2004EdgeDetection::ballScanEast(int& x, int& y){
    00129   int voteBuffer = 0;
    00130   int vote = ballEdgeVote(x,y);
    00131
    00132   while(vote > -1){
    00133     if (vote > threshold || voteBuffer != 0){
    00134       if (voteBuffer < vote) voteBuffer = vote;
    00135       else{
    00136         x--;
    00137         return true; //edge found (found local maximum)
    00138       }
    00139     }
    00140     x++;
    00141     vote = ballEdgeVote(x,y);
    00142   }
    00143
    00144   if (vote > threshold){
    00145     x--;
    00146     return true; //edgeFound (vote high enough, so found edge on Border)
    00147   }
    00148   else return false; // noEdgeFound
    00149 }
    00150
    00151 bool GT2004EdgeDetection::ballScanWest(int& x, int& y){
    00152   int voteBuffer = 0;
    00153   int vote = ballEdgeVote(x,y);
    00154
    00155   while(vote > -1){
    00156     if (vote > threshold || voteBuffer != 0){
    00157       if (voteBuffer < vote) voteBuffer = vote;
    00158       else{
    00159         x++;
    00160         return true; //edge found (found local maximum)
    00161       }
    00162     }
    00163     x--;
    00164     vote = ballEdgeVote(x,y);
    00165   }
    00166
    00167   if (vote > threshold){
    00168     x++;
    00169     return true; //edgeFound (vote high enough, so found edge on Border)
    00170   }
    00171   else return false; // noEdgeFound
    00172 }
    00173
    00174 bool GT2004EdgeDetection::scan(int& x,int& y,Vector2<double> direction){
    00175   cx = 1;
    00176   cy = 1;
    00177
    00178   if (direction.x < 0) cx = -1;
    00179   if (direction.y < 0) cy = -1;
    00180
    00181   tempX = x;
    00182   tempY = y;
    00183
    00184   int vote = crossEdgeVote(x,y);
    00185   int buffer = 0;
    00186   if (vote > threshold) buffer = vote;
    00187
    00188   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00189
    00190   dx = abs((int)(direction.x * 500));
    00191   dy = abs((int)(direction.y * 500));
    00192
    00193   if (dx > dy){
    00194     e = dx - 2*dy;
    00195     f = 2*(dx - dy);
    00196     g = -2*dy;
    00197     //setPixel(0,0)
    00198
    00199     for (x+=cx;vote != -1;x+=cx) {
    00200       if (e<0) {
    00201         y+=cy;
    00202         e+=f;
    00203       }
    00204       else {
    00205         e+=g;
    00206       }
    00207       //setPixel(x,y)
    00208       //DOT(imageProcessor_general,x,y,
    00209       //  Drawings::white, Drawings::red);
    00210       vote = crossEdgeVote(x,y);
    00211
    00212       if (vote > threshold || buffer != 0){
    00213         if (buffer < vote) buffer = vote;
    00214         else{
    00215           x = tempX;
    00216           y = tempY;
    00217           return true; //edge found (found local maximum)
    00218         }
    00219       }
    00220
    00221       tempX = x;
    00222       tempY = y;
    00223     }
    00224   }
    00225   else{
    00226     e = dy - 2*dx;
    00227     f = 2*(dy - dx);
    00228     g = -2*dx;
    00229     //setPixel(0,0)
    00230
    00231
    00232     for (y+=cy;vote != -1;y+=cy) {
    00233       if (e<0) {
    00234         x+=cx;
    00235         e+=f;
    00236       }
    00237       else {
    00238         e+=g;
    00239       }
    00240       //setPixel(x,y)
    00241       //DOT(imageProcessor_general,x,y,
    00242       //  Drawings::white, Drawings::red);
    00243       vote = crossEdgeVote(x,y);
    00244
    00245       if (vote > threshold || buffer != 0){
    00246         if (buffer < vote) buffer = vote;
    00247         else{
    00248           x = tempX;
    00249           y = tempY;
    00250           return true; //edge found (found local maximum)
    00251         }
    00252       }
    00253
    00254       tempX = x;
    00255       tempY = y;
    00256     }
    00257   }
    00258
    00259   if (buffer != 0){
    00260         x = tempX;
    00261         y = tempY;
    00262         return true; //edge found (found edge on border)
    00263   }
    00264
    00265   return false; //no edge found
    00266 }
    00267
    00268 bool GT2004EdgeDetection::bufferedScan(int& x,int& y,Vector2<double> direction){
    00269
    00270   cx = 1;
    00271   cy = 1;
    00272
    00273   if (direction.x < 0) cx = -1;
    00274   if (direction.y < 0) cy = -1;
    00275
    00276   tempX = x;
    00277   tempY = y;
    00278
    00279   int vote = crossEdgeVote(x,y);
    00280   currentColor = lastColor = getColor(x,y);
    00281   bufferSize = 0;
    00282
    00283   int buffer = 0;
    00284   if (vote > threshold) buffer = vote;
    00285
    00286   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00287
    00288   dx = abs((int)(direction.x * 500));
    00289   dy = abs((int)(direction.y * 500));
    00290
    00291   if (dx > dy){
    00292     e = dx - 2*dy;
    00293     f = 2*(dx - dy);
    00294     g = -2*dy;
    00295     //setPixel(0,0)
    00296
    00297     for (x+=cx;vote != -1;x+=cx) {
    00298       if (e<0) {
    00299         y+=cy;
    00300         e+=f;
    00301       }
    00302       else {
    00303         e+=g;
    00304       }
    00305       //setPixel(x,y)
    00306       //DOT(imageProcessor_general,x,y,
    00307       //  Drawings::white, Drawings::red);
    00308       vote = crossEdgeVote(x,y);
    00309       currentColor = getColor(x,y);
    00310       colorRange++;
    00311
    00312       if (currentColor != lastColor){
    00313         addColor();
    00314         // there are to many colorChanges between two edge-points
    00315         if (bufferSize > 19) return false;
    00316       }
    00317
    00318       if (vote > threshold || buffer != 0){
    00319         if (buffer < vote) buffer = vote;
    00320         else{
    00321           x = tempX;
    00322           y = tempY;
    00323           if (colorRange!=0){
    00324             lastColor = currentColor;
    00325             addColor();
    00326           }
    00327           return true; //edge found (found local maximum)
    00328         }
    00329       }
    00330
    00331       tempX = x;
    00332       tempY = y;
    00333       lastColor = currentColor;
    00334     }
    00335   }
    00336   else{
    00337     e = dy - 2*dx;
    00338     f = 2*(dy - dx);
    00339     g = -2*dx;
    00340     //setPixel(0,0)
    00341
    00342
    00343     for (y+=cy;vote != -1;y+=cy) {
    00344       if (e<0) {
    00345         x+=cx;
    00346         e+=f;
    00347       }
    00348       else {
    00349         e+=g;
    00350       }
    00351       //setPixel(x,y)
    00352       //DOT(imageProcessor_general,x,y,
    00353       //  Drawings::white, Drawings::red);
    00354       vote = crossEdgeVote(x,y);
    00355       currentColor = getColor(x,y);
    00356       colorRange++;
    00357
    00358       if (currentColor != lastColor){
    00359         addColor();
    00360         // there are to many colorChanges between two edge-points
    00361         if (bufferSize > 19) return false;
    00362       }
    00363
    00364       if (vote > threshold || buffer != 0){
    00365         if (buffer < vote) buffer = vote;
    00366         else{
    00367           if (colorRange!=0){
    00368             lastColor = currentColor;
    00369             addColor();
    00370           }
    00371           x = tempX;
    00372           y = tempY;
    00373           return true; //edge found (found local maximum)
    00374         }
    00375       }
    00376
    00377       tempX = x;
    00378       tempY = y;
    00379       lastColor = currentColor;
    00380     }
    00381   }
    00382
    00383   if (buffer != 0){
    00384         if (colorRange!=0){
    00385           lastColor = currentColor;
    00386           addColor();
    00387         }
    00388         x = tempX;
    00389         y = tempY;
    00390         return true; //edge found (found edge on border)
    00391   }
    00392
    00393   return false; //no edge found
    00394 }
    00395
    00396 bool GT2004EdgeDetection::bufferedScan(int& x,int& y){
    00397
    00398   currentColor = lastColor = getColor(x,y);
    00399   colorRange = 0;
    00400   bufferSize = 0;
    00401
    00402   //skipping 3 pixels, not to detect 1 edge 2 times
    00403   for (int i = 0;i<3;i++){
    00404     skip(x,y);
    00405     currentColor = getColor(x,y);
    00406     colorRange++;
    00407     if (currentColor != lastColor)addColor();
    00408     lastColor = currentColor;
    00409   }
    00410
    00411   tempX = x;
    00412   tempY = y;
    00413
    00414   int vote = crossEdgeVote(x,y);
    00415
    00416   int buffer = 0;
    00417   if (vote > threshold) buffer = vote;
    00418
    00419   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00420
    00421   if (dx > dy){
    00422     for (x+=cx;vote != -1;x+=cx) {
    00423       if (e<0) {
    00424         y+=cy;
    00425         e+=f;
    00426       }
    00427       else {
    00428         e+=g;
    00429       }
    00430       //setPixel(x,y)
    00431       //DOT(imageProcessor_general,x,y,
    00432       //  Drawings::white, Drawings::red);
    00433       vote = crossEdgeVote(x,y);
    00434       currentColor = getColor(x,y);
    00435       colorRange++;
    00436
    00437       if (currentColor != lastColor){
    00438         addColor();
    00439         // there are to many colorChanges between two edge-points
    00440         if (bufferSize > 19) return false;
    00441       }
    00442
    00443       if (vote > threshold || buffer != 0){
    00444         if (buffer < vote) buffer = vote;
    00445         else{
    00446           x = tempX;
    00447           y = tempY;
    00448           if (colorRange!=0){
    00449             lastColor = currentColor;
    00450             addColor();
    00451           }
    00452           return true; //edge found (found local maximum)
    00453         }
    00454       }
    00455
    00456       tempX = x;
    00457       tempY = y;
    00458       lastColor = currentColor;
    00459     }
    00460   }
    00461   else{
    00462     for (y+=cy;vote != -1;y+=cy) {
    00463       if (e<0) {
    00464         x+=cx;
    00465         e+=f;
    00466       }
    00467       else {
    00468         e+=g;
    00469       }
    00470       //setPixel(x,y)
    00471       //DOT(imageProcessor_general,x,y,
    00472       //  Drawings::white, Drawings::red);
    00473       vote = crossEdgeVote(x,y);
    00474       currentColor = getColor(x,y);
    00475       colorRange++;
    00476
    00477       if (currentColor != lastColor){
    00478         addColor();
    00479       }
    00480
    00481       if (vote > threshold || buffer != 0){
    00482         if (buffer < vote) buffer = vote;
    00483         else{
    00484           if (colorRange!=0){
    00485             lastColor = currentColor;
    00486             addColor();
    00487           }
    00488           x = tempX;
    00489           y = tempY;
    00490           return true; //edge found (found local maximum)
    00491         }
    00492       }
    00493
    00494       tempX = x;
    00495       tempY = y;
    00496       lastColor = currentColor;
    00497     }
    00498   }
    00499
    00500   if (buffer != 0){
    00501         if (colorRange!=0){
    00502           addColor();
    00503         }
    00504         x = tempX;
    00505         y = tempY;
    00506         return true; //edge found (found edge on border)
    00507   }
    00508
    00509   return false; //no edge found
    00510 }
    00511
    00512 bool GT2004EdgeDetection::scanField(int& x,int& y,Vector2<double> direction){
    00513   cx = 1;
    00514   cy = 1;
    00515
    00516   if (direction.x < 0) cx = -1;
    00517   if (direction.y < 0) cy = -1;
    00518
    00519   tempX = x;
    00520   tempY = y;
    00521
    00522   int vote = fieldEdgeVote(x,y);
    00523   int buffer = 0;
    00524   if (vote > threshold) buffer = vote;
    00525
    00526   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00527
    00528   dx = abs((int)(direction.x * 500));
    00529   dy = abs((int)(direction.y * 500));
    00530
    00531   if (dx > dy){
    00532     e = dx - 2*dy;
    00533     f = 2*(dx - dy);
    00534     g = -2*dy;
    00535     //setPixel(0,0)
    00536
    00537     for (x+=cx;vote != -1;x+=cx) {
    00538       if (e<0) {
    00539         y+=cy;
    00540         e+=f;
    00541       }
    00542       else {
    00543         e+=g;
    00544       }
    00545       //setPixel(x,y)
    00546       //DOT(imageProcessor_general,x,y,
    00547       //  Drawings::white, Drawings::red);
    00548       vote = fieldEdgeVote(x,y);
    00549
    00550       if (vote > threshold || buffer != 0){
    00551         if (buffer < vote) buffer = vote;
    00552         else{
    00553           x = tempX;
    00554           y = tempY;
    00555           return true; //edge found (found local maximum)
    00556         }
    00557       }
    00558
    00559       tempX = x;
    00560       tempY = y;
    00561     }
    00562   }
    00563   else{
    00564     e = dy - 2*dx;
    00565     f = 2*(dy - dx);
    00566     g = -2*dx;
    00567     //setPixel(0,0)
    00568
    00569
    00570     for (y+=cy;vote != -1;y+=cy) {
    00571       if (e<0) {
    00572         x+=cx;
    00573         e+=f;
    00574       }
    00575       else {
    00576         e+=g;
    00577       }
    00578       //setPixel(x,y)
    00579       //DOT(imageProcessor_general,x,y,
    00580       //  Drawings::white, Drawings::red);
    00581       vote = fieldEdgeVote(x,y);
    00582
    00583       if (vote > threshold || buffer != 0){
    00584         if (buffer < vote) buffer = vote;
    00585         else{
    00586           x = tempX;
    00587           y = tempY;
    00588           return true; //edge found (found local maximum)
    00589         }
    00590       }
    00591
    00592       tempX = x;
    00593       tempY = y;
    00594     }
    00595   }
    00596
    00597   if (buffer != 0){
    00598     x = tempX;
    00599     y = tempY;
    00600     return true; //edge found (found edge on border)
    00601   }
    00602
    00603   return false; //no edge found
    00604 }
    00605
    00606 bool GT2004EdgeDetection::scanField(int& x,int& y){
    00607
    00608   tempX = x;
    00609   tempY = y;
    00610
    00611   int vote = fieldEdgeVote(x,y);
    00612   int buffer = 0;
    00613   if (vote > threshold) buffer = vote;
    00614
    00615   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00616   if (dx > dy){
    00617     for (x+=cx;vote != -1;x+=cx) {
    00618       if (e<0) {
    00619         y+=cy;
    00620         e+=f;
    00621       }
    00622       else {
    00623         e+=g;
    00624       }
    00625       //setPixel(x,y)
    00626       //DOT(imageProcessor_general,x,y,
    00627       //  Drawings::white, Drawings::red);
    00628       vote = fieldEdgeVote(x,y);
    00629
    00630       if (vote > threshold || buffer != 0){
    00631         if (buffer < vote) buffer = vote;
    00632         else{
    00633           x = tempX;
    00634           y = tempY;
    00635           return true; //edge found (found local maximum)
    00636         }
    00637       }
    00638
    00639       tempX = x;
    00640       tempY = y;
    00641     }
    00642   }
    00643   else{
    00644     for (y+=cy;vote != -1;y+=cy) {
    00645       if (e<0) {
    00646         x+=cx;
    00647         e+=f;
    00648       }
    00649       else {
    00650         e+=g;
    00651       }
    00652       //setPixel(x,y)
    00653       //DOT(imageProcessor_general,x,y,
    00654       //  Drawings::white, Drawings::red);
    00655       vote = fieldEdgeVote(x,y);
    00656
    00657       if (vote > threshold || buffer != 0){
    00658         if (buffer < vote) buffer = vote;
    00659         else{
    00660           x = tempX;
    00661           y = tempY;
    00662           return true; //edge found (found local maximum)
    00663         }
    00664       }
    00665       tempX = x;
    00666       tempY = y;
    00667     }
    00668   }
    00669
    00670   if (buffer != 0){
    00671         x = tempX;
    00672         y = tempY;
    00673         return true; //edge found (found edge on border)
    00674   }
    00675
    00676   return false; //no edge found
    00677 }
    00678
    00679 bool GT2004EdgeDetection::scan(int& x,int& y,int x1,int y1){
    00680   cx = 1;
    00681   cy = 1;
    00682
    00683   dx = x1 - x;
    00684   dy = y1 - y;
    00685
    00686   if (dx < 0) cx = -1;
    00687   if (dy < 0) cy = -1;
    00688
    00689   tempX = x;
    00690   tempY = y;
    00691
    00692   int vote = crossEdgeVote(x,y);
    00693   int buffer = 0;
    00694   if (vote > threshold) buffer = vote;
    00695
    00696   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00697   if (dx > dy){
    00698     e = dx - 2*dy;
    00699     f = 2*(dx - dy);
    00700     g = -2*dy;
    00701     //setPixel(0,0)
    00702
    00703     for (x+=cx;x<x1;x+=cx) {
    00704       if (e<0) {
    00705         y+=cy;
    00706         e+=f;
    00707       }
    00708       else {
    00709         e+=g;
    00710       }
    00711       //setPixel(x,y)
    00712       //DOT(imageProcessor_general,x,y,
    00713       //  Drawings::white, Drawings::red);
    00714       vote = fastCrossEdgeVote(x,y);
    00715
    00716       if (vote > threshold || buffer != 0){
    00717         if (buffer < vote) buffer = vote;
    00718         else{
    00719           x = tempX;
    00720           y = tempY;
    00721           return true; //edge found (found local maximum)
    00722         }
    00723       }
    00724
    00725       tempX = x;
    00726       tempY = y;
    00727     }
    00728   }
    00729   else{
    00730     e = dy - 2*dx;
    00731     f = 2*(dy - dx);
    00732     g = -2*dx;
    00733     //setPixel(0,0)
    00734
    00735
    00736     for (y+=cy;y<y1;y+=cy) {
    00737       if (e<0) {
    00738         x+=cx;
    00739         e+=f;
    00740       }
    00741       else {
    00742         e+=g;
    00743       }
    00744       //setPixel(x,y)
    00745       //DOT(imageProcessor_general,x,y,
    00746       //  Drawings::white, Drawings::red);
    00747       vote = fastCrossEdgeVote(x,y);
    00748
    00749       if (vote > threshold || buffer != 0){
    00750         if (buffer < vote) buffer = vote;
    00751         else{
    00752           x = tempX;
    00753           y = tempY;
    00754           return true; //edge found (found local maximum)
    00755         }
    00756       }
    00757
    00758       tempX = x;
    00759       tempY = y;
    00760     }
    00761   }
    00762
    00763   if (buffer != 0){
    00764         x = tempX;
    00765         y = tempY;
    00766         return true; //edge found (found edge on border)
    00767   }
    00768
    00769   return false; //no edge found
    00770 }
    00771
    00772 bool GT2004EdgeDetection::colorScan(int& x,int& y,int x1,int y1,colorClass& lastColor){
    00773   cx = 1;
    00774   cy = 1;
    00775
    00776   colorClass start = getColor(x,y);
    00777   colorClass current = start;
    00778
    00779   dx = x1 - x;
    00780   dy = y1 - y;
    00781
    00782   if (dx < 0) cx = -1;
    00783   if (dy < 0) cy = -1;
    00784
    00785   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00786   if (dx > dy){
    00787     e = dx - 2*dy;
    00788     f = 2*(dx - dy);
    00789     g = -2*dy;
    00790     //TODO(schmidtb): remove inefficient code
    00791     int count = 0; //not to write more code and hold the order
    00792     //setPixel(0,0)
    00793
    00794     for (x+=cx ; current == start && count < dx ; x+=cx,count++) {
    00795       if (e<0) {
    00796         y+=cy;
    00797         e+=f;
    00798       }
    00799       else {
    00800         e+=g;
    00801       }
    00802       //setPixel(x,y)
    00803       //DOT(imageProcessor_general,x,y,
    00804       //  Drawings::white, Drawings::red);
    00805       current = getColor(x,y);
    00806     }
    00807   }
    00808   else{
    00809     e = dy - 2*dx;
    00810     f = 2*(dy - dx);
    00811     g = -2*dx;
    00812     int count = 0;
    00813     //setPixel(0,0)
    00814
    00815
    00816     for (y+=cy; current==start && count<dy; y+=cy,count++) {
    00817       if (e<0) {
    00818         x+=cx;
    00819         e+=f;
    00820       }
    00821       else {
    00822         e+=g;
    00823       }
    00824       //setPixel(x,y)
    00825       //DOT(imageProcessor_general,x,y,
    00826       //  Drawings::white, Drawings::red);
    00827       current = getColor(x,y);
    00828     }
    00829   }
    00830
    00831   if (current == -1){
    00832     lastColor = noColor;
    00833     return false;
    00834   }
    00835   else {
    00836     lastColor = start;
    00837     return true;
    00838   }
    00839 }
    00840
    00841 bool GT2004EdgeDetection::colorScan(int& x,int& y,Vector2<double> direction,colorClass& lastColor){
    00842   cx = 1;
    00843   cy = 1;
    00844
    00845   colorClass start = getColor(x,y);
    00846   colorClass current = start;
    00847
    00848   if (direction.x < 0) cx = -1;
    00849   if (direction.y < 0) cy = -1;
    00850
    00851
    00852   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00853
    00854   dx = abs((int)(direction.x * 500));
    00855   dy = abs((int)(direction.y * 500));
    00856
    00857   if (dx > dy){
    00858     e = dx - 2*dy;
    00859     f = 2*(dx - dy);
    00860     g = -2*dy;
    00861     //setPixel(0,0)
    00862
    00863     for (x+=cx;current == start && current != -1;x+=cx) {
    00864       if (e<0) {
    00865         y+=cy;
    00866         e+=f;
    00867       }
    00868       else {
    00869         e+=g;
    00870       }
    00871       //setPixel(x,y)
    00872       //DOT(imageProcessor_general,x,y,
    00873       //  Drawings::white, Drawings::red);
    00874       current = getColor(x,y);
    00875     }
    00876   }
    00877   else{
    00878     e = dy - 2*dx;
    00879     f = 2*(dy - dx);
    00880     g = -2*dx;
    00881     //setPixel(0,0)
    00882
    00883
    00884     for (y+=cy;current == start && current != -1;y+=cy) {
    00885       if (e<0) {
    00886         x+=cx;
    00887         e+=f;
    00888       }
    00889       else {
    00890         e+=g;
    00891       }
    00892       //setPixel(x,y)
    00893       //DOT(imageProcessor_general,x,y,
    00894       //  Drawings::white, Drawings::red);
    00895       current = getColor(x,y);
    00896     }
    00897   }
    00898
    00899   if (current == -1){
    00900     lastColor = noColor;
    00901     return false;
    00902   }
    00903   else {
    00904     lastColor = start;
    00905     return true;
    00906   }
    00907 }
    00908
    00909 bool GT2004EdgeDetection::colorScan(int& x,int& y,colorClass& lastColor){
    00910
    00911   colorClass start = getColor(x,y);
    00912   colorClass current = start;
    00913
    00914   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00915   if (dx > dy){
    00916     for (x+=cx;current == start && current != -1;x+=cx) {
    00917       if (e<0) {
    00918         y+=cy;
    00919         e+=f;
    00920       }
    00921       else {
    00922         e+=g;
    00923       }
    00924       //setPixel(x,y)
    00925       //DOT(imageProcessor_general,x,y,
    00926       //  Drawings::white, Drawings::red);
    00927       current = getColor(x,y);
    00928     }
    00929   }
    00930   else{
    00931     for (y+=cy;current == start && current != -1;y+=cy) {
    00932       if (e<0) {
    00933         x+=cx;
    00934         e+=f;
    00935       }
    00936       else {
    00937         e+=g;
    00938       }
    00939       //setPixel(x,y)
    00940       //DOT(imageProcessor_general,x,y,
    00941       //  Drawings::white, Drawings::red);
    00942       current = getColor(x,y);
    00943     }
    00944   }
    00945
    00946   if (current == -1){
    00947     lastColor = noColor;
    00948     return false;
    00949   }
    00950   else {
    00951     lastColor = start;
    00952     return true;
    00953   }
    00954 }
    00955
    00956 bool GT2004EdgeDetection::susanScan(int& x,int& y,Vector2<double> direction){
    00957   cx = 1;
    00958   cy = 1;
    00959
    00960   if (direction.x < 0) cx = -1;
    00961   if (direction.y < 0) cy = -1;
    00962
    00963   tempX = x;
    00964   tempY = y;
    00965
    00966   int vote = susanVote(x,y);
    00967   int buffer = 0;
    00968   if (vote > 0) buffer = vote;
    00969
    00970   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    00971
    00972   dx = abs((int)(direction.x * 500));
    00973   dy = abs((int)(direction.y * 500));
    00974
    00975   if (dx > dy){
    00976     e = dx - 2*dy;
    00977     f = 2*(dx - dy);
    00978     g = -2*dy;
    00979     //setPixel(0,0)
    00980
    00981     for (x+=cx;vote != -1;x+=cx) {
    00982       if (e<0) {
    00983         y+=cy;
    00984         e+=f;
    00985       }
    00986       else {
    00987         e+=g;
    00988       }
    00989       //setPixel(x,y)
    00990       //DOT(imageProcessor_general,x,y,
    00991       //  Drawings::white, Drawings::red);
    00992       vote = susanVote(x,y);
    00993
    00994       if (vote > 0 || buffer != 0){
    00995         if (buffer < vote) buffer = vote;
    00996         else{
    00997           x = tempX;
    00998           y = tempY;
    00999           return true; //edge found (found local maximum)
    01000         }
    01001       }
    01002
    01003       tempX = x;
    01004       tempY = y;
    01005     }
    01006   }
    01007   else{
    01008     e = dy - 2*dx;
    01009     f = 2*(dy - dx);
    01010     g = -2*dx;
    01011     //setPixel(0,0)
    01012
    01013
    01014     for (y+=cy;vote != -1;y+=cy) {
    01015       if (e<0) {
    01016         x+=cx;
    01017         e+=f;
    01018       }
    01019       else {
    01020         e+=g;
    01021       }
    01022       //setPixel(x,y)
    01023       //DOT(imageProcessor_general,x,y,
    01024       //  Drawings::white, Drawings::red);
    01025       vote = susanVote(x,y);
    01026
    01027       if (vote > 0 || buffer != 0){
    01028         if (buffer < vote) buffer = vote;
    01029         else{
    01030           x = tempX;
    01031           y = tempY;
    01032           return true; //edge found (found local maximum)
    01033         }
    01034       }
    01035
    01036       tempX = x;
    01037       tempY = y;
    01038     }
    01039   }
    01040
    01041   if (buffer != 0){
    01042         x = tempX;
    01043         y = tempY;
    01044         return true; //edge found (found edge on border)
    01045   }
    01046
    01047   return false; //no edge found
    01048 }
    01049
    01050 bool GT2004EdgeDetection::scan(int& x,int& y){
    01051
    01052   tempX = x;
    01053   tempY = y;
    01054
    01055   int vote = crossEdgeVote(x,y);
    01056   int buffer = 0;
    01057   if (vote > threshold) buffer = vote;
    01058
    01059   //doing variation of Bresenham's algorithm for line-drawing, to scan in direction
    01060   if (dx > dy){
    01061     for (x+=cx;vote != -1;x+=cx) {
    01062       if (e<0) {
    01063         y+=cy;
    01064         e+=f;
    01065       }
    01066       else {
    01067         e+=g;
    01068       }
    01069       //setPixel(x,y)
    01070       //DOT(imageProcessor_general,x,y,
    01071       //  Drawings::white, Drawings::red);
    01072       vote = crossEdgeVote(x,y);
    01073
    01074       if (vote > threshold || buffer != 0){
    01075         if (buffer < vote) buffer = vote;
    01076         else{
    01077           x = tempX;
    01078           y = tempY;
    01079           return true; //edge found (found local maximum)
    01080         }
    01081       }
    01082
    01083       tempX = x;
    01084       tempY = y;
    01085     }
    01086   }
    01087   else{
    01088     for (y+=cy;vote != -1;y+=cy) {
    01089       if (e<0) {
    01090         x+=cx;
    01091         e+=f;
    01092       }
    01093       else {
    01094         e+=g;
    01095       }
    01096       //setPixel(x,y)
    01097       //DOT(imageProcessor_general,x,y,
    01098       //  Drawings::white, Drawings::red);
    01099       vote = crossEdgeVote(x,y);
    01100
    01101       if (vote > threshold || buffer != 0){
    01102         if (buffer < vote) buffer = vote;
    01103         else{
    01104           x = tempX;
    01105           y = tempY;
    01106           return true; //edge found (found local maximum)
    01107         }
    01108       }
    01109
    01110       tempX = x;
    01111       tempY = y;
    01112     }
    01113   }
    01114
    01115   if (buffer != 0){
    01116         x = tempX;
    01117         y = tempY;
    01118         return true; //edge found (found edge on border)
    01119   }
    01120
    01121   return false; //no edge found
    01122 }