Bag of Visual Words
A bag of visual words represents an image by how often each of typical local patterns occurs in it, ignoring where they occur. The patterns are learned by clustering, which chooses the histogram bins from the data.
Building the representation takes four steps. First, extract local feature vectors from many training images, for example image patches, filter-bank responses at a pixel, or SIFT descriptors. Second, cluster them, usually with k-means, into centers . The centers are the codewords (visual words, or textons when the features are filter responses), and together they form the dictionary (codebook). Third, vector quantization replaces each feature of an image by the index of its nearest codeword,
where is the Euclidean norm (3.5a Vector Norm). Fourth, an image with features becomes the histogram of codeword frequencies
where counts the features assigned to codeword .Two histograms and are compared with a histogram distance. A common choice is the distance , summed over bins with (some texts drop the factor ). A new image takes the label of its nearest labeled histogram, or a classifier is trained on the histograms. The name comes from text analysis, where a document is summarized by its word counts regardless of word order. Adaptive binning places bins where the data is dense, which leaves fewer empty bins and spends resolution where features matter. Clustering is “super-adaptive” binning that needs no discretization along any fixed axis. Texton histograms are used to recognize textures and scene categories such as beach, forest and bedroom (Renninger & Malik).
Two Meanings of "Texton"
Julesz’s textons are perceptual features of line drawings, such as line ends and line crossings (9.1. Texture). In computer vision, a texton is a cluster center of filter-bank response vectors. The second meaning is a computational stand-in for the first. A definition question usually wants one of them specifically.
Intuition
Fixed histogram bins waste space. In a two-dimensional feature space, most cells of a regular grid stay empty while a few cells hold most of the data. The waste grows quickly with more dimensions. Clustering puts one bin at each dense group of features and lets each bin take the shape of its group. Each cluster center is a typical local pattern, such as a vertical bar of one width or a smooth patch. Counting how often each pattern occurs gives a short, well-filled histogram. The figure shows a codebook with three codewords, the cells they define, and the histogram of one image.
\usepackage{tikz}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{grn}{HTML}{2E9E5B}
\begin{tikzpicture}[x=0.9cm,y=0.9cm,>=latex]
\draw[->] (0,0) -- (5.3,0) node[below] {\small feature 1};
\draw[->] (0,0) -- (0,4.9) node[left] {\small feature 2};
% Voronoi boundaries
\draw[gray,dashed] (2.406,1.961) -- (2.633,0);
\draw[gray,dashed] (2.406,1.961) -- (0,3.02);
\draw[gray,dashed] (2.406,1.961) -- (5,3.73);
% features
\foreach \p in {(0.7,0.6),(1.0,1.4),(1.5,0.7),(1.6,1.3),(0.9,0.9),(1.3,0.4)} \fill[hot] \p circle (0.06);
\foreach \p in {(3.5,0.8),(4.2,1.0),(3.9,1.8),(4.4,1.5),(3.4,1.4)} \fill[cold] \p circle (0.06);
\foreach \p in {(2.0,3.2),(2.6,3.9),(2.2,4.1),(2.8,3.3),(1.8,3.7)} \fill[grn] \p circle (0.06);
% codewords
\draw[hot,very thick] (1.2,1.0) +(-0.13,-0.13) -- +(0.13,0.13) +(-0.13,0.13) -- +(0.13,-0.13);
\draw[cold,very thick] (3.8,1.3) +(-0.13,-0.13) -- +(0.13,0.13) +(-0.13,0.13) -- +(0.13,-0.13);
\draw[grn,very thick] (2.3,3.5) +(-0.13,-0.13) -- +(0.13,0.13) +(-0.13,0.13) -- +(0.13,-0.13);
\node[hot] at (0.35,1.25) {$\mathbf{c}_1$};
\node[cold] at (4.45,0.5) {$\mathbf{c}_2$};
\node[grn] at (1.35,3.2) {$\mathbf{c}_3$};
% query feature
\fill (2.9,2.2) circle (0.08);
\node[above] at (2.9,2.25) {$\mathbf{x}$};
\draw[->,thick,cold] (2.9,2.2) -- (3.72,1.38);
\node[cold,right] at (3.35,2.0) {\small $q(\mathbf{x}) = 2$};
% histogram
\begin{scope}[xshift=5.8cm]
\draw[->] (0,0) -- (3.4,0);
\draw[->] (0,0) -- (0,3.2) node[above] {\small $h_k$};
\fill[hot] (0.3,0) rectangle (0.9,1.2);
\fill[cold] (1.3,0) rectangle (1.9,2.6);
\fill[grn] (2.3,0) rectangle (2.9,0.8);
\node[below] at (0.6,0) {$1$};
\node[below] at (1.6,0) {$2$};
\node[below] at (2.6,0) {$3$};
\node at (1.6,-0.9) {\small codeword $k$};
\end{scope}
\end{tikzpicture}
\end{document}The document analogy explains both what the method keeps and what it loses. An article about the economy uses words like “trade” and “exports” often. An article about vision uses words like “retinal” and “cortex”. Word counts identify the topic without any word order. A bag of visual words does the same for images. It identifies a forest or a bedroom from the mix of local patterns and cannot tell where in the image each pattern appeared. A histogram of texton counts is a first-order texton statistic, which is the kind of statistic Julesz argued early vision uses.
Properties
(Shared Dictionary) The dictionary is learned once from a large pool of training features and then used for every image.
Quantizing all images with the same codebook puts their histograms in the same -dimensional space, so they can be compared bin by bin. A dictionary learned separately for each image would give each image its own bins, and its histogram could not be compared with any other. A dictionary learned from many images is sometimes called a set of universal textons. Running k-means on a large pool of features is the costly step. Quantizing a new image with features by brute force costs distance computations.
(Clustering as Adaptive Binning) Nearest-codeword quantization cuts feature space into convex cells, one around each codeword, with no fixed axes.
The points closer to than to any other center are bounded by the perpendicular bisectors between and its neighbors. Each cell is an intersection of half-spaces and is therefore convex (2.1 Convex Sets). The cells form the Voronoi diagram of the codewords, the dual of the Delaunay triangulation. In one dimension the cells are intervals whose edges sit at the midpoints between neighboring codewords (Easy example). Dense regions of feature space get many small cells, and sparse regions get a few large ones.
(Choosing ) Too few codewords merge different patterns into one bin, and too many split one pattern across several bins.
With small , a bar and an edge may share a codeword, and the histogram cannot separate textures that differ in that respect. With large , near-identical patches from two images can fall into different codewords by chance, and a bin-by-bin distance counts them as a mismatch. Large also leaves many bins nearly empty unless the image has many features. In practice is chosen by accuracy on held-out validation images.
(What the Bag Discards) The histogram keeps which patterns occur and how often, and it discards their positions.
A portrait cut into patches of eyes, nose and lips gives the same histogram whether the patches are in place or shaken up in a bag. For textures and scenes, positions matter little, so the loss is small. For objects with a fixed arrangement of parts, positions matter more. Per-region histograms (9.3. Texture Histograms) bring back coarse layout.
(Reading Values) The distance divides each squared difference by the total count in that bin, so a difference in a rare bin counts more than the same difference in a common bin.
A difference of counts gives in a bin where the two histograms hold counts together, and only in a bin that holds . In one texton-matching example, a new bedroom photo’s nearest labeled image was a bedroom at , while a beach image scored . Values of that size come from raw counts. If both images have the same number of features , dividing counts by divides by and leaves the ranking unchanged.
(Scene Recognition at a Glance) On 10 scene categories, a texton-histogram model scored in the same range as people who saw each photo for 37–50 ms.
Renninger and Malik compared a texture model built on texton histograms with human observers. The task had 10 basic scene categories (beach, mountain, forest, city, street, farm, kitchen, living room, bedroom and bathroom), so chance is . The model’s accuracy ranged from about (street) to about (living room). People who saw each image for 37 or 50 ms scored in a similar range, and people who saw it for 69 ms did better on every category. Very fast scene recognition can therefore rest on texture-like statistics, which fits the preattentive account in 9.1. Texture. Later systems replaced hand-designed dictionaries with features learned by convolutional networks.
Examples
(Easy) A Three-Word Codebook in One Dimension
Each patch is summarized by one number, its edge strength , such as a rescaled mean absolute filter response. Patches from beach and forest training photos give nine values: . Run k-means with , starting from the centers , and .
Run k-means to convergence. Where are the bin edges of the resulting quantizer?
Each iteration assigns every value to its nearest center and then moves each center to the mean of its values. In one dimension, the nearest center changes at the midpoint between two neighboring centers.
With centers , the midpoints are and . The clusters are , and , with means , and .
With centers , the midpoints are and . The clusters become , and , with means , and .
With centers , the midpoints are and , and no value changes cluster, so k-means has converged. The codebook is (smooth patches such as sky and water), (moderate texture) and (busy texture such as foliage). The quantizer’s bins are , and . Their widths , and follow the data, unlike three equal bins of width .
(Medium) Classifying a Photo by Its Word Histogram
Use the codebook , , from the Easy example. Two labeled training photos with patches each were quantized with it. The beach photo has counts and the forest photo has counts . A new photo has patches with edge strengths .
Quantize the new photo, build its histogram, and label it by the nearest training histogram under the distance. Quantization compares each value with the bin edges and . The values , and go to . The value lies near an edge, at distance from and from . The values and go to . The values , , , and go to , and is from and from . The histogram of counts is .
The distance to the beach histogram is
The distance to the forest histogram is
The new photo is closer to the forest photo and gets the label “forest”. The first two bins contribute the same amounts ( and inside the parentheses) to both distances, so the third bin, the count of busy patches, decides. Dividing all counts by divides both distances by and leaves the decision unchanged. Shuffling the patches of the new photo would change neither nor the label.
See Also
- 9.3. Texture Histograms, for fixed-bin histograms of filter responses.
- 9.2. Filter Banks, the usual source of texton features.
- 6.1. K-Means, the clustering algorithm behind the dictionary.
- 9.1. Texture, for Julesz’s textons and preattentive vision.