Asked by Maria
on 21 Jul 2013

If i've an image like : http://img836.imageshack.us/img836/6417/1zw.gif How can i identify the major two arcs in that image .

If the arcs can be modeled by y=(ax)^1/2 +b where a and b are constants such that a∈[250,400] and b∈[0,50] where b is an integer number as it represents the y-intercept of the arc in the image.

Output should be a 2-pixel thicker version of the detected arcs over the original image

May this will done by Hough Transform

Any Demo for doing that !please

Answer by Image Analyst
on 22 Jul 2013

Accepted answer

Just filter out the grid points - they seem to be at fixed positions so it will be very easy to find them but just summing vertically and horizontally and look for high sums

verticalProfile = sum(grayImage, 2); horizontalProfile = sum(grayImage, 1); gridLocations = verticalProfile > 50; % or whatever. grayImage(gridLocations, :) = 0; % Make those rows black.

etc. doing the same for the vertical grid lines.....

Then you have just the curves. Find each one and use polyfit() or whatever.

Maria
on 22 Jul 2013

i'm yrying this code , it's nearly give me 70% of correct result ., i'm do my best to get a correct result but i cant , can u make any simple modification to my code for get correct result , i think this condition play major role in my problem ((( arcs can be modeled by y=(ax)^1/2 +b where a and b are constants such that a∈[250,400] and b∈[0,50))) ,please image analyst :

I = imread('para.gif') ; [R,C] = meshgrid(30:30:300, 1:15:300) ; I(sub2ind(size(I), R(:), C(:))) = 0 ; [R,C] = meshgrid(1:7:300, [10 42 74 106 138 171 203 235 267 300]) ; I(sub2ind(size(I), R(:), C(:))) = 0 ; BW = edge(I,'canny');

[H,T,R] = hough(BW);

P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));

x = T(P(:,2));

y = R(P(:,1));lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);

figure,

imshow(I),

hold on

max_len = 0;

for k = 1:length(lines)

xy = [lines(k).point1; lines(k).point2];

plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');

plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');

plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');

end

end

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 18 Comments

## Maria (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_160827

i'm trying this code , but it didn't give acorrect answer

>> I = imread('para.gif');

BW = edge(I,'canny');

[H,T,R] = hough(BW);

P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));

x = T(P(:,2));

lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);

figure,

imshow(I),

hold on

max_len = 0;

for k = 1:length(lines)

end

## Image Analyst (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_160838

Your image does not display. Try it yourself. So I'll have no comment until I can see it.

## Maria (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_160856

you can see the image by this link :

http://s16.postimg.org/4v795t7yt/para.gif

## Cedric Wannaz (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_160934

Image Analyst gives a way to improve the performance of the hough transform. Following his idea and assuming that the grid is always at the same location, you can easily eliminate it and run your code on the new image. For example (I hardcode grid locations for sake of simplicity):

Then run the code that you submitted above and you'll see that there is already some improvement.

## Cedric Wannaz (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161019

Editing continuously your question for bumping up your thread is probably going to be less efficient than working on your code using information gathered from Image Analyst's answer and from my comment just above.

## Maria (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161023

it's not my way , but i updated the question status not more!

## Cedric Wannaz (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161045

So what changed in your question between all the times you edited it today and your last edit a few minutes ago?

## Maria (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161064

## Cedric Wannaz (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161067

So what is the difference between this version earlier today:

-----------------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------------

and this version a few minutes ago?

-----------------------------------------------------------------------------------------------------------------------------------

You and Mecheal have pretty much the same behavior as someone called "m" and his/her friend (if these were not the same person) a few months ago, who were asking for full code and making no effort.

## Maria (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161068

all of my activities aims to get further help , not more

i'm trying to focus at my points every time but there s no response about my point , u say without effort ! i sware that i'm working on that for 48 hours ago , but my capabilities doesn't help me enough , thats why every time i try to get a help from here and try to get highlited the whole of time, i need that to be done by those days or i'll lose alot ! im so tired man ! and i'm srry for doing that !

## Cedric Wannaz (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161069

Your question isn't more important than the others ones, so there is no justification for bumping your thread up every hour or so.

As I told you when you were using the nickname "m" (and if it was no you, this remark applies to you as well), you should invest your time in learning MATLAB instead of going on multiple forums asking for full code. By taking these complicated projects and asking people to solve them for you, you are trying to take/sell people's goodwill, time, and knowledge, which is not acceptable.

