Results 1 to 10 of 10

Thread: How to implement the equivalence table in connected component labeling c++ Qt

  1. #1

    Default How to implement the equivalence table in connected component labeling c++ Qt

    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 !

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to implement the equivalence table in connected component labeling c++ Qt

    What exactly is the question?

    BTW. Is this some kind of school project?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: How to implement the equivalence table in connected component labeling c++ Qt

    Sorry for not being clear

    My question was : If i was to implement the equivalence table, which is a table containing all sets having a relation with other sets, what qt object should i use ?
    Here is an example :
    The label equivalence relationships generated are,

    Qt Code:
    1. Set ID Equivalent Labels
    2. 1 1,2
    3. 2 1,2
    4. 3 3,4,5,6,7
    5. 4 3,4,5,6,7
    6. 5 3,4,5,6,7
    7. 6 3,4,5,6,7
    8. 7 3,4,5,6,7
    To copy to clipboard, switch view to plain text mode 

    Actually it is a part of a school project, i've made all the previous parts and i'm stuck just with annoying table :P

    Thank your for your help !
    Last edited by wassim24; 13th January 2015 at 16:08.

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to implement the equivalence table in connected component labeling c++ Qt

    You do realize that we have no idea what you are talking about, right? What are these "sets"? Are you looking for a data structure to represent an equivalence relation efficiently?

    Please state the problem you are trying to solve in terms of:
    - the information you receive as input;
    - what you are supposed to output.

    By the way, we have yet to understand what this has to do with Qt.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to implement the equivalence table in connected component labeling c++ Qt

    In wikipedia there is a description of an algorithm you should implement. I don't know what is your input data but I don't think Qt is going to be helpful here that much. Of course you could use Qt types such as QGenericMatrix but I don't see many benefits over other (e.g. pure c++) types.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6

    Default Re: How to implement the equivalence table in connected component labeling c++ Qt

    I'm sorry !
    Yes ! I'm looking for a data structure to represent an equivalence relation efficiently.

    Suppose i have a binary image, this image contains blobs (Connected White regions), i have to label them, but when labeling i have some issues where a same regions gets two labels, at this time i should put the the two different labels in a table, the equivalence table.

    As an output the labeled image but all labels have been replaced by the minimum equivalent labels in the table.

    The problem why i ask my question in the Qt forums is to know if there is a data structure right in Qt that can help me make this table ?

    Thank you in advance and sorry for my bad english !

    Have a good night or a nice day

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to implement the equivalence table in connected component labeling c++ Qt

    For each point you can have a list where you can add and remove labels. You can use QSet for that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to implement the equivalence table in connected component labeling c++ Qt

    You could also use QMap and QList like this:

    Qt Code:
    1. // Assuming your IDs are ints:
    2.  
    3. typedef QMap< int, QList< int > > EquivalenceTable;
    4.  
    5. EquivalenceTable eqTable;
    6.  
    7. eqTable[1] << 1 << 2;
    8.  
    9. QList< int > oneEquivalents = eqTable[1]; // returns a QList containing 1, 2
    10.  
    11. // etc
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to implement the equivalence table in connected component labeling c++ Qt

    If, given a pixel, you want to determine the largest connected monochrome region of the image containing that pixel, then this is just a graph traversal in an undirected graph, and a simple depth-first search suffices. In particular, there is no need to merge several regions.

    If, however, you have a clever way to delimit regions in an image and later want to merge some of them, then this looks to me like the perfect application for a union-find data structure.

    An union-find data structure maintains an equivalence relation on a set. It supports two operations:
    - find(x): returns a canonical representative of x's equivalence class;
    - union(x, y): merge x's and y's equivalence classes.
    In other words, the equivalence relation represented by the union-find is the smallest equivalence relation containing the pair (x, y) for all calls to union(x, y) since the beginning.

    A union-find can be represented efficiently by associating a "last computed representative" to each non-isolated element in the set. A plain C array can do if the set is small, or a QHash if it is larger. union(x, y) makes x's representative be represented by y's representative (or the opposite), but lazily leaves all other representatives untouched. find(x) follows the chains of "last computed representatives" from x until it finds the current representative c, and takes the opportunity to compress the data structure by remapping all the visited elements to c, thus speeding up subsequent lookups.

    You can probably find the details online.

    Again, this is just a shot in the dark as you still haven't explained in details what you are trying to achieve.

  10. #10

    Default Re: How to implement the equivalence table in connected component labeling c++ Qt

    Hi Guys !
    Sorry for my late answer as i've been a bit busy these days.

    Thank you for all your answers !

    @wysota, the problem with this solution is that sometimes you need to insert a label in a particular "position", for exemple list[label] = equiValentLabel, which can generate some errors.
    @d_stranz i will try your solution as soon as possible and keep you in touch, it seems that it may work very well !

    @yeye_olive, this is exactly what i'm trying to do, a union-find.

    Thank you very much guys !

Similar Threads

  1. Replies: 3
    Last Post: 9th September 2013, 01:52
  2. Replies: 1
    Last Post: 10th May 2011, 18:58
  3. Replies: 0
    Last Post: 4th May 2011, 12:33
  4. Best way to implement a table in a QGraphicsScene?
    By roband915 in forum Qt Programming
    Replies: 3
    Last Post: 31st March 2011, 11:56
  5. Replies: 4
    Last Post: 26th October 2009, 22:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.