 
                 if (img[img_index + img.stepy / img.elem_size]) {
                     P |= (P0 << 4);
+                    foreground |= (1 << 2);
                 }
 
             }


        d_img_labels_.create(d_img_.x, d_img_.y, d_img_.z, CV_32SC1);

        grid_size_ = dim3((d_img_.x + BLOCK_X - 1) / BLOCK_X, (d_img_.y + BLOCK_Y - 1) / BLOCK_Y, (d_img_.z + BLOCK_Z - 1) / BLOCK_Z);
        block_size_ = dim3(BLOCK_X, BLOCK_Y, BLOCK_Z);

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


                    if (img[img_index + img.stepz / img.elem_size + img.stepy / img.elem_size]) {
                        P |= (P0 << 20);
                        foreground |= (1 << 6);
                    }

                }
            }
        }*/

#undef P0

            // Store foreground voxels bitmask into memory
            if (x + 1 < labels.x) {
                labels[labels_index + 1] = foreground;
            }
            else if (y + 1 < labels.y) {
                labels[labels_index + labels.stepy / labels.elem_size] = foreground;
            }
            else if (z + 1 < labels.z) {
                labels[labels_index + labels.stepz / labels.elem_size] = foreground;
            }
            else {
                *last_cube_fg = foreground;
            }


            // checks on borders

