INNER CODE UNIT · Python

indices1

KennethJAllen/proper-pixel-art · proper_pixel_art/colors.py:216

    indices1 = bins1[:, 0] * num_bins**2 + bins1[:, 1] * num_bins + bins1[:, 2]
    counts1 = np.bincount(indices1, minlength=num_bins**3)
    dominant1 = np.argmax(counts1)
    max_count1 = counts1[dominant1]

    # Grid 2: offset binning (grid 1 shifted by half a bin)
    # Widen before adding so bright values don't wrap around in uint8, then clamp
    offset = bin_size // 2
    bins2 = np.minimum(rgb_pixels.astype(np.int64) + offset, 255) // bin_size
    indices2 = bins2[:, 0] * num_bins**2 + bins2[:, 1] * num_bins + bins2[:, 2]
    counts2 = np.bincount(indices2, minlength=num_bins**3)
    dominant2 = np.argmax(counts2)
    max_count2 = counts2[dominant2]

    # Use the grid with the larger dominant cluster
    mask = indices1 == dominant1 if max_count1 >= max_count2 else indices2 == dominant2

    dominant_pixels = rgb_pixels[mask]

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…