180 likes | 285 Views
Peak finding for Canny. Also called Non- maximaSuppression. Actual code for Peaks. for( i = MR;i <256-MR;i++){ for(j= MR;j <256-MR;j++){ if(( xconv [ i ][j]) == 0.0) { xconv [ i ][j] = .00001; } slope = yconv [ i ][j]/ xconv [ i ][j];
E N D
Peak finding for Canny Also called Non-maximaSuppression
Actual code for Peaks • for(i=MR;i<256-MR;i++){ • for(j=MR;j<256-MR;j++){ • if((xconv[i][j]) == 0.0) { • xconv[i][j] = .00001; • } • slope = yconv[i][j]/xconv[i][j]; • if( (slope <= .4142)&&(slope > -.4142)){ • if((mag[i][j] > mag[i][j-1])&&(mag[i][j] > mag[i][j+1])){ • cand[i][j] = 255; • } • } • else if( (slope <= 2.4142)&&(slope > .4142)){ • if((mag[i][j] > mag[i-1][j-1])&&(mag[i][j] > mag[i+1][j+1])){ • cand[i][j] = 255; • } • } • else if( (slope <= -.4142)&&(slope > -2.4142)){ • if((mag[i][j] > mag[i+1][j-1])&&(mag[i][j] > mag[i-1][j+1])){ • cand[i][j] = 255; • } • }else{ • if((mag[i][j] > mag[i-1][j])&&(mag[i][j] > mag[i+1][j])){ • cand[i][j] = 255; • } • } • } • }
Hysteresis (Double) Threshold • while(more){ • more = 0; • for(i=0;i<256;i++){ • for(j=0;j<256;j++){ • if(cand[i][j] == 255){ • if(mag[i][j] > HI){ • final[i][j] = 255; • more = 1; • cand[i][j] = 0; • } • else if(mag[i][j] < LO){ • final[i][j] = 0; • cand[i][j] = 0; • } • else if( (mag[i][j] > LO)&&(mag[i][j] < HI) ){ • for(p=-1;p<2;p++){ • for(q=-1;q<2;q++){ • if(final[i+p][j+q] == 255){ • final[i][j] = 255; • cand[i][j] = 0; • more = 1; • } • } • } • }/*end-last-else-if*/ • }/*end-first-if*/ • } • }/*end-first-for*/ • }/*end-while*/