Click here to Skip to main content
Click here to Skip to main content

Detect knoll of arc

, 12 Jul 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Detect knoll of an arc.

Original image
Gray image
Processed image


Today image processing can be applied in a variety of fields such as medical, tumor detection, driving, speed analysis, traffic analysis, edge detection, background extraction, text extraction, ...

With this algorithm we can find the knoll and get amount of arc of a line in every picture easily. For example, from figure 1, we want to get to figure 3.

Using the code

At first we must load the image to the program. We do it with the CImage object.

CImage i;

After that we should grey the image to make the process more easy. Working with two colors, black and white. We put black color where average of RGB is less than 80 and put white where average of RGB is more than 80. To convert the image to gray-mode:

CDC cdc;
//delaration an object from Class Device Content

//get Device Content from CImage (i)

COLORREF c,c1;         //define two color
long r,g,b;    //define red ,green, blue values
int avg;
for(int y=0;y<i.GetHeight();y++)
    for(int x=0;x<i.GetWidth();x++){
       c=cdc.GetPixel(x,y);           //get color from image
                                      //get RGB
       r=GetRValue(c); g=GetGValue(c);  b=GetBValue(c); avg=(r+g+b)/3;
       else r=0;
       cdc.SetPixel(x,y,RGB(r,r,r));  //put color to image

Next step is arc detection. The algorithm is:

We look for the first pixel that is not in black (white) and call Point 1 (x1,y1). Then continue. Next pixel that has this trait, if its distance from previous point is less than d, then it belongs to an arc else not. Keep on doing this until we won't find a pixel that belongs to the arc, then we call the last point Point 2(x2,y2). Point 3(x3,y3) is the knoll of the arc. To detect this while we’re looking pixels, put Point 3 = current point and see if its y is more than previous y (has higher height). Finally we get Point 3(x3,y3) as the knoll of the arc.

CDC cdc;
CPen p(PS_SOLID,1,RGB(255,255,0)),p1(PS_SOLID,1,RGB(0,0,255)),p2(PS_DASH,1,RGB(255,0,0));
register int x1=-1,x2,x3,y1,y2,y3,d=10;x1=x2=x3=y1=y2=y3=-1;
register COLORREF c;
for(register int x=0;x<i.GetWidth();x++)
    for(register int y=0;y<i.GetHeight();y++){
       if(c!=RGB(255,255,255)){//line detect
           if(x1==-1){//first point of line
           }else if(sqrt(pow(x-x2,2.0)+pow(y-y2,2.0))<=d){//next point
register float length=sqrt(pow(x1-x2,2.0)+pow(y1-y2,2.0));
float arc=4000*abs(y3-y2)/length;
CString s;char a[20]="";itoa(arc,a,10);s=a;s+=_T(" mM");


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Comments and Discussions

General[My vote of 1] Nothing to see here... PinmemberMatt T Heffron13-Jul-12 13:50 
GeneralRe: [My vote of 1] Nothing to see here... PinmemberMahdi Nejadsahebi31-Jul-12 20:26 
GeneralRe: [My vote of 1] Nothing to see here... PinmemberMatt T Heffron1-Aug-12 7:58 
QuestionRe: [My vote of 1] Nothing to see here... PinmemberMahdi Nejadsahebi18-Oct-12 3:54 
AnswerRe: [My vote of 1] Nothing to see here... PinmemberMatt T Heffron18-Oct-12 12:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 12 Jul 2012
Article Copyright 2012 by Mahdi Nejadsahebi
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid