Nppi Label Markers labeling regions same ID

When I run nppiLabelMarkers_16u_C1IR, some regions are labbeled same ID.

///
Npp16u host_src[16 * 16]
{
0, 0, 0, 0, 0, 0, 0, 0,255, 0, 0, 0, 0, 0, 0, 0,
0, 255,255,255, 0, 0,255,255,255, 0, 0, 0, 0, 0, 0, 0,
0, 255,255,255, 0, 0,255,255,255, 0, 0, 0, 0, 0, 0, 0,
0, 255,255,255, 0, 0,255,255,255,255, 0, 0,255, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,255,255,255, 0, 0, 0,255,255,255,
0, 0, 0, 0, 0, 0, 0, 0,255, 0, 0, 0, 0,255,255,255,
0, 0, 0,255, 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255,
0, 255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 255,255,255, 0, 0, 0, 0,255, 0, 0, 0, 0, 0, 0, 0,
0, 255,255,255,255, 0, 0,255,255,255, 0, 0, 0, 0, 0, 0,
0, 0,255,255,255, 0,255,255,255,255,255, 0, 0, 0, 0, 0,
0, 0, 0,255, 0, 0, 0,255,255,255, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,255, 0, 0, 0, 0,255,255,255,
0, 255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255,
0, 255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255,
0, 255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

Npp16u * device_src;
cudaMalloc((void**)&device_src, sizeof(Npp16u) * WIDTH * HEIGHT);
cudaMemcpy(device_src, host_src, sizeof(Npp16u) * WIDTH * HEIGHT, cudaMemcpyHostToDevice);

int buffer_size;
NppiSize source_roi = { WIDTH, HEIGHT };
nppiLabelMarkersGetBufferSize_16u_C1R(source_roi, &buffer_size);

Npp8u * buffer;
cudaMalloc((void**)&buffer, buffer_size);

int max;
nppiLabelMarkers_16u_C1IR(device_src, sizeof(Npp16u) * WIDTH, source_roi, 0, nppiNormInf, &max, buffer);

Npp16u *dst = new Npp16u[WIDTH * HEIGHT];
cudaMemcpy(dst, device_src, sizeof(Npp16u) * WIDTH * HEIGHT, cudaMemcpyDeviceToHost);

for (int i = 0; i < HEIGHT; i++)
{
	for (int j = 0; j < WIDTH; j++)
	{
		printf("%3hd", dst[i * WIDTH + j]);
	}
	printf("\n");
}
printf("%d\n", max);

///

this is my source and result is :

///
0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0
0 1 1 1 0 0 5 5 5 0 0 0 0 0 0 0
0 1 1 1 0 0 5 5 5 0 0 0 0 0 0 0
0 1 1 1 0 0 5 5 5 5 0 0 8 0 0 0
0 0 0 0 0 0 0 5 5 5 0 0 0 8 8 8
0 0 0 0 0 0 0 0 5 0 0 0 0 8 8 8
0 0 0 1 0 0 0 0 0 0 0 0 0 8 8 8
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 5 0 0 0 0 0 0 0
0 1 1 1 1 0 0 5 5 5 0 0 0 0 0 0
0 0 1 1 1 0 5 5 5 5 5 0 0 0 0 0
0 0 0 1 0 0 0 5 5 5 0 0 0 0 0 0
0 0 0 0 0 0 0 0 5 0 0 0 0 9 9 9
0 1 1 1 0 0 0 0 0 0 0 0 0 9 9 9
0 1 1 1 0 0 0 0 0 0 0 0 0 9 9 9
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0

10
///
How can i solve this problem?

Thanks for reporting. At the moment, it appears to be a defect in the npp library. Our development team is taking a look, but I don’t have any further information at this time.

This issue should be fixed in the current CUDA 10.1U1 release (10.1 Update 1, 10.1.168)

Hi,
I tried the nppiLabelMarkers method of CUDA 10.2 in a similar way as kihun12122iu8d did. There are still regions with same IDs in rare cases.
I tested it on 8000x5000px images with some random generated regions. Unfortunately the image is to big to upload here.
I had 83 regions but just 82 labels. All pixels have a value of 0 or 255 except of one region I’ve added with a value of 40. This last region has the same ID (the id was 40,too) as a random other region.
Has the image to be a binary image?
Is there something else I can try?