Color moment principle and Python implementation

Source: Internet
Author: User
Tags square root

principle

The color moment (moments) is a very simple and effective color feature presented by Stricker and Orengo. The mathematical basis of this method is that any color distribution in the image can be represented by its moment. In addition, since the color distribution information is mainly concentrated in the low-order moment, only the first-order moment (mean), second moment (variance) and third-order moment (skewness) of the color can be used to express the color distribution of the image. Another benefit of this approach, compared to color histograms, is the need to vectorize features. Thus, the color moment of the image requires only 9 components (3 color components, 3 low-order moments on each component), which is very concise compared to other color features. In the practical application, in order to avoid the low second moment resolution ability, the color moment is often used in conjunction with other features, and generally before the use of other features, to reduce the scope of filtering (narrow down) role.

Note:

in the figure, N represents the total number of pixels in the picture, Pij indicates that the I-color channel is in the J-image pixel value, ei represents the mean of all the pixel on the I-color channel, and Ōi represents the standard deviation of all pixels on the first I color channel, Si represents the 3 square root of the slope (skewness) of all pixels on the first I color channel.

Python Implementation
ImportCv2ImportNumPy as NP#Compute Low Order moments (all-in-all)defcolor_moments (filename): img=cv2.imread (filename)ifImg isNone:return    #Convert BGR to HSV colorspaceHSV =Cv2.cvtcolor (IMG, Cv2. COLOR_BGR2HSV)#Split the Channels-h,s,vH, s, v =Cv2.split (HSV)#Initialize the color featureColor_feature = []    #N = h.shape[0] * H.shape[1]    #The first central moment-averageH_mean = Np.mean (h)#np.sum (h)/float (N)S_mean = Np.mean (s)#Np.sum (s)/float (N)V_mean = Np.mean (v)#np.sum (v)/float (N)Color_feature.extend ([H_mean, S_mean, V_mean])#The second central Moment-standard deviationH_STD = NP.STD (h)#np.sqrt (Np.mean (ABS (H-h.mean ()) **2 )S_STD = NP.STD (s)#np.sqrt (Np.mean (ABS (S-s.mean ()) **2 )V_STD = NP.STD (v)#np.sqrt (Np.mean (ABS (V-v.mean ()) **2 )Color_feature.extend ([H_std, S_STD, V_STD])#The third Central moment-the third root of the skewnessh_skewness = Np.mean (ABS (H-h.mean ()) **3) s_skewness= Np.mean (ABS (S-s.mean ()) **3) v_skewness= Np.mean (ABS (V-v.mean ()) **3) H_thirdmoment= h_skewness** (1./3) S_thirdmoment= s_skewness** (1./3) V_thirdmoment= v_skewness** (1./3) Color_feature.extend ([H_thirdmoment, S_thirdmoment, v_thirdmoment])returnColor_feature

References

1, color characteristics of the extraction (turn) http://blog.sina.com.cn/s/blog_66f17a900100w1iy.html

2. Color Moment http://www.xuebuyuan.com/2199860.html

3, M. Stricker and M. Orengo, similarity of Color Images, in Proc. SPIE Storage and retrieval for Image and Video Databases , 1995.

Color moment principle and Python implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.