Fetch the repository succeeded.
"""
直方图可以显示一个数据集中数据分布频率的统计结果;在遥感领域,数据集就是图片。其中的
数据分布就是区间在0~255之间的像素数出现的次数;
在RGB图形中,颜色是由数字组成的3位元祖表达,其中(0,0,0)代表黑色,(255,255,255)
代表白色;
直方图 y轴代表频率值,x轴代表区间中256种像素值;
"""
from osgeo import gdal_array
import turtle as t
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]
print("a:", a)
print("fa:", fa)
# print("1:", n[1:])
# print("2:", n[:-1])
# print("3:", hist)
return hist
def draw_histogram(hist, scale=True):
# 画x、y轴坐标系
t.color("black")
axes = ((-355, -200), (355, -200), (-355, -200), (-355, 250))
t.up()
for p in axes:
t.goto(p)
t.down()
# 画 x轴的名称
t.up()
t.goto(0, -250)
t.write("VALUE", font=("Arial", 12, "bold"))
# 画 x轴的刻度
t.up()
x = -355
y = -200
for i in range(1,11):
x = x + 65
t.goto(x, y)
t.down()
t.goto(x, y-10)
t.up()
t.goto(x, y-25)
t.write("{}".format((i*25)), align="center")
# 画 y轴的刻度
x = -355
y = -200
t.up()
pixels = sum(hist[0])
if scale:
max = 0
for h in hist:
hmax = h.max()
if hmax > max:
max = hmax
pixels = max
label = int(pixels/10)
for i in range(1, 11):
y = y + 45
t.goto(x, y)
t.down()
t.goto(x-10, y)
t.up()
t.goto(x-15, y-6)
t.write("{}".format((i*label)), align="right")
# 画R、G、B三色曲线
x_ratio = 709.0/256
y_ratio = 450.0/pixels
colors = ["red", "green", "blue"]
for j in range(len(hist)):
h = hist[j]
x = -354
y = -199
t.up()
t.goto(x, y)
t.down()
t.color(colors[j])
for i in range(255):
x = i * x_ratio
y = h[i] * y_ratio
x = x - (709/2)
y = y + -199
t.goto(x, y)
arr = gdal_array.LoadFile("TIF/FalseColor/swap.tif")
histograms = []
for b in arr:
histograms.append(histogram(b))
draw_histogram(histograms)
t.pen(shown=False)
t.done()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。