This paper presents a novel method for optimizing rectangular boundaries in stitched images using a combination of deep learning and genetic algorithms. The proposed method utilizes an enhanced structure of convolutional neural network (CNN) in order to extract features for residual regression and a genetic algorithm to tune CNN parameters. The performance of the proposed method was evaluated using various metrics, including mean squared error, peak signal-to-noise ratio (PSNR), structural similarity index (SSIM), and Fréchet inception distance (FID). The outcomes from the conducted experiment demonstrated that the suggested method achieved high accuracy in rectangular boundary optimization, even for images with complex shapes and orientations. The method was also tested with different parameters, and results indicated that increasing the number of generations and population size led to improved performance. Also, the combination of deep learning algorithm specifically (CNN) and optimization algorithm specifically (genetic algorithm (GA)) led to an increase in the accuracy of the rectified images where the average PSNR reached 23.98, SSIM is 0.8066, and FID is 18.72. The proposed method has potential applications in various areas of study, such as image cropping, object detection, and image segmentation.