是否有任何转换器可以提取具有确定值的像素百分比并将其显示为属性?我的阅读器将是一个 tiff,而编写器将是一个 csv 文件,其中包含每个波段黑色像素百分比的属性。
谢谢。
我还有其他属性,来自 RasterStatisticsCalculator
以下是如何使用
numpy
中的 python
计算统计数据,函数 prop_black()
可用于计算每个颜色通道中黑色像素的比例:
from skimage.io import imread
import numpy as np
import matplotlib.pylab as plt
from numpy import mean, min, max, std, sum
import pandas as pd
def prop_black(im):
return 100*(sum(im == 0) / np.prod(im.shape))
im = imread('lena_color.tiff')
assert(len(im.shape) == 3) # must have color channels
funcs = [mean, min, max, std, sum, prop_black]
df = pd.DataFrame(columns = ['band_index'] + [f.__name__ for f in funcs])
for k in range(im.shape[2]):
stat_dict = {'band_index': k}
for func in funcs:
stat_dict[func.__name__] = func(im[...,k])
df = df.append(stat_dict, ignore_index=True)
df['band_index'] = df['band_index'].astype(int)
df.head()
# band_index mean amin amax std sum prop_black
#0 0 180.223454 0.0 255.0 49.049418 47244497.0 0.000381
#1 1 99.051090 0.0 248.0 52.877750 25965649.0 0.004196
#2 2 105.410038 0.0 225.0 34.058561 27632609.0 0.002670
使用的输入图像(
lena_color.tiff'
)附在下面: