 
 		if (row < labels.rows && col < labels.cols) {
 
-			unsigned int label = labels[labels_index];
-
-			if (label) {
-
-				if (img.data[img_index]) {
-					// labels[labels_index] = label;
-				}
+			unsigned int label = labels[labels_index] + 1;
+
+			if (img.data[img_index])
+				labels[labels_index] = label;
+			else {
+				labels[labels_index] = 0;
+			}
+
+			if (col + 1 < labels.cols) {
+				if (img.data[img_index + 1])
+					labels[labels_index + 1] = label;
 				else {
-					labels[labels_index] = 0;
-				}
-
-				if (col + 1 < labels.cols) {
-					if (img.data[img_index + 1])
-						labels[labels_index + 1] = label;
+					labels[labels_index + 1] = 0;
+				}
+
+				if (row + 1 < labels.rows) {
+					if (img.data[img_index + img.step + 1])
+						labels[labels_index + (labels.step / labels.elem_size) + 1] = label;
 					else {
-						labels[labels_index + 1] = 0;
-					}
-
-					if (row + 1 < labels.rows) {
-						if (img.data[img_index + img.step + 1])
-							labels[labels_index + (labels.step / labels.elem_size) + 1] = label;
-						else {
-							labels[labels_index + (labels.step / labels.elem_size) + 1] = 0;
-						}
-					}
-				}
-
-				if (row + 1 < labels.rows) {
-					if (img.data[img_index + img.step])
-						labels[labels_index + (labels.step / labels.elem_size)] = label;
-					else {
-						labels[labels_index + (labels.step / labels.elem_size)] = 0;
-					}
-				}
-			}
-			else {
-				labels[labels_index + 1] = 0;
-
-				if (col + 1 < labels.cols) {
-					labels[labels_index + 1] = 0;				
-
-					if (row + 1 < labels.rows) {
 						labels[labels_index + (labels.step / labels.elem_size) + 1] = 0;
 					}
 				}
-
-				if (row + 1 < labels.rows) {
+			}
+
+			if (row + 1 < labels.rows) {
+				if (img.data[img_index + img.step])
+					labels[labels_index + (labels.step / labels.elem_size)] = label;
+				else {
 					labels[labels_index + (labels.step / labels.elem_size)] = 0;
 				}
-
 			}
 
 		}

		//d_expanded_connections.download(expanded_connections);
		//d_expanded_connections.release();


		Merge << <grid_size_, block_size_ >> > (d_img_, d_img_labels_);

		//Mat1i block_info_final;
		//d_img_labels_.download(block_info_final);		

		Compression << <grid_size_, block_size_ >> > (d_img_labels_);

		FinalLabeling << <grid_size_, block_size_ >> > (d_img_, d_img_labels_);

		//d_img_labels_.download(img_labels_);
		cudaDeviceSynchronize();
	}


		grid_size_ = dim3((((d_img_.cols + 1) / 2) + BLOCK_COLS - 1) / BLOCK_COLS, (((d_img_.rows + 1) / 2) + BLOCK_ROWS - 1) / BLOCK_ROWS, 1);
		block_size_ = dim3(BLOCK_COLS, BLOCK_ROWS, 1);

		InitLabeling << <grid_size_, block_size_ >> > (d_img_, d_img_labels_, last_pixel_);

		Compression << <grid_size_, block_size_ >> > (d_img_labels_);

