for(int i=0;i<getnumrows();++i) { for(int j=0;j<getnumcols();++j) { int x = hfilter * threebythree(i,j,getdata()); int y = vfilter * threebythree(i,j,getdata()); //cout<<x<<","<<y<<endl; setvalue(i,j, sqrt(x*x+y*y)); } } writetofile(ofilename); } image image::threebythree(int globali,int globalj,int**data){ image neighbor; neighbor.setnumrows(3); neighbor.setnumcols(3); neighbor.allocatemem(); //this algorithm wrong here, trying figure out one. for(int i=0;i<neighbor.getnumrows();++i) { for(int j=0;j<neighbor.getnumcols();++j)
what doing here trying cut portion out of bigger matrix, in case, getdata() returns, say, 100x100 matrix, want cope 3x3 neighborhood around each pixel bigger matrix newly created one, condition if 3x3 neighborhood goes out of bound in 100x100 matrix, top neighbor of data[0-1][1] out of bound, corresponding position in 3x3 matrix set zero. how can that?
if you're going trouble of building image class, why not use data
?
image image::threebythree(int globali,int globalj, const image &data) { image neighbor; neighbor.setnumrows(3); neighbor.setnumcols(3); neighbor.allocatemem(); for(int i=0 ; i<=3 ; ++i) for(int j=0 ; j<=3 ; ++j) { if(i+globali-1 >=0 && j+globalj-1 >=0 && i+globali-1 < data.getnumrows() && j+globalj-1 < data.getnumcols()) neighbor[i][j] = data[i+globali-1][j+globalj-1]; else neighbor[i][j] = 0; } return(neighbor); }
Comments
Post a Comment