Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009 #include "osl_canny_gradient.h"
00010 #include <vcl_cmath.h>
00011
00012
00013
00014
00015
00016
00017
00018
00019 void osl_canny_gradient(int xsize_, int ysize_,
00020 float const * const * smooth_,
00021 float * const * dx_,
00022 float * const * dy_,
00023 float * const * grad_)
00024 {
00025
00026 dy_[0][0]=(smooth_[0][0]-smooth_[0][1])*2;
00027 dx_[0][0]=(smooth_[1][0]-smooth_[0][0])*2;
00028 for (int x=1; x<xsize_-1; ++x) {
00029 dy_[x][0]=(smooth_[x ][0]-smooth_[x ][1])*2;
00030 dx_[x][0]= smooth_[x+1][0]-smooth_[x-1][0];
00031 }
00032 dy_[xsize_-1][0]=(smooth_[xsize_-1][0]-smooth_[xsize_-1][1])*2;
00033 dx_[xsize_-1][0]=(smooth_[xsize_-1][0]-smooth_[xsize_-2][0])*2;
00034
00035
00036
00037 for (int y=1; y<ysize_-1; ++y) {
00038 dy_[0][y]= smooth_[0][y-1]-smooth_[0][y+1];
00039 dx_[0][y]=(smooth_[1][y ]-smooth_[0][y ])*2;
00040 for (int x=1; x<xsize_-1; ++x) {
00041 dy_[x][y]=smooth_[x ][y-1]-smooth_[x ][y+1];
00042 dx_[x][y]=smooth_[x+1][y ]-smooth_[x-1][y ];
00043 }
00044 dy_[xsize_-1][y]= smooth_[xsize_-1][y-1]-smooth_[xsize_-1][y+1];
00045 dx_[xsize_-1][y]=(smooth_[xsize_-1][y ]-smooth_[xsize_-2][y ])*2;
00046 }
00047
00048
00049
00050 dy_[0][ysize_-1]=(smooth_[0][ysize_-2]-smooth_[0][ysize_-1])*2;
00051 dx_[0][ysize_-1]=(smooth_[1][ysize_-1]-smooth_[0][ysize_-1])*2;
00052 for (int x=1; x<xsize_-1; ++x) {
00053 dy_[x][ysize_-1]=(smooth_[x ][ysize_-2]-smooth_[x ][ysize_-1])*2;
00054 dx_[x][ysize_-1]= smooth_[x+1][ysize_-1]-smooth_[x-1][ysize_-1];
00055 }
00056 dy_[xsize_-1][ysize_-1]=(smooth_[xsize_-1][ysize_-2]-smooth_[xsize_-1][ysize_-1])*2;
00057 dx_[xsize_-1][ysize_-1]=(smooth_[xsize_-1][ysize_-1]-smooth_[xsize_-2][ysize_-1])*2;
00058
00059
00060
00061 for (int y=0; y<ysize_; ++y)
00062 for (int x=0; x<xsize_; ++x)
00063 grad_[x][y] = (float)vcl_sqrt(dx_[x][y]*dx_[x][y] + dy_[x][y]*dy_[x][y]);
00064 }
00065
00066
00067 void osl_canny_gradient_central(int xsize_, int ysize_,
00068 float const * const * smooth_,
00069 float * const * dx_,
00070 float * const * dy_,
00071 float * const * grad_)
00072 {
00073 for (int x=1; x<xsize_-1; ++x) {
00074 for (int y=1; y<ysize_-1; ++y) {
00075 dx_[x][y] = smooth_[x+1][y] - smooth_[x-1][y];
00076 dy_[x][y] = smooth_[x][y+1] - smooth_[x][y-1];
00077 grad_[x][y] = (float)vcl_sqrt(dx_[x][y]*dx_[x][y] + dy_[x][y]*dy_[x][y]);
00078 }
00079 }
00080 }