DeduplicateSimilarImages

影像處理、最佳化

描述

找出感知上相似的間接影像 XObject,把其參照改指向確定性的正規影像,並可選擇移除重複物件

Candidates must have the same semantic image dictionary after excluding encoded-container fields, then pass a 64-bit difference-hash threshold and a 64 × 64 decoded colour-sample comparison

語法

Function TPDFlib.DeduplicateSimilarImages(
  MaxHashDistance, MaxMeanError, MaxChannelError,
  Options: Integer): Integer; Overload;
Function TPDFlib.DeduplicateSimilarImages(
  MaxHashDistance, MaxMeanError, MaxChannelError,
  Options: Integer;
  Out Stats: TPDFlibImageSimilarityDedupStats): Integer; Overload;

參數

MaxHashDistance兩個 64 位元差異雜湊之間的最大漢明距離,0 到 7
MaxMeanError解碼取樣間的平均絕對通道差異上限,0 到 255
MaxChannelError任一取樣顏色通道的最大絕對差異,0 到 255
OptionsPDF_RESOURCE_DEDUP_DRY_RUN、PDF_RESOURCE_DEDUP_GARBAGE_COLLECT、兩個旗標,或 0
Stats接收解碼、候選、比較、可接受誤差、參照、酬載與物件收集計數器

傳回值

Positive value被合併的相似影像物件數,或 dry run 所回報的數量
0找不到可接受的一組、未載入任何文件,或門檻與選項無效

備註

每個被接受群組中物件編號與 generation 最小的影像成為標準影像

/Length、/Filter 與 /DecodeParms 描述的是編碼儲存形式,可以不同;但尺寸、色彩空間、位元深度、遮罩、decode 陣列、內插、選用內容、中繼資料與其他語義字典項必須一致

無法解碼的影像會被略過並計入 DecodeFailures

雜湊切成八個索引帶,在比較解碼取樣之前先把候選搜尋限制在支援的距離範圍內

這是有意為之的近似視覺操作:它取樣固定的 64 × 64 格線,因此即使所有門檻都設為零,小於取樣格的差異仍可能被遺漏

需要位元組級完全一致的證明時請用 DeduplicateResources;對不熟悉的內容選擇門檻之前,先用 dry run 搭配 GetSimilarImageDeduplicationReportJSON

範例

var
  Stats: TPDFlibImageSimilarityDedupStats;
  Merged: Integer;
begin
  Merged:= PDF.DeduplicateSimilarImages(2, 3, 12,
    PDF_RESOURCE_DEDUP_GARBAGE_COLLECT, Stats);
  PDF.SaveToFile('optimised.pdf');
end;

另請參閱

GetSimilarImageDeduplicationReportJSON, TPDFlibImageSimilarityDedupStats, DeduplicateResources