find a number for every single corner of rectangle

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
Lily el 27 de Feb. de 2013
sorry,but i don't know what do you mean. i just wanna know how to find/compute the angle (270/180/90) for every corner of rectangle, then i can get the number. I would be very pleased if you could give advice and guide me to implement the code or post some sort of sample code.thank you
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
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?

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
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
Lily el 27 de Feb. de 2013
thank you for the answer,but i mean that,how to compute the angle.how to find the angle to be 270,180 or 90 so i can find the number. the example above is just a description to explain what i mean. thank you
Image Analyst
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?
Lily
Lily el 27 de Feb. de 2013
sorry,i don't mean like that. i've deleted the answer bellow,thanks. so, i want to do something like this picture. http://i1327.photobucket.com/albums/u667/narutonartz/pict2_zps31a15db2.jpg
as seen in the rounded picture, each degree of corner marked by a number. 270 degrees is marked with the number 3, 180 = 2 and 90 = 1. the output is something like "so,the number is 1123311312123121". please guide me to implement the code or post some sort of sample code.thank you
Jan
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
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.
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
Lily el 27 de Feb. de 2013
sorry for giving the paper,but it's really hard to explain clearly. there are 2 pseudo code. the 1st is to find the rectangular,and then the 2nd is to find the code. i don't know how to detect "the code" with that "if position in corner A/B/C/D" in the second pseudo code. please help me..thank you
Image Analyst
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?
Lily
Lily el 28 de Feb. de 2013
Editada: Lily el 28 de Feb. de 2013
This paper is clear enough for me to explain the description about the process of chain code, so i need the algorithm to get the chain code as the feature extraction of OCR. Please guide me to implement it into a code to get the chain code. i didn't find another resource anymore about this chain code..
It looks to me like it would be more work than Image Analyst would typically be willing to devote.
Lily
Lily el 1 de Mzo. de 2013
somebody please help me implement it to code, i really don't know how to solve this chain code..i've searched everywhere, but there is only this paper that explain about this chain code
It is more research than I have the resources to do at this time.
@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
Lily el 1 de Mzo. de 2013
Sorry,but i just wanna ask about the way to find the "if position in corner A/B/C/D" from the paper. i don't want you to code all these things. i've already written some code for the rectangular code. also,as i said before that the chain code would be used as feature extraction of OCR. thank you.
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?

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 27 de Feb. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by