日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python中直方图-Numpy,Python中的“拉伸”直方图(级别)

發布時間:2023/12/10 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中直方图-Numpy,Python中的“拉伸”直方图(级别) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是一種方法-

def stretch(a,lower_thresh,upper_thresh):

r = 255.0/(upper_thresh-lower_thresh+2) # unit of stretching

out = np.round(r*(a-lower_thresh+1)).astype(a.dtype) # stretched values

out[a

out[a>upper_thresh] = 255

return out

根據OP,設置的標準是:

>將246以上的每個像素“移動”到255,因此247及以上的像素應變為255.

> 186以下的每個像素都為零,因此185以下的像素應變為0.

>因此,基于上述兩個要求,186應該變為大于0的值,依此類推,直到246應該小于255.

另外,我們也可以使用np.where使它更緊湊-

def stretch(a,upper_thresh):

r = 255.0/(upper_thresh-lower_thresh+2) # unit of stretching

out = np.round(r*np.where(a>=lower_thresh,a-lower_thresh+1,0)).clip(max=255)

return out.astype(a.dtype)

樣品運行-

# check out first row input,output for variations

In [216]: a

Out[216]:

array([[186,187,188,246,247],[251,195,103,9,211],[ 21,242,36,87,70]],dtype=uint8)

In [217]: stretch(a,lower_thresh=186,upper_thresh=246)

Out[217]:

array([[ 4,8,12,251,255],[255,41,107],[ 0,234,0]],dtype=uint8)

總結

以上是生活随笔為你收集整理的python中直方图-Numpy,Python中的“拉伸”直方图(级别)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。