#include #include #define BLACK '1' #define WHITE '0' char **img_alloc(int, int); void img_free(char **,int, int); char **img_read(int *, int *); void img_write(char **, int, int); char** img_dilate(char **pbm, int x, int y); char** img_erode(char **pbm, int x, int y); int main(){ char **pbm1, **pbm2; int ix,iy; pbm1 = img_read(&ix,&iy); if(pbm1==NULL){ fprintf(stderr,"Invalid image format"); exit(1); } #ifdef ERODE pbm2=img_erode(pbm1,ix,iy); img_free(pbm1,ix,iy); #elif DILATE pbm2=img_dilate(pbm1,ix,iy); img_free(pbm1,ix,iy); #else pbm2=pbm1; #endif /* 画像を書きだす */ img_write(pbm2,ix,iy); /* 画像領域の解放 */ img_free(pbm2,ix,iy); return 0; } char** img_dilate(char **pbm, int x, int y){ int i, j; char pu, pd, pl, pr; /* up, down, left, right */ char **dst; if((dst=img_alloc(x,y))==NULL){ return NULL; } for(i=0; i