find a number for every single corner of rectangle
Mostrar comentarios más antiguos
Hi,i'm new in matlab. i don't know how to find a number for every single corner of rectangle. it's 270 for number 3, 180 for number 2 and 90 for number 1. the input image is a thinned binary image. it looks like,
if (angle=270) then
number=3
elseif (angle=180) then
number=2
elseif (angle=90) then
number=1
end
number;
Please help me..thanks in advance
4 comentarios
Lily
el 27 de Feb. de 2013
Walter Roberson
el 27 de Feb. de 2013
Compute the angle given what information?
Are you sure the image will have exact right angles?
When you do the calculation of the angles, you are probably going to be working in radians. Converting radians to degrees is likely not to get you exactly 90 or exactly 180 or exactly 270, because radians involve Pi which is an infinitely long irrational number that cannot be exactly represented in finite binary floating point arithmetic. So you might, for example, end up with 270.0000000000122593 instead of 270 exactly. And if you try to use "==" to compare that to 270 you are not going to get a match. See the FAQ I cited above for more on why you should seldom compare floating point results for equality.
Jan
el 27 de Feb. de 2013
I still do not understand what "find a number for every single corner of rectangle" could mean. Corners of rectangles do not have angles like 270 or 180, but according to the definition all angles between the sides are 90 degrees (counter clockwise orientation). In addition I do not understand how you come from an "thinned binary image" (whatever this is) to angles.
So I ask you to explain again, which obejcts you are talking of. What are the inputs for the actual question?
Respuestas (1)
Image Analyst
el 27 de Feb. de 2013
Almost. Use double equals and get rid of the "then" and it should work:
if (angle == 270)
number = 3
elseif (angle == 180)
number = 2
elseif (angle == 90)
number = 1
else
number = 0
end
number;
15 comentarios
Lily
el 27 de Feb. de 2013
Image Analyst
el 27 de Feb. de 2013
Given the image you referred to in your answer, I'm not sure what you want. Yes, it's a binary image and yes it has corners. But what do you want as an output. Do you just want an array [0 1 2 3] or you want an array [0 90 180 270]? Well I can give that to you without even analyzing the image at all. Do you want to know the (row, column) coordinates of the upper left, upper right, lower left, and lower right pixel of the rectangle?
Have you seen my image segmentation tutorial? http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Lily
el 27 de Feb. de 2013
Jan
el 27 de Feb. de 2013
As usual I do not see anything at the linked page. I would have to allow 7 different domains to execute scripts on my computer to be able to see the picture. Because I do not want to trust them, I do not have any idea how "270 degrees" is related to the corners of a rectangle. And in addition I cannot imagine, how the 4(!) corners of a rectangle can lead to a result like "1123311312123121". Are you talking about a polygone?
Image Analyst
el 27 de Feb. de 2013
And if you have a bunch of corners scattered around the image, and you made an array such as "1123311312123121", don't you need to know what corner or pixel in the image corresponds to say, the 4th "1" in that array? Otherwise it's just a bunch of random numbers unless you know what they mean. I mean if you had a chessboard, you'd have 4*64 possible corners, but what are you going to do with that 256 element long array? Let's say that you knew that element #42 was a 3. So, then what? Do you just want to label the image with a text label saying "3"? If so, you had better know which pixels element #42 corresponds to so that you can put the text label at the correct location. I think you need to think out all steps of this and then take a look from our point of view about what information we're getting on the problem. Because I'm not getting enough information to give you a useful response.
Walter Roberson
el 27 de Feb. de 2013
It looks to me like it is intended to generate a list of travel directions numbered 1 to 4 -- "right and go one unit", "one unit straight", "left and go one unit". If that is the case, though, you do not need to analyze the image down to degree values.
Lily
el 27 de Feb. de 2013
Image Analyst
el 28 de Feb. de 2013
I see no use for this paper. MATLAB already provides bwboundaries() which will give you the boundaries of a binary object. Did you know that? If so, then why are you bothering trying to come up with a boundary following code like this? What's the purpose? I have never needed that to do anything in MATLAB. (By the way you can get that code by looking at what bwboundaries or bwperim returns.)
Let's take a step back and ask what is the larger picture here.
Let's say you had the chain code - what would you then do with it?
Walter Roberson
el 28 de Feb. de 2013
It looks to me like it would be more work than Image Analyst would typically be willing to devote.
Lily
el 1 de Mzo. de 2013
Walter Roberson
el 1 de Mzo. de 2013
It is more research than I have the resources to do at this time.
Jan
el 1 de Mzo. de 2013
@Lily: This does not seem to be an efficient method to ask in a public forum. Do you see the size of the discussion, which has been been needed to understand, what you are doing? But still readers of the original question cannot imagine, what you are actually wanting to achieve, because all important information are hidden in different comments.
You ask "help me to implement this code", but currently we cannot see any attempt from you. It does not motivate, that it currently looks, like you want us to write the code you need. And please note, that it discourages contributors to assist you, when you do not answer questions for clarifications. I'm stil waiting for the reply to IA's question:
Let's say you had the chain code - what would you then do with it?
Lily
el 1 de Mzo. de 2013
Image Analyst
el 1 de Mzo. de 2013
Well, what are you starting with? Did you run bwboundaries() and now you need to run around the coordinates and figure out which ones are the corners? Well then why not just see which is closest to the 4 corners of the image?
Categorías
Más información sobre Convert Image Type en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!