Ask Your Question

contourArea meaning and arclength

asked 2015-07-29 03:53:10 -0500

zms gravatar image

Hi, I'm playing with the moment coding and i'm confuse with the result. What I understand is the contourarea and the moment code will give the same result. 1) Contour area - is it means the area inside a close loop? Must it close contour? 2) what is the unit of the contour? I obtained result as 1, 7.5 and etc and confuse. 3) arclength is measuring the countour in pixel?

Anyone can help?

edit retag flag offensive close merge delete



Please comment what I have not answered to and I will improve my answer, so it can be marked as answer ;)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-29 09:08:00 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-07-29 04:40:04 -0500

thdrksdfthmn gravatar image

updated 2015-07-30 02:57:15 -0500

I suppose that you are playing with this, so

  1. contourArea is returning the area inside a contour (ofcourse, it should be closed, otherwise, it will consider it closed, so if it is a line it will consider the area inside the contour defined by the line if the first point and the last point are linked).
  2. As mentioned in the docs, the unit is pixel. If you want to get more deeper in the theory, then see Green's theorem; but for a better understanding, if the contour is a triangle, then ofcourse its area is very probably not an integer number.
  3. arcLength is measuring the length of a contour in pixels, ofcourse. Think that the contour is composed of points, so between each 2 points, there is a line, so that segment's length can be computed if the coordinates of the 2 points are known; and the coordinates are in pixels (with (0, 0) in top left corner of the image).

responding to your comment questions:

Q1. the function arcLength has a parameter closed that let you choose the case (read the docs...)

Q2. Well, that I cannot prove, because I have not the image you have. Hint: display the thresholded image to see the area. You can also draw the contour on another image to see exact what contour is it using.

Q3. About this, I am afraid I cannot tell you much, but you can search on google, too. ;)

edit flag offensive delete link more


@thdrksdfthmn, it is a details explaination!! :). Yes i'm playing with the code just for a bit and additional question.

Q1: if the contour is the line, so the length would be from the start to the end of the line? i.e. open loop? Q2: For moment or contourarea, let say if 7 means 7 pixels right ? I'm quite confuse because the area I look on the image should be more than 7 pixels after the thresholding as I'm using 268X206 image area.

Q3: In general, how moment can be used for the pattern recognition? I had listened few lectures in the youtube, but I could not find the relationship on how the moment can be used to do the pattern recognition process. Tried Hu's Moments and after rotate the image, it returns diff value. Should it be always the same? TQ

zms gravatar imagezms ( 2015-07-29 21:39:50 -0500 )edit

@thdrksdfthmn, I tried to check using and a very simple image ( inside the image there is a square black and white). The dimension of the image is 100X100 pixel. The square point coordinate in the image are (11,11),(84,11),(11,84),(84,84). With the size of the square should be at 73 square = 5329 pixels. But running the moment code return me moment & area size = 5843 which is different. I didn't do blur in the image. With this thread I could not send the image. Only if I do a new thread I can share the image. Do I still have the wrong coding?

zms gravatar imagezms ( 2015-08-03 06:14:52 -0500 )edit

Ok, supposing that this question is answered, you can create the thread you are talking about, adding: the code, the image and the question

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-03 07:08:41 -0500 )edit

@thdrksdfthmn When we have detected a broken contour which is not closed. What would the contourArea return? Does it find the shortest path between the first and the last point, then give the area under that closed contour?

Santhosh1 gravatar imageSanthosh1 ( 2017-11-10 23:01:59 -0500 )edit

Question Tools

1 follower


Asked: 2015-07-29 03:53:10 -0500

Seen: 6,855 times

Last updated: Jul 30 '15