The purpose of the program is to take a position and count how many "pixels" are in the "blob". If there is no "pixel" aka the value is 0, the blob number is 0. If there is a pixel, the blob_check function recursively checks the surrounding cells for "pixels" aka values of 1. My program compiles but doesn't accurately count the number of pixels in the blob. Please help!

#include <stdlib.h>
#include <stdio.h>

int blob_check(int tab[][], int x, int y);

#define N 5

int main(int argc, char *argv[])
{
	int x,y,i,j;
	int row=0;
	char line[80];
	int table[N][N] = { {1,1,0,0,0},
						{0,1,1,0,0},
						{0,0,1,0,1},
						{1,0,0,0,1},
						{0,1,0,1,1}};
				
	printf("\t0\t1\t2\t3\t4\t");
	printf("\n   -----------------------------------------");			
	for(i=0;i<5;i++)
	{
		printf("\n   |\n%d  |\t", i);
		for(j=0;j<5;j++)
		{
			printf("%d\t", table[i][j]);
		}
	}
								
								
	printf("\n\nEnter x-y coordinates of cell  => ");
	scanf("%d %d", &x, &y);								
	
	printf("Pixel quantity in blob: %i\n", blob_check(table, x, y));
	
	system("pause");
	return 0;
}

int blob_check(int pic[N][N], int x, int y)
{
	if (pic[x][y] == 0)
		return 0;
	else
	{
		pic[x][y] = 0;
		
		int sum = 1;
		
		//check 
		if (x>0)
		{
			sum += blob_check(pic, x-1, y);
			if (y<N-1)
				sum += blob_check(pic, x-1, y+1);
		}
		else if (y<N-1)
		{
			sum += blob_check(pic, x, y+1);
			if (x<N-1)
				sum += blob_check(pic, x+1, y+1);
		}
		else if (x<N-1)
		{
			sum += blob_check(pic, x+1, y);
			if (y>0)
				sum += blob_check(pic, x+1, y-1);
		}		
		else if (y>0)
		{
			sum += blob_check(pic, x, y-1);
			if (x>0)
				sum += blob_check(pic, x-1, y-1);
		}

		return sum;
	}
}
This article has been dead for over six months. Start a new discussion instead.