The enhanced YOLO algorithm YOLOv5-Z is designed for precise target detection. This paper primarily focuses on optimizing the YOLOv5 target detection model by refining the detection frame generation strategy, ensuring the generated rectangular outline completely encompass the target area. The improved YOLO algorithm will deliberately enlarge the detected target area to detect the lesion area as accurately as possible while effectively avoiding the problem that the detection area does not contain complete lesions. Moreover, the enhanced UNet algorithm is applicable for image segmentation. While the study uses the COCO dataset for evaluating performance of YOLOv5-Z, the target detection area can be expanded to better serve subsequent possible image segmentation research, extending beyond medical images. Our experiments demonstrate that YOLOv5-Z algorithm expands the target detection range, promoting the development of artificial intelligence in the field of medical image detection.