In this paper a dictionary learning method for the Bag-ofFeatures (BoF) representation optimized towards spectral clustering is proposed. First, an objective function that measures the clustering ability of the histogram space, i.e., the space where the extracted histogram vectors lie after being encoded using the dictionary, is defined using the similarity graph of the spectral representation of the data. Then, the learned dictionary is optimized in order to minimize this objective and achieve better clustering solutions. That way, the histogram space is used as an intermediate space that helps to unwrap the manifold of the data. The ability of the proposed method to improve the spectral clustering is demonstrated using several clustering criteria and two image datasets, the 15-scene dataset and the Corel image dataset. The better clustering ability of the learned representation is also confirmed by evaluating the clustering solutions in the histogram space, as well as by using a different clustering algorithm. Although only image datasets were used in this work, the proposed method can be applied to any kind of objects that are represented using the BoF model, such as video, audio and time-series.