scient
scient一个用python实现科学计算相关算法的包,包括自然语言、图像、神经网络、优化算法、机器学习、图计算等模块。
scient源码和编译安装包可以在Python package index
获取。
The source code and binary installers for the latest released version are available at the [Python package index].
https://pypi.org/project/scient
可以用pip
安装scient
。
You can install scient
like this:
pip install scient
也可以用setup.py
安装。
Or in the scient
directory, execute:
python setup.py install
scient.image
图像相关算法模块,包括边缘检测、图像相似度计算、图像质量评价、图像特征提取等。
scient.image.hash
图像hash模块,包括均值hash(mean hash),差值hash(diff hash),感知hash(percept hash)。
scient.image.hash.percept(image,hash_size=64)
Parameters
image : numpy.array 2D
hash_size : 输出hash值的长度
Returns
list
Algorithms
先将图片缩放成hash_size * hash_size大小,然后对图像进行离散余弦变换DCT,并输出左上角h * w=hash_size的mean hash。
DCT是一种特殊的傅立叶变换,将图片从像素域变换为频率域,并且DCT矩阵从左上角到右下角代表越来越高频率的系数,图片的主要信息保留左上角的低频区域。
一维DCT变换:
F ( x ) = c ( x ) ∑ i = 0 N − 1 f ( i ) c o s ( ( i + 0.5 ) π N x ) c ( x ) = { 1 N , x = 0 2 N , x ! = 0 F(x)=c(x)\sum^{N-1}_{i=0}{f(i)cos(\frac {(i+0.5)π}{N}x) } \\ c(x)=\left\{\begin{matrix}\sqrt{\frac{1}{N}} ,x=0\\\sqrt{\frac{2}{N}} ,x!=0 \end{matrix}\right. F(x)=c(x)i=0∑N−1f(i)cos(N(i+0.5)πx)c