I think you should modify existing terms instead of recreating them, thereby not requiring to add new rule blocks every time. In
fuzzyRGBTest, go over all the terms, modify their parameters, and keep going. In addition, you add the rule block in
initCodebook and not in
fuzzyRGBTest. This should significantly increase performance.
Furthermore, you could create multiple engines, divide your frame into regions, and assign each region an engine. Each engine would run in a separate thread, thereby utilising multiple cores in parallel, which would vastly increase the performance.