Component labelling

This may not be the right platform to ask such questions, but I am stuck on this for a day or two and I think only some experienced coders can help me in this.
I have .bmp image(image has been change to .png) and binary array where the image is marked as 0 and digits as 1.


Here is the code,— https://ide.geeksforgeeks.org/2s1gpCwuEc
I cannot figure out where it is incorrect. Can anyone help please.

I’ve written an image evalution program before, by reading a bmp, can you tell me what’s wrong with you r code?

Can you please provide the link of your program?

It was wirtten during my internship at the company last year. You know, for security reasons, I don’t have a copy of it, but I use some library fuctions of window.h to help me do this.

Can you please look through my code I have provided. The array just prints 0 and 2 whereas it should print 0,2,3,4,5.

I don’t quite understand the meaning of array, and I can’t find the possibility of 3, 4, 5 in your code.

I have converted the .bmp image into a 2d binary array and marked the background as 0 and digits as 1. Now for a given pixel in the 2d array, I am incrementing the counter if it contains “1” by recursively calling the function. Now after it marks digit “9” as “2”, it moves on to"4" where it marks it “3”, and so on. So the 2d array should contain 2,3,4,5. Thats what my code does.

So your program is used to calculate the number of connected blocks, but your DFS is wrong, I think your mistake is here:
image
there should be array[i][j] = ++c; and your c should be initialized to 1.

2 Likes

Thank you for this. But this did not work. Any other fault in the code?

Make sure that the binary image you decode is correct, because it’s a gray image.

1 Like

Thank you. I tried scanning the eight neighbours and it worked.

Aha, I didn’t notice that, sorry:thinking:

1 Like