1 year ago

#376469

test-img

Adithya Raj

GIven an Image crop of vehicle how to find the colour of the vehicle with image processing

Giving below a method I have used for getting the dominant colour. I want to know which is that colour. So, do anyone has a better solution than this or any other way to modify it. It would be great if someone helps with some snippets of code.

from PIL import Image


def get_dominant_color(pil_img, palette_size=16):
    # Resize image to speed up processing
    img = pil_img.copy()
    img.thumbnail((100, 100))

    # Reduce colors (uses k-means internally)
    paletted = img.convert('P', palette=Image.ADAPTIVE, colors=palette_size)

    # Find the color that occurs most often
    palette = paletted.getpalette()
    color_counts = sorted(paletted.getcolors(), reverse=True)
    palette_index = color_counts[0][1]
    dominant_color = palette[palette_index*3:palette_index*3+3]

return dominant_color

im = Image.open('sb.png')
result = get_dominant_color(im)
print(result) 

opencv

image-processing

computer-vision

python-imaging-library

image-segmentation

0 Answers

Your Answer

Accepted video resources