class Histogram -- Histogram 物件

histogram 物件由 Image.get_histogram() 回傳。底層類別名稱為 histogram

對於灰階影像,直方圖具有單一通道的分箱。對於 RGB565 影像,直方圖具有三個通道,涵蓋 CIE-LAB 的 LAB 軸。在這兩種情況下,每個通道都會經過正規化,使其分箱總和為 1.0。

每個通道的分箱清單同時透過繫結方法(hist.bins())與下標表示法(hist[0])公開。高階的歸約 get_percentile()get_threshold()get_statistics() 會回傳對應的 PercentileThresholdStatistics attrtuple。

class image.histogram

請呼叫 Image.get_histogram() 來建立此物件。它沒有公開的建構子。

bins() list[float]

回傳灰階直方圖的分箱清單。每個項目的範圍為 0.0 至 1.0,且所有項目總和為 1.0。

等同於 histogram[0]

l_bins() list[float]

回傳 RGB565 直方圖中 LAB L 通道的分箱清單。每個項目的範圍為 0.0 至 1.0,且所有項目總和為 1.0。

等同於 histogram[0]

a_bins() list[float]

回傳 RGB565 直方圖中 LAB A 通道的分箱清單。每個項目的範圍為 0.0 至 1.0,且所有項目總和為 1.0。

等同於 histogram[1]

b_bins() list[float]

回傳 RGB565 直方圖中 LAB B 通道的分箱清單。每個項目的範圍為 0.0 至 1.0,且所有項目總和為 1.0。

等同於 histogram[2]

get_percentile(percentile: float) image.percentile

計算每個直方圖通道的 CDF,並回傳在所要求 percentile(範圍為 0.01.0 的浮點數)處的分箱值。

適合在忽略離群值的情況下尋找色彩分布的最小值/最大值(get_percentile(0.05)get_percentile(0.95) 可提供穩健的最小值/最大值)。

回傳一個 Percentile attrtuple。

get_threshold() image.threshold

對每個通道使用大津法(Otsu's Method)來尋找能將各通道分布最佳地分割為「背景」與「前景」兩半的閾值。回傳的閾值很適合直接餵入 Image.binary() 或任何其他接受 LAB L/A/B 色彩閾值的方法。

回傳一個 Threshold attrtuple。

get_statistics() image.statistics

計算每個直方圖通道的平均值、中位數、眾數、標準差、最小值、最大值、下四分位數與上四分位數。

回傳一個 Statistics attrtuple。

get_stats() image.statistics

get_statistics() 的別名。

statistics() image.statistics

get_statistics() 的別名。