MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / color_topusage

Method color_topusage

src/__init__.py:13585–13598  ·  view source on GitHub ↗

Return most frequent color and its usage ratio.

(self, clip=None)

Source from the content-addressed store, hash-verified

13583 return rc
13584
13585 def color_topusage(self, clip=None):
13586 """Return most frequent color and its usage ratio."""
13587 allpixels = 0
13588 cnt = 0
13589 if clip is not None and self.irect in Rect(clip):
13590 clip = self.irect
13591 for pixel, count in self.color_count(colors=True,clip=clip).items():
13592 allpixels += count
13593 if count > cnt:
13594 cnt = count
13595 maxpixel = pixel
13596 if not allpixels:
13597 return (1, bytes([255] * self.n))
13598 return (cnt / allpixels, maxpixel)
13599
13600 @property
13601 def colorspace(self):

Callers 4

top_row_bg_colorMethod · 0.80
test_3848Function · 0.80
test_3994Function · 0.80
test_4254Function · 0.80

Calls 2

color_countMethod · 0.95
RectClass · 0.85

Tested by 3

test_3848Function · 0.64
test_3994Function · 0.64
test_4254Function · 0.64