#include #include char** imageMatrix; char blankPixel,imagePixel; typedef struct{ int row,col; }pixel; int getBlackNeighbours(int row,int col){ int i,j,sum = 0; for(i=-1;i<=1;i++){ for(j=-1;j<=1;j++){ if(i!=0 || j!=0) sum+= (imageMatrix[row+i][col+j]==imagePixel); } } return sum; } int getBWTransitions(int row,int col){ return ((imageMatrix[row-1][col]==blankPixel && imageMatrix[row-1][col+1]==imagePixel) +(imageMatrix[row-1][col+1]==blankPixel && imageMatrix[row][col+1]==imagePixel) +(imageMatrix[row][col+1]==blankPixel && imageMatrix[row+1][col+1]==imagePixel) +(imageMatrix[row+1][col+1]==blankPixel && imageMatrix[row+1][col]==imagePixel) +(imageMatrix[row+1][col]==blankPixel && imageMatrix[row+1][col-1]==imagePixel) +(imageMatrix[row+1][col-1]==blankPixel && imageMatrix[row][col-1]==imagePixel) +(imageMatrix[row][col-1]==blankPixel && imageMatrix[row-1][col-1]==imagePixel) +(imageMatrix[row-1][col-1]==blankPixel && imageMatrix[row-1][col]==imagePixel)); } int zhangSuenTest1(int row,int col){ int neighbours = getBlackNeighbours(row,col); return ((neighbours>=2 && neighbours<=6) && (getBWTransitions(row,col)==1) && (imageMatrix[row-1][col]==blankPixel||imageMatrix[row][col+1]==blankPixel||imageMatrix[row+1][col]==blankPixel) && (imageMatrix[row][col+1]==blankPixel||imageMatrix[row+1][col]==blankPixel||imageMatrix[row][col-1]==blankPixel)); } int zhangSuenTest2(int row,int col){ int neighbours = getBlackNeighbours(row,col); return ((neighbours>=2 && neighbours<=6) && (getBWTransitions(row,col)==1) && (imageMatrix[row-1][col]==blankPixel||imageMatrix[row][col+1]==blankPixel||imageMatrix[row][col-1]==blankPixel) && (imageMatrix[row-1][col]==blankPixel||imageMatrix[row+1][col]==blankPixel||imageMatrix[row][col+1]==blankPixel)); } void zhangSuen(char* inputFile, char* outputFile){ int startRow = 1,startCol = 1,endRow,endCol,i,j,count,rows,cols,processed; pixel* markers; FILE* inputP = fopen(inputFile,"r"); fscanf(inputP,"%d%d",&rows,&cols); fscanf(inputP,"%d%d",&blankPixel,&imagePixel); blankPixel<=9?blankPixel+='0':blankPixel; imagePixel<=9?imagePixel+='0':imagePixel; printf("\nPrinting original image :\n"); imageMatrix = (char**)malloc(rows*sizeof(char*)); for(i=0;i0); for(i=0;i0); for(i=0;i