private unsafe void LabelColorPixel(byte* pixel, int labelPointer)
{
if ((tempLabels[labelPointer] == 0) && (
(pixel[RGB.R] > backgroundThresholdR) ||
(pixel[RGB.G] > backgroundThresholdG) ||
(pixel[RGB.B] > backgroundThresholdB)))
{
tempLabels[labelPointer] = ObjectsCount;
LabelColorPixel(pixel + pixelSize, labelPointer + 1); // x + 1, y
LabelColorPixel(pixel + pixelSize + stride, labelPointer + 1 + 2 + ImageWidth); // x + 1, y + 1
LabelColorPixel(pixel + stride, labelPointer + 2 + ImageWidth); // x , y + 1
LabelColorPixel(pixel - pixelSize + stride, labelPointer - 1 + 2 + ImageWidth); // x - 1, y + 1
LabelColorPixel(pixel - pixelSize, labelPointer - 1); // x - 1, y
LabelColorPixel(pixel - pixelSize - stride, labelPointer - 1 - 2 - ImageWidth); // x - 1, y - 1
LabelColorPixel(pixel - stride, labelPointer - 2 - ImageWidth); // x , y - 1
LabelColorPixel(pixel + pixelSize - stride, labelPointer + 1 - 2 - ImageWidth); // x + 1, y - 1
}
}
}