0

What i have is 2 images, the goal is to redraw the second image but only use the colors from the first image.

I have a solution for this already but currently its too slow (you can test it here http://167.99.243.66/).

Essentialy it takes all the colours from image1 and then goes pixel by pixel to redraw the second image, here it then searches the for closest color in the colors from image1.

What kills the speed is the fact that for each pixel i need to loop through the whole palette of image1 to find the nearest color (calculating the nearest 2 points in a 3d vector space).

What can i do here to speed this up?

Vajura
  • 133
  • 1
    There might be another StackExchange site where this would fit better. This is really a question about programming - you could probably speed it up both through language features (e.g. using shaders or otherwise invoking the GPU) and through algorithms (e.g. using spatial data structures like octrees) - you can look up "nearest neighbor search" for the latter. (You also might secretly want approximate solutions, and a manifold learning technique might be appropriate if the color palette is large or represents a continuous structure) – Milo Brandt May 17 '18 at 21:15
  • 1
    Octree is standard way to find closest color efficiently. – Somnium May 17 '18 at 21:51
  • 1
    Nearest neighbor search and BSP tree will be a good search key for this sort of stuff. In the old days when true color monitor isn't that common, people are using BSP tree (or Octree) for color quantization, build a palette and then remap colors to that palette. There are also C code floating around. dsp.SE is probably a better place for image processing related questions. – achille hui May 17 '18 at 21:59
  • See this answer over at Stack Overflow. – Cris Luengo May 24 '18 at 02:13

0 Answers0