求直方图
hist = cv2.calcHist([img],[0],None,[256],[0,256])
https://segmentfault.com/a/1190000015674654
判断直方图是否是双峰的函数 C++
https://www.cnblogs.com/Imageshop/p/3307308.html
绘制直方图
from matplotlib import pyplot as plt
plt.plot(hist);plt.show()
https://blog.csdn.net/jnulzl/article/details/47171549
平滑直方图
一维高斯滤波
https://loopvoid.github.io/2017/03/04/%E4%B8%80%E7%BB%B4%E4%BF%A1%E5%8F%B7%E7%9A%84%E9%AB%98%E6%96%AF%E6%BB%A4%E6%B3%A2/
https://www.zhihu.com/question/54918332
调大(sigma)即提高了远处像素对中心像素的影响程度
窗口越大自然近似越好
https://cloud.tencent.com/developer/article/1352446
均值滤波平滑直方图
int winSize = 5;
int winMidSize = winSize / 2;
for(int i = winMidSize; i < NBins - winMidSize; ++i)
{
float mean = 0;
for(int j = i - winMidSize; j <= (i + winMidSize); ++j)
{
mean += hist[j];
}
hist[i] = mean / winSize;
}
https://codeday.me/bug/20190724/1519439.html
list类型操作
删除元素
del a_list[1: 3]
pop()
remove()
clear()
http://c.biancheng.net/view/2209.html
list 常用操作
list 增加元素
li.append("new")
li.insert(2, "new")
li.extend(["two", "elements"])
https://www.runoob.com/python3/python3-list-operator.html
Python-字符串中指定位置插入一个字符
str_1='wo shi yi zhi da da niu/n'
str_list=list(str_1)
nPos=str_list.index('/')
str_list.insert(nPos,',')
str_2="".join(str_list)
print(str_2)
https://www.jianshu.com/p/a2f6f98284e2
Python三种方法删除列表中的元素、方法一、用remove("")方法删除指定元素,没有该元素时报错;
>>> number=[1,3,2,0]
>>> number.remove(1)#删除指定元素1,这里是int类型因此不需要引号
>>> print(number)
[3, 2, 0]
方法二、利用del[索引数] 函数删除指定索引数的元素;
>>> number=[1,3,2,0]
>>> del number[3]#删除指定索引数的元素,这里是3
>>> print(number)
[1, 3, 2]
方法三、利用pop()方法弹出元素,当()内无索引数时默认弹出最后一个元素;
>>> number=[1,3,2,0]
>>> number.pop(1)#弹出索引数为1的元素
3
>>> print(number)#由此看出pop方法可以改变原列表
[1, 2, 0]
https://blog.csdn.net/qq_32718875/article/details/79113542
min() 方法返回列表元素中的最小值。
cmp(x,y) 函数用于比较2个对象,如果 x < y 返回 -1, 如果 x == y 返回 0, 如果 x > y 返回 1。
b = a[i:j:s]这种格式呢,i,j与上面的一样,但s表示步进,缺省为1.
所以a[i:j:1]相当于a[i:j]
当s<0时,i缺省时,默认为-1. j缺省时,默认为-len(a)-1
所以a[::-1]相当于 a[-1:-len(a)-1:-1],也就是从最后一个元素到第一个元素复制一遍。所以你看到一个倒序的东东。
https://www.cnblogs.com/mxh1099/p/5804064.html
x=-123
`x`[::-1] 得到 '321-'
`x` 表示整型变成字符串
=========================================================================
sort()与sorted()的不同在于,sort()是在原位重新排列列表,而sorted()是产生一个新的列表。
L = [5, 2, 3, 1, 4]
L.sort()
sorted(L)
来自
=========================================================================
寻找list中最大元素对应的索引
https://blog.csdn.net/Nov_csdn/article/details/52959346
列表的逆序遍历
for i in range(len(a)-1,-1,-1):
https://blog.csdn.net/qq_22186119/article/details/79201205
返回所有符合条件的下标
https://blog.csdn.net/lanchunhui/article/details/50952663
https://blog.csdn.net/hftytf/article/details/84039336
统计list中满足条件部分指定value的个数
np.sum(list(map(lambda x: x == 0, lst)))
https://www.zhihu.com/question/59874808
两个列表里元素对应相乘
向量点乘 (dot) 和对应分量相乘 (multiply) :
>>> a
array([1, 2, 3])
>>> b
array([ 1., 1., 1.])
>>> np.multiply(a,b)
array([ 1., 2., 3.])
>>> np.dot(a,b)
6.0
https://blog.csdn.net/weixin_36060730/article/details/79743704
从1D阵列或列表中获取局部最大值
from scipy.signal import argrelmax
t=linspace(-4,40,1000)
y=sin(t)
argrelmax(y)[0]
https://codeday.me/bug/20190301/737963.html
将一组数分成每3个一组
a = [1,2,3,4,5,6,7,8,9,10,11]
step = 3
b = [a[i:i+step] for i in range(0,len(a),step)]
https://blog.csdn.net/Mr_Cat123/article/details/80584988
list 合并去重
A = [‘a’,‘b’,‘c’,‘a’,‘b’]
b = [‘a’,‘b’]
print(list(set(A+b)))
https://blog.csdn.net/m0_43432638/article/details/88707390
感知哈希算法
https://blog.csdn.net/u013421629/article/details/85007793
multiprocessing多进程
如果使用多线程实际上还是在一个核上做并发处理。不过,如果使用多进程就可以真正利用多核,因为各进程之间是相互独立的,不共享资源,可以在不同的核上执行不同的进程,达到并行的效果。
from multiprocessing import Process
def f(name):
print 'hello', name
if __name__ == '__main__':
p = Process(target=f, args=('bob',)) # 新建一个子进程p,目标函数是f,args是函数f的参数列表
p.start() # 开始执行进程
p.join() # 等待子进程结束
如果要同时创建多个子进程可以使用multiprocessing.Pool类。该类可以创建一个进程池,然后在多个核上执行这些进程。
pool = multiprocessing.Pool(processes=4) # 创建4个进程
results = []
for i in xrange(10):
msg = "hello %d" %(i)
results.append(pool.apply_async(func, (msg, )))
pool.close() # 关闭进程池,表示不能再往进程池中添加进程,需要在join之前调用
pool.join() # 等待进程池中的所有进程执行完毕
print ("Sub-process(es) done.")
for res in results:
print (res.get())
https://blog.csdn.net/jinping_shi/article/details/52433867
numba加速
在for循环函数前面加一个numba的修饰器
https://cloud.tencent.com/developer/article/1488555
https://blog.csdn.net/qq_36618444/article/details/106016245



