我是靠谱客的博主 要减肥楼房,最近开发中收集的这篇文章主要介绍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)

最后

以上就是要减肥楼房为你收集整理的python中绘制数组直方图一维数组划分10组,在直方图中查找区域设置最小值(一维数组)(Python)...的全部内容,希望文章能够帮你解决python中绘制数组直方图一维数组划分10组,在直方图中查找区域设置最小值(一维数组)(Python)...所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部