If I understood your problem correctly, a way to do what you want would be to use a thinning algorithm. You will find an implementation with OpenCV here.
The steps are :
Take the reverse of your image, to get this :
Then apply the thinning algorithm :
Matlab code to do this :
I = imread('image.jpg');
I = ~I;
It = bwmorph(I(:,:,1),'thin',Inf);