image processing - Implement Sobel Filter in Java - Normalize values -


i want implement sobel filter myself (actual no beautiful implementation). after doing convolution have no idea how calculate rgb values.

  • assumption: grey scaled image

    double [][] sobel_x =  {     { -1, 0, 1},     { -2, 0, 2},     { -1, 0, 1} };  double [][]    sobel_y =  {     { 1, 2, 1},     { 0, 0, 0},     {-1, -2, 1} };  for(int y=1; y<image.getheight()-1; y++) {     for(int x=1; x<image.getwidth()-1; x++)     {        color = new color(image.getrgb(x-1, y-1));        color b = new color(image.getrgb(x, y-1));        color c = new color(image.getrgb(x+1, y-1));        color d = new color(image.getrgb(x-1, y));        color e = new color(image.getrgb(x, y));        color f = new color(image.getrgb(x+1, y));        color g = new color(image.getrgb(x-1, y+1));        color h = new color(image.getrgb(x, y+1));        color = new color(image.getrgb(x+1, y+1));          double pixel_x =    (sobel_x[0][0] * a.getred()) + (sobel_x[0][1] * b.getred()) + (sobel_x[0][2] * c.getred()) +                             (sobel_x[1][0] * d.getred())   + (sobel_x[1][1] * e.getred())   + (sobel_x[1][2] * f.getred()) +                             (sobel_x[2][0] * g.getred()) + (sobel_x[2][1] * h.getred()) + (sobel_x[2][2] * i.getred());         double pixel_y =                              (sobel_y[0][0] * a.getred()) + (sobel_x[0][1] * b.getred()) + (sobel_x[0][2] * c.getred()) +                             (sobel_y[1][0] * d.getred())   + (sobel_x[1][1] * e.getred())   + (sobel_x[1][2] * f.getred()) +                             (sobel_y[2][0] * g.getred()) + (sobel_x[2][1] * h.getred()) + (sobel_x[2][2] * i.getred());            //here possible values between [-1020, 1020]                 //how going on          //int rgb = (int) math.sqrt(pixel_x*pixel_x+pixel_y*pixel_y);          //int rgbasint = (int)(65536 * rgb + 256 * rgb + rgb);           } }    

one of ideas linear transformation. example, minimum pixel value in image got -998 , maximum 1000. can correspond -998 0 , 1000 255, relationship between scale of (-998,1000) scale of (0,255) , normalize values between [-998,1000] [0,255].


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -