I'm trying to implement the Connected Components Labeling in C++ with Qt but i'm struggling in implementing the equivalence table and having some problems to understand how to work with it.
Here is what i've done so far :

Qt Code:
  1. for (int x = 0; x < image.width(); ++x) {
  2. for (int y = 0; y < image.height(); ++y) {
  3.  
  4. color = image.pixel(x,y);
  5.  
  6. if(color.red() == 0)
  7. imageLabeled.setPixel(x,y, qRgb(0,0,0));
  8.  
  9. else{
  10. color1 = imageLabeled.pixel(x, y-1);
  11. color2 = imageLabeled.pixel(x-1, y);
  12.  
  13. if(color1.red() == 0 && color2.red() == 0)
  14. {
  15. imageLabeled.setPixel(x,y, qRgb(label, label, label));
  16. label+=1;
  17.  
  18. }else if(color1.red() == 0 && color2.red() != 0)
  19. imageLabeled.setPixel(x,y,color2.rgb());
  20.  
  21.  
  22. else if(color1.red() != 0 && color2.red() == 0)
  23. imageLabeled.setPixel(x,y, color1.rgb());
  24.  
  25. else if(color1.red() != 0 && color2.red() != 0)
  26. {
  27. if(color1.red() < color2.red())
  28. imageLabeled.setPixel(x,y, color1.rgb());
  29. else
  30. imageLabeled.setPixel(x,y, color2.rgb());
  31. }
  32.  
  33. }
  34.  
  35. }
  36. }
To copy to clipboard, switch view to plain text mode 

In this block of instructions i'm just searching for pixels to be labeled. There is no equivalence table or so.

Thanks you for your help !
Cheers !