2 Star 4 Fork 3

汉塞大叔/Geospatial_Analysis_By_Python

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
7.3.1 直方图均衡化.py 855 Bytes
Copy Edit Raw Blame History
汉塞大叔 authored 2021-01-20 20:59 +08:00 . 上传py
from osgeo import gdal_array
import operator
from functools import reduce
def histogram(a, bins=list(range(0, 256))):
fa = a.flat
n = gdal_array.numpy.searchsorted(gdal_array.numpy.sort(fa), bins)
hist = n[1:] - n[:-1]
return hist
def strehch(a):
hist = histogram(a)
lut = []
for b in range(0, len(hist), 256):
step = reduce(operator.add, hist[b:b+256])/255
n = 0
for i in range(255):
lut.append(n/step)
n = n + hist[i + b]
gdal_array.numpy.take(lut, a, out=a)
asrc="swap_02.tif"
return asrc
arr = gdal_array.LoadFile("TIF/FalseColor/swap.tif")
stretched = strehch(arr)
output = gdal_array.SaveArray(arr, "TIF/FalseColor/stretched.tif", format="GTiff",
prototype="TIF/FalseColor/swap.tif")
output = None
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/fengfeng233/geospatial_-analysis_-by_-python.git
git@gitee.com:fengfeng233/geospatial_-analysis_-by_-python.git
fengfeng233
geospatial_-analysis_-by_-python
Geospatial_Analysis_By_Python
master

Search