I have a segmented region in an image, it is not rectilinear. Just a random shape without right angles , much like a circule.
I want to calculate the mean on that shape. so I can plot the mean as a starting poiny for drawing a vector.

I have read the ITK software guide for this, but there were alot of ways to find the mean but I didnt find one appropriate for my problem. Am i right?
should I use iterators?

thanks .


Well first you need to be clear what you mean by "mean". The mean is like the average value of a number of values. In the easiest case that would be a simple vector of double values. One type of mean is the sum of all of those values divided by the number of values. This is what you would normally use. Also you could multiply all values and take the n'th square-root. There are other ways but those are the most common ones (arithmetic mean and geometric mean) . If you have a region with grey-values then you could for example add them all up (integral over the region) and divide by the total number of values. If you have RGB-pixels you can do the same componentwise.
But probably that's not even what you want but calucalte a mean for each pixes using its surrounding pixels (like when you want to smoothen your picture). You can calculate the mean on the subregion surrounding each pixel in the same way.
I hope that answers the question or points you in the right direction.


Thanks for your reply.

I think the first choice you pointed is what I need.
becuase using the neighborhood to calculate surroundiing pixels will not help me.

I will make my problem more clear

I did segment this part and then threshold it, so the segmented part is all white. and black background.
I want to calculate the mean for the segmented part.
because this part does not have a specific shape, I cant find the centre,
so I just want to calculate the mean to give me something nearly in the middle to start drawing my vectors.

So, I add all pixels inside that region and devide my number of values??
which mwthod should I use in itk? MeanCalculator?
should I use an iterator that goes through all pixels and add them togather? which iterator because itk::NeighborhoodIterator is not what i need right?

Thank you.


So you actually want to calculate the centre of gravity of your area. So what you need to do is add the (2D-)vectors of of your black pixels and divide by the number of pixels. That will give you the centre of gravity of your black area.

I will try this , but actually I want to finid the centre of the white area which I segmented. and this can vary in position between different images.
I tried using the sentroid function in ITK , but still it always gives me
centroid(0,0) ! dont know why


I don't know your library unfortunately and also don't know whether it
has any function that can do what you want for you. The algorithm to calculate the coordinates of your centre of gravity of the white pixels if the following

for (x=0; x<maxX; x++)
    for(y=0; y<maxY; y++)
           accumulatedX += x;
           accumulatedY += y;
centerGravX = accumulatedX / numberWhite;
centerGravY = accumulatedY / numberWhite;

this is obviously pseudo code and I let you do the actual implementation in C++ ;-)