scient


Namescient JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
SummaryA python package about science compute algorithm, include natural language, image, neural network, optimize algorithm, machine learning, graphic algorithm, etc.
upload_time2024-06-28 04:05:42
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseLicence
keywords science compute image natural language machine learning neural network optimize algorithm graphic algorithm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](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.friqa

全参考图像质量评价模块,包括峰值信噪比(PSNR),结构相似度(SSIM),直方图相似度(HistSim)。

#### scient.image.friqa.psnr(image1,image2,max_pix=255)

Parameters
----------
image1 : numpy.array 2D or 3D,参考图像

image2 : numpy.array 2D or 3D,待评价图像

max_pix : int, optional default is 255, 像素值的最大值,默认值是255.

Returns
-------
float

Algorithms
-------
PSNR(Peak Signal to Noise Ratio),峰值信噪比,是一种评价图像的客观标准,单位dB。图像在经过压缩之后,会在某种程度与原始图像不同,PSNR值用来衡量经过处理后的图像品质是否令人满意。

$$
PSNR=10 \cdot \log _ {10} ( \frac { MAX _ I ^ 2 } { MSE }) = 20 \cdot \log _ {10} ( \frac { MAX _ I } { MSE })
$$

其中,$MAX _ I$是图像像素值的最大值,一般每个采样点用8位表示,那么$MAX _ I$就是255。

$MSE$是待评价图像与参考图像的均方误差,$MSE$越小,PSNR越大;PSNR越大,待评价图像质量越好。

* PSNR高于40dB说明待评价图像质量极好,非常接近原始图像;
* PSNR在30—40dB说明待评价图像质量是较好,虽然有明显失真但可以接受;
* PSNR在20—30dB说明待评价图像质量差;
* PSNR低于20dB说明待评价图像质量不可接受。


PSNR缺点:基于对应像素点间的误差,即基于误差敏感的图像质量评价。由于并未考虑到人眼的视觉特性(人眼对空间频率较低的对比差异敏感度较高,人眼对亮度对比差异的敏感度较色度高,人眼对一个 区域的感知结果会受到其周围邻近区域的影响等),因而经常出现评价结果与人的主观感觉不一致的情况。

Examples
-------

```
import os
from scient.image import friqa
import numpy
from PIL import Image

ref_image='test/data/I10.BMP'
images=['test/data/I10.BMP','test/data/i10_23_3.bmp','test/data/i10_23_4.bmp','test/data/i10_23_5.bmp','test/data/i10_24_5.bmp']

#读取图像文件
ref_image=Image.open(os.path.join(os.path.dirname(friqa.__file__),'..',ref_image))
images=[Image.open(os.path.join(os.path.dirname(friqa.__file__),'..',i)) for i in images]

#计算psnr
for i in images:
    print(friqa.psnr(numpy.array(ref_image),numpy.array(i)))
```

运行结果

```
100
32.436263852012544
31.184291262813648
30.272831107297733
29.3584810257951
```
    
    
#### scient.image.friqa.ssim(image1,image2,k1=0.01,k2=0.03,block_size=(8, 8),max_pix=255)

Parameters
----------
image1 : numpy.array 2D

image2 : numpy.array 2D

k1 : float, optional,k1<<1,避免分母为0造成不稳定. The default is 0.01.

k2 : float, optional,k2<<1,避免分母为0造成不稳定. The default is 0.03.

block_size : tuple, optional,将图像分成多个block,采用gaussian加权计算所有block的均值、方差、协方差,进而计算所有block的ssim,最后的ssim取所有block的平均值. The default is (8,8).

max_pix : int, optional default is 255, 像素值的最大值,默认值是255.

Returns
-------
float

Algorithms
-------

SSIM(Structural Similarity),结构相似度,用于衡量两个图像相似程度,或检测图像的失真程度。
SSIM基于样本之间的亮度(luminance,像素平均值)、对比度(contrast,像素标准差)和结构(structure,像素减均值除以标准差)计算。

$$
SSIM(x,y)=f(l(x,y),c(x,y),s(x,y))
$$

$l(x,y)$为亮度对比函数,是关于图像的平均灰度$μ_x,μ_y$的函数;

$$
l(x,y)=\frac { 2μ_x μ_y + C1 } { μ_x^2 μ_y^2 + C1 } \\
μ_x=\frac { 1 } { N } \sum^{N}_{i=1}{x_i} \\
C1=(K_1 L)^2
$$

像素值的最大值,默认值是255. K1<<1。

$c(x,y)$为对比度对比函数,是关于图像的标准差$σ_x,σ_y$的函数;

$$
c(x,y)=\frac { 2σ_x σ_y + C2 } { σ_x^2 σ_y^2 + C2 } \\
σ_x=(\frac { 1 } { N-1 } \sum^{N}_{i=1}{(x_i-μ_x)^2})^{\frac { 1 } { 2 }} \\
C2=(K_2 L)^2
$$

K2<<1

$s(x,y)$为结构对比函数,是关于图像的标准化$\frac { x-μ_x } { σ_x },\frac { y-μ_y } { σ_y }$的函数;

$$
s(x,y)=\frac { σ_{xy} + C3 } { σ_x σ_y + C3 } \\
σ_{xy}=\frac { 1 } { N-1 } (\sum^{N}_{i=1}{(x_i-μ_x)(y_i-μ_y)}) \\
$$

$$
SSIM(x,y)=[l(x,y)]^α[c(x,y)]^β[s(x,y)]^γ
$$

α,β,γ取1,令$C_3=\frac { C_2 } { 2 }$,可将SSIM简化为:

$$
SSIM(x,y)=\frac { (2μ_x μ_y + C1)(2σ_{xy} + C2) } { (μ_x^2 μ_y^2 + C1)(σ_x^2 σ_y^2 + C2) }
$$

SSIM取值范围为[0,1],值越大表示图像质量越好。
SSIM具有:对称性,ssim(x,y)==ssim(y,x);
         有界性,ssim(x,y)<=1;
         最大值唯一性,当且仅当x==y时,ssim(x,y)==1。
SSIM缺点:对于图像出现位移、缩放、旋转(皆属于非结构性的失真)的情况无法有效的判断。

Examples
-------

```
import os
from scient.image import friqa
import numpy
from PIL import Image

ref_image='test/data/I10.BMP'
images=['test/data/I10.BMP','test/data/i10_23_3.bmp','test/data/i10_23_4.bmp','test/data/i10_23_5.bmp','test/data/i10_24_5.bmp']

#读取图像文件
ref_image=Image.open(os.path.join(os.path.dirname(friqa.__file__),'..',ref_image))
images=[Image.open(os.path.join(os.path.dirname(friqa.__file__),'..',i)) for i in images]

#计算ssim
for i in images:
    print(friqa.ssim(numpy.array(ref_image.convert("L")),numpy.array(i.convert("L"))))
```

运行结果

```
1.0
0.8568124416229375
0.6810351495300123
0.5575398637742431
0.5072153083460104
```

### scient.image.feature

图像特征提取模块,包括BRISQUE,基于累积概率的锐化因子(CPB),曝光度。

#### scient.image.feature.brisque(image)

Parameters
----------
image : numpy.array 2D

Returns
-------
tuple
('gdd_α','gdd_σ',
'aggd_α1','aggd_η1','aggd_σl1','aggd_σr1',
'aggd_α2','aggd_η2','aggd_σl2','aggd_σr2',
'aggd_α3','aggd_η3','aggd_σl3','aggd_σr3',
'aggd_α4','aggd_η4','aggd_σl4','aggd_σr4')

Algorithms
-------
 BRISQUE(Blind/Referenceless Image Spatial QUality Evaluator),是一种无参考的空间域图像质量评估算法。先计算Mean Subtracted Contrast Normalized Coefficients(MSCN系数),MSCN系数反映了由于失真的存在而改变的特征统计,可以用来作为图像失真的统计特征。再用MSCN系数估计Generalized Gaussian Distribution(GDD)的参数α、σ,以及Asymmetric Generalized Gaussian Distribution(AGGD)在Horizontal Neighbour, Vertical Neighbour, On Diagonal Neighbour, Off Diagonal Neighbour上的参数α、η、σl、σr,将GDD的两个参数和AGGD的16个参数作为输出的特征。

MSCN系数:

$$
MSCN(i,j)=\frac { I(i,j)-μ(i,j) } { σ(i,j)+C } \\
μ(i,j)=\sum^{K}_{k=-K}{\sum^{L}_{l=-L}{w_{k,l}I_{k,l}(i,j)}} \\
σ(i,j)=\sqrt{\sum^{K}_{k=-K}{\sum^{L}_{l=-L}{w_{k,l}(I_{k,l}(i,j)-μ(i,j))^2}}}
$$

其中$I(i,j)$表示原始图像i行j列元素的值。

Generalized Gaussian Distribution:

$$
f(x;α,σ^2)=\frac {α} {2βΓ(1/α)} e^{-(\frac {|x|}{β})^α} \\
β=σ\sqrt{\frac{Γ(1/α)}{Γ(3/α)}} \\
Γ(α)=\int^{\infty}_{0}{t^{α-1}e^{-t}dt} α>0
$$

Neighbours:

$$
HorizontalNeighbour(i,j)=MSCN(i,j)MSCN(i,j+1) \\
VerticalNeighbour(i,j)=MSCN(i,j)MSCN(i+1,j) \\
OnDiagonalNeighbour(i,j)=MSCN(i,j)MSCN(i+1,j+1) \\
OffDiagonalNeighbour(i,j)=MSCN(i,j)MSCN(i+1,j-1)
$$

Asymmetric Generalized Gaussian Distribution:

$$
f(x;α,σ_l^2,σ_r^2)=
\frac {α}{(β_l+β_r)Γ(1/α)}e^{-(\frac {-x}{β_l})^α} x<0
\frac {α}{(β_l+β_r)Γ(1/α)}e^{-(\frac {x}{β_r})^α} x>=0
β_l=σ_l\sqrt{\frac{Γ(1/α)}{Γ(3/α)}} \\
β_r=σ_r\sqrt{\frac{Γ(1/α)}{Γ(3/α)}}
$$

Examples
-------

```
import os
from scient.image import feature
import numpy
from PIL import Image

images=['test/data/I10.BMP','test/data/i10_23_3.bmp','test/data/i10_23_4.bmp','test/data/i10_23_5.bmp','test/data/i10_24_5.bmp']

#读取图像文件
images=[Image.open(os.path.join(os.path.dirname(feature.__file__),'..',i)) for i in images]

#计算brisque
brisques=[]
for i in images:
    brisques.append(feature.brisque(numpy.array(i.convert('L'))))
print(brisques)
```

运行结果

```
[(2.8390000000000026, 0.5387382509471336, 0.8180000000000005, 0.1597336483186561, 0.19928197982139934, 0.4696747920784309, 0.8640000000000005, 0.17081167501931036, 0.1703080506100513, 0.440894038756712, 0.8610000000000007, -0.002437981115828319, 0.2983089768677447, 0.2943996123553127, 0.8670000000000007, 0.03657370089459203, 0.2641503963750437, 0.32229688865209727), (2.179000000000002, 0.3755805588864052, 0.6610000000000005, 0.2105638785869636, 0.06573065885425396, 0.3546433105372317, 0.7250000000000005, 0.2035633011201771, 0.04895566298941261, 0.2895746994148656, 0.7110000000000005, 0.09196294223642214, 0.10660221933416321, 0.22150476223116147, 0.7220000000000004, 0.10061626044729756, 0.09951649928883519, 0.22307536755643081), (1.489000000000001, 0.19567592119387475, 0.4370000000000002, 0.16656579278574843, 0.005144811587270607, 0.1595102390164801, 0.4400000000000002, 0.14819323960693676, 0.007946536338563829, 0.14400949152877282, 0.46900000000000025, 0.1304195444573072, 0.010840852166168865, 0.12285748598680354, 0.47300000000000025, 0.12785146234621667, 0.011051488263507676, 0.11939877242752284), (1.2570000000000008, 0.1189807661854071, 0.2940000000000001, 0.09858069094224381, 0.0033503171775502846, 0.1003980673321924, 0.2960000000000001, 0.09662228540309649, 0.0037953392707882772, 0.09854664422093222, 0.3160000000000001, 0.08840261656054116, 0.004225987220008733, 0.08029184471742051, 0.3180000000000001, 0.08631426420092875, 0.004399447310061135, 0.07751730107145516), (1.203000000000001, 0.14103130545847511, 0.3270000000000001, 0.10623288442963101, 0.008919473174326557, 0.12226537626029133, 0.3280000000000001, 0.06853644417080812, 0.02378947796849877, 0.10143999168472712, 0.33900000000000013, 0.05689116726400874, 0.02385946076111514, 0.08256978072093775, 0.33900000000000013, 0.05450324427873719, 0.02492368706293601, 0.0813272014967197)]
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "scient",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "science compute, image, natural language, machine learning, neural network, optimize algorithm, graphic algorithm",
    "author": null,
    "author_email": "yaomsn@live.cn",
    "download_url": "https://files.pythonhosted.org/packages/d5/94/38cc385175457e762f918a61e31cb7036bd61f6541eead8d484c91a67e29/scient-0.3.0.tar.gz",
    "platform": "any",
    "description": "# scient\r\n\r\n**scient**\u4e00\u4e2a\u7528python\u5b9e\u73b0\u79d1\u5b66\u8ba1\u7b97\u76f8\u5173\u7b97\u6cd5\u7684\u5305\uff0c\u5305\u62ec\u81ea\u7136\u8bed\u8a00\u3001\u56fe\u50cf\u3001\u795e\u7ecf\u7f51\u7edc\u3001\u4f18\u5316\u7b97\u6cd5\u3001\u673a\u5668\u5b66\u4e60\u3001\u56fe\u8ba1\u7b97\u7b49\u6a21\u5757\u3002\r\n\r\n**scient**\u6e90\u7801\u548c\u7f16\u8bd1\u5b89\u88c5\u5305\u53ef\u4ee5\u5728`Python package index`\u83b7\u53d6\u3002\r\n\r\nThe source code and binary installers for the latest released version are available at the [Python package index].\r\n\r\n[https://pypi.org/project/scient](https://pypi.org/project/scient)\r\n\r\n\u53ef\u4ee5\u7528`pip`\u5b89\u88c5`scient`\u3002\r\n\r\nYou can install `scient` like this:\r\n    \r\n```\r\npip install scient\r\n```\r\n\r\n\u4e5f\u53ef\u4ee5\u7528`setup.py`\u5b89\u88c5\u3002\r\n\r\nOr in the `scient` directory, execute:\r\n\r\n```\r\npython setup.py install\r\n```\r\n\r\n## scient.image\r\n\r\n\u56fe\u50cf\u76f8\u5173\u7b97\u6cd5\u6a21\u5757\uff0c\u5305\u62ec\u8fb9\u7f18\u68c0\u6d4b\u3001\u56fe\u50cf\u76f8\u4f3c\u5ea6\u8ba1\u7b97\u3001\u56fe\u50cf\u8d28\u91cf\u8bc4\u4ef7\u3001\u56fe\u50cf\u7279\u5f81\u63d0\u53d6\u7b49\u3002\r\n\r\n### scient.image.friqa\r\n\r\n\u5168\u53c2\u8003\u56fe\u50cf\u8d28\u91cf\u8bc4\u4ef7\u6a21\u5757\uff0c\u5305\u62ec\u5cf0\u503c\u4fe1\u566a\u6bd4\uff08PSNR\uff09\uff0c\u7ed3\u6784\u76f8\u4f3c\u5ea6\uff08SSIM\uff09\uff0c\u76f4\u65b9\u56fe\u76f8\u4f3c\u5ea6\uff08HistSim\uff09\u3002\r\n\r\n#### scient.image.friqa.psnr(image1,image2,max_pix=255)\r\n\r\nParameters\r\n----------\r\nimage1 : numpy.array 2D or 3D\uff0c\u53c2\u8003\u56fe\u50cf\r\n\r\nimage2 : numpy.array 2D or 3D\uff0c\u5f85\u8bc4\u4ef7\u56fe\u50cf\r\n\r\nmax_pix : int, optional default is 255, \u50cf\u7d20\u503c\u7684\u6700\u5927\u503c\uff0c\u9ed8\u8ba4\u503c\u662f255.\r\n\r\nReturns\r\n-------\r\nfloat\r\n\r\nAlgorithms\r\n-------\r\nPSNR(Peak Signal to Noise Ratio)\uff0c\u5cf0\u503c\u4fe1\u566a\u6bd4\uff0c\u662f\u4e00\u79cd\u8bc4\u4ef7\u56fe\u50cf\u7684\u5ba2\u89c2\u6807\u51c6\uff0c\u5355\u4f4ddB\u3002\u56fe\u50cf\u5728\u7ecf\u8fc7\u538b\u7f29\u4e4b\u540e\uff0c\u4f1a\u5728\u67d0\u79cd\u7a0b\u5ea6\u4e0e\u539f\u59cb\u56fe\u50cf\u4e0d\u540c\uff0cPSNR\u503c\u7528\u6765\u8861\u91cf\u7ecf\u8fc7\u5904\u7406\u540e\u7684\u56fe\u50cf\u54c1\u8d28\u662f\u5426\u4ee4\u4eba\u6ee1\u610f\u3002\r\n\r\n$$\r\nPSNR=10 \\cdot \\log _ {10} ( \\frac { MAX _ I ^ 2 } { MSE }) = 20 \\cdot \\log _ {10} ( \\frac { MAX _ I } { MSE })\r\n$$\r\n\r\n\u5176\u4e2d\uff0c$MAX _ I$\u662f\u56fe\u50cf\u50cf\u7d20\u503c\u7684\u6700\u5927\u503c\uff0c\u4e00\u822c\u6bcf\u4e2a\u91c7\u6837\u70b9\u75288\u4f4d\u8868\u793a\uff0c\u90a3\u4e48$MAX _ I$\u5c31\u662f255\u3002\r\n\r\n$MSE$\u662f\u5f85\u8bc4\u4ef7\u56fe\u50cf\u4e0e\u53c2\u8003\u56fe\u50cf\u7684\u5747\u65b9\u8bef\u5dee\uff0c$MSE$\u8d8a\u5c0f\uff0cPSNR\u8d8a\u5927\uff1bPSNR\u8d8a\u5927\uff0c\u5f85\u8bc4\u4ef7\u56fe\u50cf\u8d28\u91cf\u8d8a\u597d\u3002\r\n\r\n* PSNR\u9ad8\u4e8e40dB\u8bf4\u660e\u5f85\u8bc4\u4ef7\u56fe\u50cf\u8d28\u91cf\u6781\u597d,\u975e\u5e38\u63a5\u8fd1\u539f\u59cb\u56fe\u50cf\uff1b\r\n* PSNR\u572830\u201440dB\u8bf4\u660e\u5f85\u8bc4\u4ef7\u56fe\u50cf\u8d28\u91cf\u662f\u8f83\u597d\uff0c\u867d\u7136\u6709\u660e\u663e\u5931\u771f\u4f46\u53ef\u4ee5\u63a5\u53d7\uff1b\r\n* PSNR\u572820\u201430dB\u8bf4\u660e\u5f85\u8bc4\u4ef7\u56fe\u50cf\u8d28\u91cf\u5dee\uff1b\r\n* PSNR\u4f4e\u4e8e20dB\u8bf4\u660e\u5f85\u8bc4\u4ef7\u56fe\u50cf\u8d28\u91cf\u4e0d\u53ef\u63a5\u53d7\u3002\r\n\r\n\r\nPSNR\u7f3a\u70b9\uff1a\u57fa\u4e8e\u5bf9\u5e94\u50cf\u7d20\u70b9\u95f4\u7684\u8bef\u5dee\uff0c\u5373\u57fa\u4e8e\u8bef\u5dee\u654f\u611f\u7684\u56fe\u50cf\u8d28\u91cf\u8bc4\u4ef7\u3002\u7531\u4e8e\u5e76\u672a\u8003\u8651\u5230\u4eba\u773c\u7684\u89c6\u89c9\u7279\u6027\uff08\u4eba\u773c\u5bf9\u7a7a\u95f4\u9891\u7387\u8f83\u4f4e\u7684\u5bf9\u6bd4\u5dee\u5f02\u654f\u611f\u5ea6\u8f83\u9ad8\uff0c\u4eba\u773c\u5bf9\u4eae\u5ea6\u5bf9\u6bd4\u5dee\u5f02\u7684\u654f\u611f\u5ea6\u8f83\u8272\u5ea6\u9ad8\uff0c\u4eba\u773c\u5bf9\u4e00\u4e2a \u533a\u57df\u7684\u611f\u77e5\u7ed3\u679c\u4f1a\u53d7\u5230\u5176\u5468\u56f4\u90bb\u8fd1\u533a\u57df\u7684\u5f71\u54cd\u7b49\uff09\uff0c\u56e0\u800c\u7ecf\u5e38\u51fa\u73b0\u8bc4\u4ef7\u7ed3\u679c\u4e0e\u4eba\u7684\u4e3b\u89c2\u611f\u89c9\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002\r\n\r\nExamples\r\n-------\r\n\r\n```\r\nimport os\r\nfrom scient.image import friqa\r\nimport numpy\r\nfrom PIL import Image\r\n\r\nref_image='test/data/I10.BMP'\r\nimages=['test/data/I10.BMP','test/data/i10_23_3.bmp','test/data/i10_23_4.bmp','test/data/i10_23_5.bmp','test/data/i10_24_5.bmp']\r\n\r\n#\u8bfb\u53d6\u56fe\u50cf\u6587\u4ef6\r\nref_image=Image.open(os.path.join(os.path.dirname(friqa.__file__),'..',ref_image))\r\nimages=[Image.open(os.path.join(os.path.dirname(friqa.__file__),'..',i)) for i in images]\r\n\r\n#\u8ba1\u7b97psnr\r\nfor i in images:\r\n    print(friqa.psnr(numpy.array(ref_image),numpy.array(i)))\r\n```\r\n\r\n\u8fd0\u884c\u7ed3\u679c\r\n\r\n```\r\n100\r\n32.436263852012544\r\n31.184291262813648\r\n30.272831107297733\r\n29.3584810257951\r\n```\r\n    \r\n    \r\n#### scient.image.friqa.ssim(image1,image2,k1=0.01,k2=0.03,block_size=(8, 8),max_pix=255)\r\n\r\nParameters\r\n----------\r\nimage1 : numpy.array 2D\r\n\r\nimage2 : numpy.array 2D\r\n\r\nk1 : float, optional\uff0ck1<<1,\u907f\u514d\u5206\u6bcd\u4e3a0\u9020\u6210\u4e0d\u7a33\u5b9a. The default is 0.01.\r\n\r\nk2 : float, optional\uff0ck2<<1,\u907f\u514d\u5206\u6bcd\u4e3a0\u9020\u6210\u4e0d\u7a33\u5b9a. The default is 0.03.\r\n\r\nblock_size : tuple, optional\uff0c\u5c06\u56fe\u50cf\u5206\u6210\u591a\u4e2ablock,\u91c7\u7528gaussian\u52a0\u6743\u8ba1\u7b97\u6240\u6709block\u7684\u5747\u503c\u3001\u65b9\u5dee\u3001\u534f\u65b9\u5dee,\u8fdb\u800c\u8ba1\u7b97\u6240\u6709block\u7684ssim,\u6700\u540e\u7684ssim\u53d6\u6240\u6709block\u7684\u5e73\u5747\u503c. The default is (8,8).\r\n\r\nmax_pix : int, optional default is 255, \u50cf\u7d20\u503c\u7684\u6700\u5927\u503c\uff0c\u9ed8\u8ba4\u503c\u662f255.\r\n\r\nReturns\r\n-------\r\nfloat\r\n\r\nAlgorithms\r\n-------\r\n\r\nSSIM(Structural Similarity)\uff0c\u7ed3\u6784\u76f8\u4f3c\u5ea6\uff0c\u7528\u4e8e\u8861\u91cf\u4e24\u4e2a\u56fe\u50cf\u76f8\u4f3c\u7a0b\u5ea6\uff0c\u6216\u68c0\u6d4b\u56fe\u50cf\u7684\u5931\u771f\u7a0b\u5ea6\u3002\r\nSSIM\u57fa\u4e8e\u6837\u672c\u4e4b\u95f4\u7684\u4eae\u5ea6(luminance,\u50cf\u7d20\u5e73\u5747\u503c)\u3001\u5bf9\u6bd4\u5ea6(contrast,\u50cf\u7d20\u6807\u51c6\u5dee)\u548c\u7ed3\u6784(structure,\u50cf\u7d20\u51cf\u5747\u503c\u9664\u4ee5\u6807\u51c6\u5dee)\u8ba1\u7b97\u3002\r\n\r\n$$\r\nSSIM(x,y)=f(l(x,y),c(x,y),s(x,y))\r\n$$\r\n\r\n$l(x,y)$\u4e3a\u4eae\u5ea6\u5bf9\u6bd4\u51fd\u6570\uff0c\u662f\u5173\u4e8e\u56fe\u50cf\u7684\u5e73\u5747\u7070\u5ea6$\u03bc_x,\u03bc_y$\u7684\u51fd\u6570\uff1b\r\n\r\n$$\r\nl(x,y)=\\frac { 2\u03bc_x \u03bc_y + C1 } { \u03bc_x^2 \u03bc_y^2 + C1 } \\\\\r\n\u03bc_x=\\frac { 1 } { N } \\sum^{N}_{i=1}{x_i} \\\\\r\nC1=(K_1 L)^2\r\n$$\r\n\r\n\u50cf\u7d20\u503c\u7684\u6700\u5927\u503c\uff0c\u9ed8\u8ba4\u503c\u662f255. K1<<1\u3002\r\n\r\n$c(x,y)$\u4e3a\u5bf9\u6bd4\u5ea6\u5bf9\u6bd4\u51fd\u6570\uff0c\u662f\u5173\u4e8e\u56fe\u50cf\u7684\u6807\u51c6\u5dee$\u03c3_x,\u03c3_y$\u7684\u51fd\u6570\uff1b\r\n\r\n$$\r\nc(x,y)=\\frac { 2\u03c3_x \u03c3_y + C2 } { \u03c3_x^2 \u03c3_y^2 + C2 } \\\\\r\n\u03c3_x=(\\frac { 1 } { N-1 } \\sum^{N}_{i=1}{(x_i-\u03bc_x)^2})^{\\frac { 1 } { 2 }} \\\\\r\nC2=(K_2 L)^2\r\n$$\r\n\r\nK2<<1\r\n\r\n$s(x,y)$\u4e3a\u7ed3\u6784\u5bf9\u6bd4\u51fd\u6570\uff0c\u662f\u5173\u4e8e\u56fe\u50cf\u7684\u6807\u51c6\u5316$\\frac { x-\u03bc_x } { \u03c3_x },\\frac { y-\u03bc_y } { \u03c3_y }$\u7684\u51fd\u6570\uff1b\r\n\r\n$$\r\ns(x,y)=\\frac { \u03c3_{xy} + C3 } { \u03c3_x \u03c3_y + C3 } \\\\\r\n\u03c3_{xy}=\\frac { 1 } { N-1 } (\\sum^{N}_{i=1}{(x_i-\u03bc_x)(y_i-\u03bc_y)}) \\\\\r\n$$\r\n\r\n$$\r\nSSIM(x,y)=[l(x,y)]^\u03b1[c(x,y)]^\u03b2[s(x,y)]^\u03b3\r\n$$\r\n\r\n\u03b1,\u03b2,\u03b3\u53d61\uff0c\u4ee4$C_3=\\frac { C_2 } { 2 }$\uff0c\u53ef\u5c06SSIM\u7b80\u5316\u4e3a\uff1a\r\n\r\n$$\r\nSSIM(x,y)=\\frac { (2\u03bc_x \u03bc_y + C1)(2\u03c3_{xy} + C2) } { (\u03bc_x^2 \u03bc_y^2 + C1)(\u03c3_x^2 \u03c3_y^2 + C2) }\r\n$$\r\n\r\nSSIM\u53d6\u503c\u8303\u56f4\u4e3a[0,1]\uff0c\u503c\u8d8a\u5927\u8868\u793a\u56fe\u50cf\u8d28\u91cf\u8d8a\u597d\u3002\r\nSSIM\u5177\u6709\uff1a\u5bf9\u79f0\u6027\uff0cssim(x,y)==ssim(y,x);\r\n         \u6709\u754c\u6027,ssim(x,y)<=1;\r\n         \u6700\u5927\u503c\u552f\u4e00\u6027\uff0c\u5f53\u4e14\u4ec5\u5f53x==y\u65f6\uff0cssim(x,y)==1\u3002\r\nSSIM\u7f3a\u70b9\uff1a\u5bf9\u4e8e\u56fe\u50cf\u51fa\u73b0\u4f4d\u79fb\u3001\u7f29\u653e\u3001\u65cb\u8f6c\uff08\u7686\u5c5e\u4e8e\u975e\u7ed3\u6784\u6027\u7684\u5931\u771f\uff09\u7684\u60c5\u51b5\u65e0\u6cd5\u6709\u6548\u7684\u5224\u65ad\u3002\r\n\r\nExamples\r\n-------\r\n\r\n```\r\nimport os\r\nfrom scient.image import friqa\r\nimport numpy\r\nfrom PIL import Image\r\n\r\nref_image='test/data/I10.BMP'\r\nimages=['test/data/I10.BMP','test/data/i10_23_3.bmp','test/data/i10_23_4.bmp','test/data/i10_23_5.bmp','test/data/i10_24_5.bmp']\r\n\r\n#\u8bfb\u53d6\u56fe\u50cf\u6587\u4ef6\r\nref_image=Image.open(os.path.join(os.path.dirname(friqa.__file__),'..',ref_image))\r\nimages=[Image.open(os.path.join(os.path.dirname(friqa.__file__),'..',i)) for i in images]\r\n\r\n#\u8ba1\u7b97ssim\r\nfor i in images:\r\n    print(friqa.ssim(numpy.array(ref_image.convert(\"L\")),numpy.array(i.convert(\"L\"))))\r\n```\r\n\r\n\u8fd0\u884c\u7ed3\u679c\r\n\r\n```\r\n1.0\r\n0.8568124416229375\r\n0.6810351495300123\r\n0.5575398637742431\r\n0.5072153083460104\r\n```\r\n\r\n### scient.image.feature\r\n\r\n\u56fe\u50cf\u7279\u5f81\u63d0\u53d6\u6a21\u5757\uff0c\u5305\u62ecBRISQUE\uff0c\u57fa\u4e8e\u7d2f\u79ef\u6982\u7387\u7684\u9510\u5316\u56e0\u5b50\uff08CPB\uff09\uff0c\u66dd\u5149\u5ea6\u3002\r\n\r\n#### scient.image.feature.brisque(image)\r\n\r\nParameters\r\n----------\r\nimage : numpy.array 2D\r\n\r\nReturns\r\n-------\r\ntuple\r\n('gdd_\u03b1','gdd_\u03c3',\r\n'aggd_\u03b11','aggd_\u03b71','aggd_\u03c3l1','aggd_\u03c3r1',\r\n'aggd_\u03b12','aggd_\u03b72','aggd_\u03c3l2','aggd_\u03c3r2',\r\n'aggd_\u03b13','aggd_\u03b73','aggd_\u03c3l3','aggd_\u03c3r3',\r\n'aggd_\u03b14','aggd_\u03b74','aggd_\u03c3l4','aggd_\u03c3r4')\r\n\r\nAlgorithms\r\n-------\r\n BRISQUE\uff08Blind/Referenceless Image Spatial QUality Evaluator\uff09\uff0c\u662f\u4e00\u79cd\u65e0\u53c2\u8003\u7684\u7a7a\u95f4\u57df\u56fe\u50cf\u8d28\u91cf\u8bc4\u4f30\u7b97\u6cd5\u3002\u5148\u8ba1\u7b97Mean Subtracted Contrast Normalized Coefficients\uff08MSCN\u7cfb\u6570\uff09\uff0cMSCN\u7cfb\u6570\u53cd\u6620\u4e86\u7531\u4e8e\u5931\u771f\u7684\u5b58\u5728\u800c\u6539\u53d8\u7684\u7279\u5f81\u7edf\u8ba1\uff0c\u53ef\u4ee5\u7528\u6765\u4f5c\u4e3a\u56fe\u50cf\u5931\u771f\u7684\u7edf\u8ba1\u7279\u5f81\u3002\u518d\u7528MSCN\u7cfb\u6570\u4f30\u8ba1Generalized Gaussian Distribution\uff08GDD\uff09\u7684\u53c2\u6570\u03b1\u3001\u03c3\uff0c\u4ee5\u53caAsymmetric Generalized Gaussian Distribution\uff08AGGD\uff09\u5728Horizontal Neighbour, Vertical Neighbour, On Diagonal Neighbour, Off Diagonal Neighbour\u4e0a\u7684\u53c2\u6570\u03b1\u3001\u03b7\u3001\u03c3l\u3001\u03c3r\uff0c\u5c06GDD\u7684\u4e24\u4e2a\u53c2\u6570\u548cAGGD\u768416\u4e2a\u53c2\u6570\u4f5c\u4e3a\u8f93\u51fa\u7684\u7279\u5f81\u3002\r\n\r\nMSCN\u7cfb\u6570\uff1a\r\n\r\n$$\r\nMSCN(i,j)=\\frac { I(i,j)-\u03bc(i,j) } { \u03c3(i,j)+C } \\\\\r\n\u03bc(i,j)=\\sum^{K}_{k=-K}{\\sum^{L}_{l=-L}{w_{k,l}I_{k,l}(i,j)}} \\\\\r\n\u03c3(i,j)=\\sqrt{\\sum^{K}_{k=-K}{\\sum^{L}_{l=-L}{w_{k,l}(I_{k,l}(i,j)-\u03bc(i,j))^2}}}\r\n$$\r\n\r\n\u5176\u4e2d$I(i,j)$\u8868\u793a\u539f\u59cb\u56fe\u50cfi\u884cj\u5217\u5143\u7d20\u7684\u503c\u3002\r\n\r\nGeneralized Gaussian Distribution\uff1a\r\n\r\n$$\r\nf(x;\u03b1,\u03c3^2)=\\frac {\u03b1} {2\u03b2\u0393(1/\u03b1)} e^{-(\\frac {|x|}{\u03b2})^\u03b1} \\\\\r\n\u03b2=\u03c3\\sqrt{\\frac{\u0393(1/\u03b1)}{\u0393(3/\u03b1)}} \\\\\r\n\u0393(\u03b1)=\\int^{\\infty}_{0}{t^{\u03b1-1}e^{-t}dt} \u03b1>0\r\n$$\r\n\r\nNeighbours:\r\n\r\n$$\r\nHorizontalNeighbour(i,j)=MSCN(i,j)MSCN(i,j+1) \\\\\r\nVerticalNeighbour(i,j)=MSCN(i,j)MSCN(i+1,j) \\\\\r\nOnDiagonalNeighbour(i,j)=MSCN(i,j)MSCN(i+1,j+1) \\\\\r\nOffDiagonalNeighbour(i,j)=MSCN(i,j)MSCN(i+1,j-1)\r\n$$\r\n\r\nAsymmetric Generalized Gaussian Distribution:\r\n\r\n$$\r\nf(x;\u03b1,\u03c3_l^2,\u03c3_r^2)=\r\n\\frac {\u03b1}{(\u03b2_l+\u03b2_r)\u0393(1/\u03b1)}e^{-(\\frac {-x}{\u03b2_l})^\u03b1} x<0\r\n\\frac {\u03b1}{(\u03b2_l+\u03b2_r)\u0393(1/\u03b1)}e^{-(\\frac {x}{\u03b2_r})^\u03b1} x>=0\r\n\u03b2_l=\u03c3_l\\sqrt{\\frac{\u0393(1/\u03b1)}{\u0393(3/\u03b1)}} \\\\\r\n\u03b2_r=\u03c3_r\\sqrt{\\frac{\u0393(1/\u03b1)}{\u0393(3/\u03b1)}}\r\n$$\r\n\r\nExamples\r\n-------\r\n\r\n```\r\nimport os\r\nfrom scient.image import feature\r\nimport numpy\r\nfrom PIL import Image\r\n\r\nimages=['test/data/I10.BMP','test/data/i10_23_3.bmp','test/data/i10_23_4.bmp','test/data/i10_23_5.bmp','test/data/i10_24_5.bmp']\r\n\r\n#\u8bfb\u53d6\u56fe\u50cf\u6587\u4ef6\r\nimages=[Image.open(os.path.join(os.path.dirname(feature.__file__),'..',i)) for i in images]\r\n\r\n#\u8ba1\u7b97brisque\r\nbrisques=[]\r\nfor i in images:\r\n    brisques.append(feature.brisque(numpy.array(i.convert('L'))))\r\nprint(brisques)\r\n```\r\n\r\n\u8fd0\u884c\u7ed3\u679c\r\n\r\n```\r\n[(2.8390000000000026, 0.5387382509471336, 0.8180000000000005, 0.1597336483186561, 0.19928197982139934, 0.4696747920784309, 0.8640000000000005, 0.17081167501931036, 0.1703080506100513, 0.440894038756712, 0.8610000000000007, -0.002437981115828319, 0.2983089768677447, 0.2943996123553127, 0.8670000000000007, 0.03657370089459203, 0.2641503963750437, 0.32229688865209727), (2.179000000000002, 0.3755805588864052, 0.6610000000000005, 0.2105638785869636, 0.06573065885425396, 0.3546433105372317, 0.7250000000000005, 0.2035633011201771, 0.04895566298941261, 0.2895746994148656, 0.7110000000000005, 0.09196294223642214, 0.10660221933416321, 0.22150476223116147, 0.7220000000000004, 0.10061626044729756, 0.09951649928883519, 0.22307536755643081), (1.489000000000001, 0.19567592119387475, 0.4370000000000002, 0.16656579278574843, 0.005144811587270607, 0.1595102390164801, 0.4400000000000002, 0.14819323960693676, 0.007946536338563829, 0.14400949152877282, 0.46900000000000025, 0.1304195444573072, 0.010840852166168865, 0.12285748598680354, 0.47300000000000025, 0.12785146234621667, 0.011051488263507676, 0.11939877242752284), (1.2570000000000008, 0.1189807661854071, 0.2940000000000001, 0.09858069094224381, 0.0033503171775502846, 0.1003980673321924, 0.2960000000000001, 0.09662228540309649, 0.0037953392707882772, 0.09854664422093222, 0.3160000000000001, 0.08840261656054116, 0.004225987220008733, 0.08029184471742051, 0.3180000000000001, 0.08631426420092875, 0.004399447310061135, 0.07751730107145516), (1.203000000000001, 0.14103130545847511, 0.3270000000000001, 0.10623288442963101, 0.008919473174326557, 0.12226537626029133, 0.3280000000000001, 0.06853644417080812, 0.02378947796849877, 0.10143999168472712, 0.33900000000000013, 0.05689116726400874, 0.02385946076111514, 0.08256978072093775, 0.33900000000000013, 0.05450324427873719, 0.02492368706293601, 0.0813272014967197)]\r\n```\r\n",
    "bugtrack_url": null,
    "license": "Licence",
    "summary": "A python package about science compute algorithm, include natural language, image, neural network, optimize algorithm, machine learning, graphic algorithm, etc.",
    "version": "0.3.0",
    "project_urls": null,
    "split_keywords": [
        "science compute",
        " image",
        " natural language",
        " machine learning",
        " neural network",
        " optimize algorithm",
        " graphic algorithm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bcd95b02f90be5a6f54e85db58c5fa74d2856a59a2cc669d0e35f53adb94d876",
                "md5": "41ab7fb584c1669f571477f99c2b664c",
                "sha256": "7b4ce12389031738cd5c8868379b984061a453e0c77906abd93cc90f24d6a294"
            },
            "downloads": -1,
            "filename": "scient-0.3.0-cp312-cp312-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "41ab7fb584c1669f571477f99c2b664c",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": null,
            "size": 6824049,
            "upload_time": "2024-06-28T04:04:32",
            "upload_time_iso_8601": "2024-06-28T04:04:32.241881Z",
            "url": "https://files.pythonhosted.org/packages/bc/d9/5b02f90be5a6f54e85db58c5fa74d2856a59a2cc669d0e35f53adb94d876/scient-0.3.0-cp312-cp312-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d59438cc385175457e762f918a61e31cb7036bd61f6541eead8d484c91a67e29",
                "md5": "1ef71873fd5727a77873df3599557dd8",
                "sha256": "2bf546953608738fdadb017ecaedf72fbd3ef96b0a829d9e08553d0b1d3fffa2"
            },
            "downloads": -1,
            "filename": "scient-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1ef71873fd5727a77873df3599557dd8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7327930,
            "upload_time": "2024-06-28T04:05:42",
            "upload_time_iso_8601": "2024-06-28T04:05:42.925629Z",
            "url": "https://files.pythonhosted.org/packages/d5/94/38cc385175457e762f918a61e31cb7036bd61f6541eead8d484c91a67e29/scient-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-28 04:05:42",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "scient"
}
        
Elapsed time: 0.27245s