Image edge detection is an important part of image processing, and the effect of edge detection is also directly affected by image analysis, recognition and understanding. Canny operator is the most commonly used image edge detection operator. However, this operator has some limitations. The traditional Canny operator uses Gaussian filtering which may bring problems such as missing edge information and false edge. Besides, the selection of high and low thresholds of the traditional Canny operator are not accurate, and cannot be carried out by self-adaption. In order to solve these problems, this paper presents an optimized algorithm for Canny operator. In this paper, an improved anisotropic diffusion function is used to filter the image, and the improved filtering not only reduces the noise, but also maintains the edge information of the image. Additionally, this paper has improved the maximum between-class variance method (OTSU) to select the high and low thresholds of Canny operator by self-adaption. The improved algorithm is applied to edge detection of various images, and the results indicated that the improved Canny operator is effective in reducing noise and extracting edge.