Usenet.com

www.Usenet.com

Group Index

Sci Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Smoothing?



Thanks for the great help provided by this group and in particular
Roger Rowland.

I've nearly got all functionality i require for my image processing
package and i thought that by manipulating an edge detection function
that had been provided i would easily be able to apply other templates
such as smoothing and blurring. however i'm not getting the desired
results cou;ld some one please have a look over this code?

int Smooth()
{
 double Result;
 int i, j, x, y, Value;
 int Sum, NeighX, NeighY;


 int smooth[][3] = {{1, 3, 1}, {3, 16, 3}, {1, 3, 1}};
 

 // allocate working array
 double* pWork = new double [my_image.width * my_image.length];

 // apply over whole image
 for (y = 0; y < my_image.length; y++)
 {
  for (x = 0; x < my_image.width; x++)
  {
   // apply filter at this xy
   Sum = 0; 
   for (i = -1; i <= 1; i++)
   {
    for (j = -1; j <= 1; j++)
    {
     // get neighbour
     NeighX = x + i;
     NeighY = y + j;

     // "extend" image at extremeties
     if (NeighX < 0) 
         {
                 NeighX = 0;
         }
     if (NeighX >= my_image.width)
         {
                 NeighX = my_image.width - 1;
         }
     if (NeighY < 0)
         {
                 NeighY = 0;
         }
     if (NeighY >= my_image.length)
         {
                 NeighY = my_image.length - 1;
         }
        
     // accumulate
     Value = my_image.raw_image[(NeighY * my_image.width) + NeighX];
     Sum = Sum + (Value * smooth[j + 1][i + 1]);
     
    }
   }

   // calculate result
   Result = Sum;
   if (Result > 0) 
   {
           Result = sqrt(Result);
   }
   pWork[(y * my_image.width) + x] = Result;
  }
 }

 // copy result back into source array
 for (i = 0; i < my_image.width * my_image.length; i++)
 {
  // clamp to 255
  if (pWork[i] > 255)
   my_image.raw_image[i] = 255;
  else
   my_image.raw_image[i] = (unsigned char)pWork[i];
 }

return 0;
}

Thanks for any help


//code supplied by Roger Rowland (butchered by me :p)



<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.