In this paper, a method is proposed to automatically select reference image in histogram matching. Histogram matching is one of the simplest spatial image enhancement methods which improves contrast of the initial image based on histogram of the reference image. In the conventional histogram matching methods, user should perform several experiments on various images to find a suitable reference image. This paper presents a new method to automatically select the reference image. In this method, images are converted from RGB to HSV, and the illumination (V) components are considered to select the reference image. The appropriate reference image is selected using a similarity measure via measuring the similarity between the histograms of the initial image and histograms of the images in the data base. Indeed, an image with similar histogram to the histogram of the original images is more appropriate to choose as the reference image for histogram matching. Results in this research indicate superiority of the proposed approach, compared to other existing approaches, in image enhancement via histogram matching. In addition, the user would have no concern in selecting an appropriate reference image for histogram matching in the proposed approach. This approach is applicable to both RGB and gray scale images.