Given your image im, you can binarize it with im2bw:
The horizontal histogram (I guess) is the sum of the object in the horizontal direction, which is
You can then plot it with:
Which gives you the image attached.
The segmentation could be performed with findpeaks.