python中绘制数组直方图一维数组划分10组,在直方图中查找区域设置最小值(一维数组)(Python)...

I have processed radar image and to detect water I have to find local minimum in the histogram. Histogram is little bit different for every area so I have to automatically find local minimum based on every histogram.

V7u0i.png

My input array is 1D array of image values (0.82154, 0.012211,...). I know how to create histogram in numpy and matplotlib but I do not know what should I do to determine locale minimum which is showed in the picture. I use python scipy libraries.

First step should be to smooth the histogram for easier determination of minimum, could you tell me what to use to smooth data ? Something like this:

aYdGe.png

解决方案

You can smooth the data with numpy with numpy.convolve() or you can use the following function:

import numpy

def smooth(x,window_len=11,window='hanning'):

if x.ndim != 1:

raise ValueError, "smooth only accepts 1 dimension arrays."

if x.size < window_len:

raise ValueError, "Input vector needs to be bigger than window size."

if window_len<3:

return x

if not window in ['flat', 'hanning', 'hamming', 'bartlett', 'blackman']:

raise ValueError, "Window is on of 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'"

s=numpy.r_[x[window_len-1:0:-1],x,x[-2:-window_len-1:-1]]

#print(len(s))

if window == 'flat': #moving average

w=numpy.ones(window_len,'d')

else:

w=eval('numpy.'+window+'(window_len)')

y=numpy.convolve(w/w.sum(),s,mode='valid')

return y

Also please take a look at the scipy documentation:

If you are looking for all entries in the 1d array a smaller than their neighbors, you can try

numpy.r_[True, a[1:] < a[:-1]] & numpy.r_[a[:-1] < a[1:], True]

In SciPy >= 0.11 you can use the following:

import numpy as np

from scipy.signal import argrelextrema

x = np.random.random(12)

# for local minima

argrelextrema(x, np.less)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值