Creating automated methods for detecting branches in images is crucial for applications like harvesting robots and forest monitoring. However, the tree images encountered in real-world scenarios present significant challenges for branch detection techniques due to issues such as background interference, occlusion, and varying environmental lighting. While there has been notable progress in extracting tree trunks for specific species, research on identifying lateral branches remains limited. The primary challenges include establishing a unified mathematical representation for multi-level branch structures, conducting quantitative analyses, and the absence of suitable datasets to facilitate the development of effective models. This study addresses these challenges by creating a dataset encompassing various tree species, developing annotation tools for multi-level branch structure labeling, designing branch vector representations and quantitative metrics. Building on this foundation, the study introduces an automatic extraction model for multi-level branch structures that utilizes ResNet and a self-attention mechanism, along with a tailored loss function for branch extraction tasks. The study evaluated several model variants through both qualitative and quantitative experiments. Results from different tree images demonstrate that the final model can accurately identify the trunk structure and effectively extract detailed lateral branch structures, offering a valuable tool for applications in this area.