السلام عليكم
الكود أسفله يقوم بالعمل بطريقة جيدة، وجدته في الإنترنت و استأذنت مالكه في استخدامه فأذن لي، طلبت منه أن يشرحه لي فقال أن أستاذه هو من كتبه . الكود يقوم باخراج image skeleton باستخدام Hilditch's algorithm . هذا هو الكود:
/* 3x3 neighborhood, 8 connection, C.J.Hilditch's algorithm */
public ImgArray[][] Thinning(int w,int h,ImgArray img[][]){
int i,ix,iy,m,ir,iv,iw;
int ia[] = new int[9];
int ic[] = new int[9];
ImgArray thi[][] = new ImgArray[h][w];
for(iy=0;iy<h;iy++)
for(ix=0;ix<w;ix++){
thi[iy][ix]= new ImgArray();
thi[iy][ix].gray = img[iy][ix].gray;
}
m=100; ir=1;
while(ir!=0){
ir=0;
for(iy=1;iy<h-1;iy++){
for(ix=1;ix<w-1;ix++){
if(thi[iy][ix].gray!=(GRAYLEVEL-1))continue;
ia[0]=thi[iy ][ix+1].gray;
ia[1]=thi[iy-1][ix+1].gray;
ia[2]=thi[iy-1][ix ].gray;
ia[3]=thi[iy-1][ix-1].gray;
ia[4]=thi[iy ][ix-1].gray;
ia[5]=thi[iy+1][ix-1].gray;
ia[6]=thi[iy+1][ix ].gray;
ia[7]=thi[iy+1][ix+1].gray;
for(i=0;i<8;i++){
if(ia==m){
ia=(GRAYLEVEL-1);ic = 0;
}
else{
if(ia<(GRAYLEVEL-1))ia=0;
ic=ia;
}
}
ia[8]=ia[0]; ic[8]=ic[0];
if(ia[0]+ia[2]+ia[4]+ia[6]==(GRAYLEVEL-1)*4) continue;
for(i=0,iv=0,iw=0;i<8;i++){
if(ia==(GRAYLEVEL-1)) iv++;
if(ic==(GRAYLEVEL-1)) iw++;
}
if(iv<=1)continue;
if(iw==0)continue;
if(cconc(ia)!=1) continue;
if(thi[iy-1][ix].gray==m){
ia[2]=0;
if(cconc(ia)!=1) continue;
ia[2]=(GRAYLEVEL-1);
}
if(thi[iy][ix-1].gray==m){
ia[4]=0;
if(cconc(ia)!=1) continue;
ia[4]=(GRAYLEVEL-1);
}
thi[iy][ix].gray=m; ir++;
}
}
m++;
}
for(iy=0;iy<h;iy++)
for(ix=0;ix<w;ix++)
if(thi[iy][ix].gray<(GRAYLEVEL-1))thi[iy][ix].gray=0;
return thi;
}
/* 8 connected connectivity */
private int cconc(int inb[])
{
int icn,i;
int indum[] = new int[9];
for(i=0;i<9;i++)
if(inb==(GRAYLEVEL-1)){
indum = 0;
}else{
indum = 1;
}