Back to your problem, it is really not trivial to "extract" automatically the four curves and answer your question. Even detecting the grid and removing it automatically is not trivial; if you look at the code that I gave you, grid parameters are hardcoded based on tests that I made by hand, and there is absolutely nothing automatic. Assuming that, by working hard on this, you are able to build a solution for removing the grid (based e.g. on FFT), you might have then to split the image into blocks that contain each a single curve, which is not trivial either, before you can finally fit something and/or perform some hough transform (for matching a parametric curve, which, again, is not trivial). Nobody will be teaching you all this material from A to Z, and you'll have to be particularly lucky to find someone who's willing to spend time developing this code for you (especially if you don't demonstrate that you are making a significant effort on your side for learning the material).

So my recommendation is that, instead of trying to bump up your thread continuously, you go over the Image Processing Toolbox manual, and you follow e.g. an online class like "UCF Computer Vision Video Lectures 2012" on youtube.

## Maria (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161070

i swear that i'm not the one that called "m" ! i don't have another account .

any way thanks for your advice .

## Cedric Wannaz (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161072

Last comment before leaving: if you want to reduce the complexity of the approach by allowing some manual operations, try the following:

then you enlarge the image so it is big enough on your screen. Once done, type the following in the command window:

press enter, and you'll see that the cursor on the figure was replaced by some lines which look like a targeting tool. Choose a curve and click at e.g. four or five different locations on this curve. Then press Enter. You see that you have the coordinates of your clicks stored in variable

coord. This is "curve matching and data extraction done by eye/hand". Now if this is acceptable for your project (as a temporary solution), the next question that you have to think about is how many points do you need to determine a set of parameters for a curve, or whether you'd prefer recording a significant amount of coordinates and look for a best fit.## Maria (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161179

all of ur recommendation absoulutely right , but i dont have a enough time for learining all of this by 2 days! i do my best but i cant get it , it must be done before thursday , i dont know what i've to do , Matlab isn't my major , but i need it to solve this problem . thank u for ur attention at general.

## Matt Kindig (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161182

If you just need to the equation of the curves, why not use the ginput() method outlined above? Why do you need a full Matlab image processing solution anyway? Why do you need a plot with thicker lines?

Also, what happens on Thursday?

## Cedric Wannaz (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161211

The approach with ginput() is one of the simplest possible, because it bypasses the quite complicated development of an algorithm for detecting/extracting curves from the image.

Have you tried what I told you above? Now take one set of coordinates and inject

xandyin the equation that you give in your question. What do you see? Doesn't it look like an equation with two unknowns,aandb? Now repeat the operation for another set of coordinates .. it seems that you have another equation with the same two unknowns, right? So you have two equations with two unknownsaandb, and a bunch of constrains on their values. This should be enough for your to get an approximate result already, without it to involve more than basic algebra.## Maria (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161235

the deadline for this probllem by thursday , thats why i need it before thursday ,,

Cedric Wannaz ur approach refused by my supervisor ! he need it to be done as i ask before with a full question specification , i'm not specialist in matlab to do all of this ! !

i'm trying to modify my code alot of times but i cant get the result ! i'm sleepless ! if u want to help me the last time , plzz do it for me ..

## Cedric Wannaz (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/82689#comment_161239

I already spent way too much time explaining why you should learn MATLAB before trying to undertake this kind of quite complex problems, giving extra information and a simpler alternative (simpler than the fully algorithmic approach). I also told you that you should ask a more specific question (than

"please solve my complicated problem for me and provide me with complete code that I can give to my supervisor"). I suggested"how to use hough transforms in MATLAB for extracting parametric curves (e.g. parabola)", which would already be quite complex in itself.. and unlikely to be fully answered on the forum. This would have been a chunk of the answer, which is way more complex as there is a grid (which might vary a bit between images), multiple curves, etc.As I said above, it is unlikely that anybody will spend time to explain all the material to you, or to provide you with full code. Either your supervisor knows you but doesn't know the material and is asking for way too much, or you are missing a significant amount of practice (math + programming + scientific computing + image processing + MATLAB basics) for working for this person. In either case, it is not up to us to work half a day for providing a full solution to him or to you.