I’m pretty new to Matlab and have to do some work for a lab.
Basically I have to calculate the height of persons in an image. There are some markers next to the persons which I’ve already identified. So now I now converted the image to an binary image: 
I need the x and y positions of every person in the picture to compare it with the markers I already found.
I tried to iterate over the image and check the surroundings if I’ve already found a person near this coordinates but it does not work, nor it is very “matlab like”. (Performance is also bad because of the loops)
NOTE: I’m not allowed to use most of the “good or sophisticated” functions like imfilter… (I also had to write the conversion to the binary image for example)
I have no idea how I should tackle this problem (other than the method I described above).
I can post my code here but I guess that won’t help answer this question.
If you can use built-ins (or write your own) here’s what I have been thinking of as a partial solution.
First, invert the image so the people are in white and the background is black. Find the sum of all the rows.
This will give you some noisy data that shows the number of on pixels in each row. If you plot it, the peaks are the people, and the valleys are the areas between them. But there will be a lot of false peaks. To fix this, use convolution like:
A size of 50 seemed to work pretty well. It may differ from image to image, but if they are all more or less like the one above, 50 should work.
Now you should have a clean set of data showing the peaks where the people are (and specifically the highest points of the people). You can do a single for loop to find those peaks. But don’t start looking for the next peak until you’ve crossed a valley. If it helps you can use the derivative to find where the derivative passes zero (these are the peaks and valleys).
But I found that there aren’t always literal zero points on the derivative, so you’ll have too look for sign changes instead.
There are also public functions out there that you can download to automatically find the peaks.
So let’s say you have your peaks stored in some vector peaks. Now you know the x location of the person, so isolate the columns and find the first nonzero (the top of the people’s head, and y locations) then subtract that from the total column size to find the height. So for the first peak:
I think somthing along those lines might work for you. You still need to do some iterating, but not a whole lot.