We present a variational model to perform the segmentation of thin structures in MRI images (namely codimension 1 objects). It is based on the classical Mumford-Shah functional and we have added geometrical priors as constraints. We precisely describe the structure model (that we call tubes) and write the problem as a bilevel problem. We focus on the lower level optimization problem and give existence, uniqueness and regularity results for the solution. The keypoint is the fact that 2D/3D problems are equivalent to 1D ones. This gives hints to perform an automatic parameter tuning for numerical purpose.