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

Modules/ImageProcessor/ImageProcessorTools/MSH2004EdgeDetection.cpp

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

Generated on Mon Mar 20 21:59:50 2006 for GT2005 by doxygen 1.3.6