Connected Component Labeling - Equivalence Table I am trying to write a connected component labelling program, I have done the first part to create a label based on the neighbours. For simplicity I am using a 4-connectivity. I am using ANSI C and to create the equivalence table I am using two linked lists with structures defined like this:

struct T2_node
{
    size_t value;    
    struct T2_node *next;
};

struct T1_node
{
     struct T2_node *T2;    
     struct T1_node *next;
};


Every newly found object has a T1_node which links to a T2_node linked list that keeps the labels of the objects that particular label is connected to. As an example you can see this thresholded image (very noisy!) I am trying to find the connected components of:



A section of the equivalence table for this image is:

label id: connected labels (including its self).

835: 847, 835, 
834: 846, 834, 
833: 820, 833, 
832: 812, 832, 
831: 831, 
830: 830, 
829: 818, 829, 
828: 828, 
827: 929, 778, 840, 783, 827, 
826: 826, 
825: 825, 
824: 993, 944, 904, 916, 839, 824, 
823: 823, 
822: 957, 794, 837, 822, 
821: 956, 912, 888, 848, 821, 
820: 1021, 997, 915, 924, 887, 812, 833, 820, 
819: 819, 
818: 829, 818, 
817: 817, 
816: 816, 


A grey scale image of the labels of the same image can be seen below:



As you see, the labelled regions within a connected component do not all touch! 

My final question is: What algorithm should I use to effectively merge the labels? In other words, how can I find which labels belong to one connected object? I am a graduate student in Astronomy, so I do not know the details of graph theory and set theory or how to implement them in a computer program, take C for example! (although I am interested to learn). So if there is a specific method to do this, please also introduce a reference I can learn that method from, thanks in advance.
As I've said in my comment to question, you can use function pixConnComp from leptonica library. Another variant is to use one of a common known algorithm for connected components labeling. For example you can use my realisation (from line 385) of conncomp labeling algorithm.

Most algorithms use two or three passes over image. My version have three passes:


Mark neighbours in each line: you just assign labels to each connected set of pixels line by line (labels are saving in matrix with image size).
Fill associative array with remarking: we assign a new labels to labels that we've get at step 1. For this operation we check neighbours of non-zero labels on image and assign to it a smallest value.
Rename markers due to associative array. 


We can combine steps 2 and 3, but in that case algorithm would be more difficult.