0

I have a image that I've logically separated into a 100 by 100 grid. In each cell of the grid, I want to find the most commonly occurring color. My current algorithm uses a hash map to calculate the mode in linear time, but processing the whole image still takes a ridiculous amount of time!

I'm working on a little game that is grid based, and I wanted to allow the players to import an image to color the grid after.

Is there a better algorithm out there that I should know about?

  • 1
    Without seeing your algorithm, it may be hard to comment. Since you need to look at every square, linear is probably as good as you can get. My guess is there are other optimizations that could take down the coefficient on the linear algorithm. – Stephen C Nov 01 '18 at 03:06
  • Look at [this question](https://stackoverflow.com/questions/582336/how-can-you-profile-a-script) on how to profile a script. This will help identify where the bottlenecks are and you can ask more specific questions on how to reduce those. A [mcve] will help people identify problems in your code. – import random Nov 01 '18 at 03:10
  • Thanks so much! I actually profiled my functions and found that my bottleneck had nothing to do with my algorithm in itself. My program is running much faster now :) – Dustin Nguyen Nov 01 '18 at 03:33

0 Answers0