home Forums # Technical Support Fuzzy system for image segmentation slow Reply To: Fuzzy system for image segmentation slow



you have a number of problems in your code.

(1) The Centroid defuzzifier is computationally expensive. You may want to decrease its resolution by passing another parameter to the configure(..., "Centroid", 100) method, where 100 is the number integration points. The smaller the resolution, the faster the algorithm is, but its accuracy decreases. The larger the resolution, the slower the algorithm is, but its accuracy increases. By default, the resolution is set to 200 (revise IntegralDefuzzifier.[h|cpp]).

(2) You are executing the method fuzzyRGBTest $i\times j\times k$, and there are several problems in this method.
(2.1) deltaIntensityVar->removeTerm(i); will remove the term from the vector, but will not delete it, therefore you are leaking memory, not to mention that you need to remove terms using for i=n-1 to 0 and not for i = 0 to n. You could do delete deltaIntensityVar->removeTerm(i);, but you will likely cause a segmentation fault because you are not deleting the rule blocks correctly, and these will have pointers to the terms you delete.
(2.2) fuzzyEngineRGB->addRuleBlock(ruleblockRGB); you continue to add rule blocks and rules to the engine, yet I cannot see where you remove *and delete* other rule blocks.
(2.3) By not removing rule blocks, the engine needs to process every rule block added upon process(), which seems to me is what is causing the slow response.

You need to rethink your implementation. You should consider designing multiple fuzzy engines outside the $i,j,k$ for-loop and choose the right engine within the for-loop without changing its configuration. Even better would be to design a single fuzzy engine that takes into account the variable intervalBrightness, and create rules that modify your current rules only once, but I am not sure if this is possible given that I am not familiar with what you are trying to achieve.

Hope this helps somehow.