/*----------------------------------------------------------------------------*/ void image_pan(my1Image *image, my1Image *result, int shx, int shy, int vin) { int iloop, jloop; int calcx, calcy, calcv; int row = image->height, col = image->width; /* calculate new pixel index */ for(iloop=0;iloop<row;iloop++) { for(jloop=0;jloop<col;jloop++) { calcx = jloop - shx; calcy = iloop - shy; if(calcx>=0&&calcx<col&&calcy>=0&&calcy<row) { calcv = imagepixel(image,calcy,calcx); setimagepixel(result,iloop,jloop,calcv); } else { setimagepixel(result,iloop,jloop,vin); } } } }
/*----------------------------------------------------------------------------*/ int sobel_image(my1Image *src, my1Image *dst_mag, my1Image *dst_ang) { my1Image buff1, buff2; int irow, icol, x, y, temp; // create temporary buffer if(!createimage(&buff1,src->height,src->width)) { //printf("Cannot allocate buff1 memory\n"); return -1; } if(!createimage(&buff2,src->height,src->width)) { freeimage(&buff1); //printf("Cannot allocate buff2 memory\n"); return -1; } // calculate directional edge sobel_x_image(src, &buff1); sobel_y_image(src, &buff2); // calculate angle for 3x3 neighbourhood for(irow=0;irow<src->height;irow++) { for(icol=0;icol<src->width;icol++) { x = imagepixel(&buff1,irow,icol); y = imagepixel(&buff2,irow,icol); setimagepixel(dst_mag,irow,icol,iabs(y)+iabs(x)); if(!dst_ang) continue; if(x>0) { if(y>0) { // q1 y = iabs(y); x = iabs(x); if(y>2*x) temp = 90; else if(x>2*y) temp = 0; else temp = 45; } else if(y<0) { // q4 y = iabs(y); x = iabs(x); if(y>2*x) temp = 270; else if(x>2*y) temp = 0; else temp = 315; } else { temp = 0; // +ve x-axis } } else if(x<0) { if(y>0) { // q2 y = iabs(y); x = iabs(x); if(y>2*x) temp = 90; else if(x>2*y) temp = 180; else temp = 135; } else if(y<0) { // q3 y = iabs(y); x = iabs(x); if(y>2*x) temp = 270; else if(x>2*y) temp = 180; else temp = 225; } else { temp = 180; // -ve x-axis } } else { if(y>0) { temp = 90; // +ve y-axis } else if(y<0) { temp = 270; // -ve y-axis } else { temp = 0; // origin! no edge? } } setimagepixel(dst_ang,irow,icol,temp); } } /* clean-up */ freeimage(&buff1); freeimage(&buff2); return 0; }