Bag-of-Words The original bag-of-words is also called "bag of words". In information retrieval, the bag-of-words model assumes that for a text, its word order and syntax are ignored, think of it as only a word set, or a combination of words. The appearance of each word in the text is independent and does not depend on whether other words appear.
Bow simple example for text
John likes to watch movies. Mary likes too.
John also likes to watch football games.
Based on the words in the above two sentences, we can build a dictionary
{"John": 1, "likes": 2, "to": 3, "watch": 4, "Movies": 5, "also": 6, "football": 7, "games": 8, "Mary": 9, "too": 10}
This dictionary contains 10 words and each word has a unique index. Based on this dictionary, we can express the preceding two sentences as the following two vectors:
[1, 2, 1, 1, 1, 0, 0, 0, 1, 1]
[1, 1, 1, 1, 0, 1, 1, 1, 0, 0]
These two vectors contain 10 elements, in which the I element represents the number of times that the I word in the dictionary appears in the sentence. Therefore, the Bow model can be considered as a statistical histogram. In text retrieval and processing applications, this model is used to conveniently calculate word frequency.
Bag-of-words for image processing Background Simple introduction to sift Scale-invariant feature transform (SIFT) is a descriptive descriptor used in image processing. This descriptive description has a scale immutability and can detect key points in the image. Is a local descriptive sub.
Advantages of Sift SIFT features not only have scale immutability, but can still get a good detection effect even if they change the rotation angle, image brightness, or shooting angle. Therefore, when applied to image recognition, the effects of image scale, angle, and brightness can be suppressed.
Image Feature Extraction An image can be analogous to a document. Words in an image can be defined as feature vectors of an image block. Then, the Bow model of the image is "the histogram obtained from the feature vectors of all image blocks ".
1. Feature Extraction If there are n images, the I image can be composed of N (I) image patches, that is, it can be expressed by N (I) feature vectors. Then sum (N (I) feature vectors (words) are obtained in total ).
Feature vectors can be obtained using the sift method. The dimension of each patch feature vector is 128.
2. Generate a dictionary/code book If the dictionary size is 100, there are 100 words. Use the K-means algorithm to cluster all patches. k = 100. When k-means converges, we obtain the final center of each cluster, the 100 centers (with 128 dimensions) are the 100 words in the dictionary, and the dictionary is constructed.
3. Generate a histogram Based on the code book For each image, we use the neighborhood calculation method to calculate each word in the image that belongs to the category of word in the cluster, so as to obtain the bow representation of the image corresponding to the code book.
After the bag-of-words model is built, you can perform classification, pre-attention, and other training.
Image Feature Extraction Method: Bag-of-Words