Introduction: Diabetes is a disease, which is caused by the cessation of insulin production or the dysfunction of the body. Early detection of diabetic foot ulcers thermal images of the sole of the foot is one of the new methods of diagnosing diabetic foot ulcers. Material and Method: In this paper, by optimizing the nearest neighbor algorithm, early detection of diabetic foot ulcers is performed by comparing the thermal similarity of the left and right soles of the feet. And the condition of the possibility of foot ulcer is diagnosed. In the proposed solution, by removing additional areas and creating a temperature image of the soles of the feet, using image matching techniques and then extracting statistical features such as standard distribution, percentage of dissimilar pixels and average temperature of the soles of the feet, early diagnosis of the wound condition is attempted. Results: To evaluate the proposed method, 74 images of gray surfaces were used, in which the image of the left and right soles of the feet is specified in the image, and along with the images, there is a file in which the class of each image is specified. The information file also contains the minimum and maximum temperatures in the image to create a thermal image. Therefore, the above problem is a 3-class classification problem in which 75% of the images are used for training and 25% for testing. We have used thermal images by crossvalidation method, which we have achieved with a total accuracy of 85. 14%. Conclusion: Many researches have been done in recent years, most of which have been qualitatively examining the quality of thermal images. In this research, a method based on the use of optimization algorithm using MATLAB software and computer aided diagnostics has been performed. Based on the designed objective functions and the constraints considered in the diagnostic design, we were able to take a step, towards early diagnosis of the ulcer. As sometimes a diabetic patient as possible,Inflammation and change in tissue temperature and cannot diagnose this change in temperature, can be used the proposed methods to eliminate this lack of diagnosis In this study, it has been shown that among the images that the algorithm has been able to run on, the symptoms of inflammation and subcutaneous heat and rising tissue temperature have been obtained correctly and accurately to prevent and follow the early diagnosis of such ulcers.