https://www.youtube.com/watch?v=DogZJmThRSE
That's a high-speed computer-vision optical pea sorter. Yes, each and every pea in that huge flow of peas is examined by a computer vision system. Tiny high-speed air jets are kicking out the rejects during the brief period the peas are in free flight.
Here's a blueberry sorting machine, throwing out anything that doesn't look like a round blue blueberry:
https://www.youtube.com/watch?v=8CyWvnh4YtE
That machine could sort M&Ms by color, easily.
The food industry has lots of machines like that. The technology was first applied to large fruit like tomatoes. It's now so cheap it's applied to rice and grains.