2d860d3bb02b904bd8f482be76f253d0e26cafb4,mathics/builtin/image.py,DominantColors,apply,#DominantColors#Any#Any#Any#Any#,1285

Before Change



        flat = numpy.array(list(im.getpalette())) / 255.0  // float values now
        rgb_palette = [flat[i:i + 3] for i in range(0, len(flat), 3)]  // group by 3
        lab_palette = convert_color(rgb_palette, "RGB", "LAB", False)
        palette = [numpy.array(x) for x in lab_palette]

        bins = numpy.bincount(numpy.array(list(im.getdata())), minlength=len(rgb_palette))
        num_pixels = im.size[0] * im.size[1]

        from mathics.algorithm.clusters import agglomerate, PrecomputedDistances, FixedDistanceCriterion

        norm = numpy.linalg.norm

        def df(i, j):
            return norm(palette[i] - palette[j])

        lab_distances = [df(i, j) for i in range(len(lab_palette)) for j in range(i)]

        dominant = agglomerate(
            (rgb_palette, bins),
            (FixedDistanceCriterion, {"merge_limit": py_min_color_distance}),
            PrecomputedDistances(lab_distances),
            mode="dominant")

        result = []

        min_coverage = max(0, int(num_pixels * py_min_color_coverage))
        max_coverage = min(num_pixels, int(num_pixels * py_max_color_coverage))

        for prototype, coverage, members in dominant:
            if len(result) >= at_most:
                break
            if max_coverage >= coverage > min_coverage:
                result.append(Expression("RGBColor", *prototype))

        return Expression("List", *result)


// pixel access

After Change


                if max_coverage >= coverage > min_coverage:
                    yield Expression("RGBColor", *prototype)

        return Expression("List", *itertools.islice(result(), 0, at_most))


// pixel access
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 3

Instances


Project Name: mathics/Mathics
Commit Name: 2d860d3bb02b904bd8f482be76f253d0e26cafb4
Time: 2016-09-15
Author: Bernhard.Liebl@gmx.org
File Name: mathics/builtin/image.py
Class Name: DominantColors
Method Name: apply


Project Name: GoogleCloudPlatform/python-docs-samples
Commit Name: b92890a9f389909a81e6640d527e29a17ae1922f
Time: 2017-08-03
Author: jonwayne@google.com
File Name: speech/cloud-client/transcribe_async.py
Class Name:
Method Name: transcribe_gcs


Project Name: studioml/studio
Commit Name: 13986978d4545aa429a7fc233d8e39718d52e255
Time: 2020-08-11
Author: andrei.denissov@cognizant.com
File Name: studio/keyvalue_provider.py
Class Name: KeyValueProvider
Method Name: checkpoint_experiment