The complexity of pulmonary tuberculosis (TB) lung cavity lesion features significantly increase the cost of semantic segmentation and labelling. However, the high cost of semantic segmentation has limited the development of TB automatic recognition to some extent. To address this issue, we developed an algorithm that automatically generates a semantic segmentation mask of TB from the TB target detection boundary box. Pulmonologists only need to identify and label the location of TB, and the algorithm can automatically generate the semantic segmentation mask of TB lesions in the labelled area. The algorithm, first, calculates the optimal threshold for separating the lesion from the background region. Then, based on this threshold, the lesion tissue within the bounding box is extracted and forms a mask that can be used for semantic segmentation tasks. Finally, we use the generated TB semantic segmentation mask to train Unet and Vnet models to verify the effectiveness of the algorithm. The experimental results demonstrate that Unet and Vnet achieve mean Dice coefficients of 0.612 and 0.637, respectively, in identifying TB lesion tissue.