Question: the output of some processing consists of a binary map with several connected areas. 

The objective is, for each area, to compute and draw on the image a line crossing the area on its longest axis, but not extending further. It is very important that the line lies just inside the area, therefore ellipse fitting is not very good.

Any hint on how to do achieve this result in an efficient way?

Answer: 
If you have the image processing toolbox you can use `regionprops` which will give you several standard measures of any binary connected region. This includes 

You can also get the tightest rectangular bounding box, centroid, perimeter, orientation. These will all help you in ellipse fitting.

Depending on how you would like to draw your lines, the `regionprops` function also returns the length for major and minor axes in 2-D connected regions and does it on a per-connected-region basis, giving you a vector of axis lengths. If you specify **4 neighbor connected** you are *fairly* sure that the length will be exclusively within the connected region. But this is not guaranteed since `regionprops' calculates major axis length of an ellipse that has the same normalized second central moment as the connected region.
My first inclination would be to treat the pixels as 2D points and use principal components analysis. [PCA](http://en.wikipedia.org/wiki/Principal_component_analysis) will give you the major axis of each region (`princomp` if you have the stat toolbox).

Regarding making line segments and not lines, not knowing anything about the shape of these regions, an efficient method doesn't occur to me. Assuming the region could have any arbitrary shape, you could just trace along each line until you reach the edge of the region. Then repeat in the other direction.

I assumed you already have the binary image divided into regions. If this isn't true you could use bwlabel (if the regions aren't touching) or k-means (if they are) first.