2 Replies Latest reply on Oct 1, 2009 6:22 PM by Dongwook, Kwon

    Simple convolution filter problem in PB.

    Dongwook, Kwon

      I have little trouble with PB.

       

      I was trying to build Canny edge detector for my another project, in order to do that I needed to do simple Sobel operation.

      Which is just convolution filter with this matrix.

       

      [-1, 0, 1,

      -2, 0, 2,

      -1, 0, 1]

       

      This matrix works perfect on Flash using ConvolutionFilter, also on Photoshop with Custom filter.

      But it won't work on Pixelbender, simply result wasn't the same.

       

      PixelBender file was from Pixel Bender Effects exchange site made by manojvekaria.

       

      I test with different matrices on PB 1.5.1 Build 2 on PC and 1.5 Build 1 on Mac.

       

      Sharpen

      [0, -1, 0,

      -1, 5, -1,

      0, -1, 0]

       

      [1, 1, 1,

      1, -7, 1,

      1, 1, 1]

       

      Emboss

      [1, 1, 0,

      1, 0, -1,

      0, -1, -1]

       

      Sobel y

      [1, 2, 1,

      0, 0, 0,

      -1, -2, -1]

       

      All matrices was working fine on Flash and Photoshop,

      But some of matrices didn't give visual result on PB like emboss, sobels.

       

      Is there any way to trace values in PB?

      Or have any idea what's going on this issus?

      Did I do something wrong?

       

      If you can share some thoughts on this, I really appreciate that.

      Thanks in advance.

       

      This is the PB source.

       

      <languageVersion : 1.0;>

      kernel NewFilter
      <   namespace : "com.om-labs.filters.convolution";
          vendor : "Om Labs";
          version : 1;
          description : "Allows defining of convolution matrices for blur, edge tracing, embossing, crayonify";
      >
      {
          parameter float divider<
              minValue: 0.0;
              maxValue:9.0;
              defaultValue:1.0;
          >;

          parameter float4 bias<
              minValue: float4(-1.0);
              maxValue:float4(1.0);
              defaultValue:float4(0.0);
          >;
         
          parameter float3x3 matrix<
              defaultValue: float3x3(-1.0, 0.0, 1.0, -2.0, 0.0, 2.0, -1.0, 0.0, 1.0);
          >;

          input image4 src;
          output pixel4 dst;

          void evaluatePixel(){
              float2 curPt = outCoord();
              float4 tot = float4(0.0);
             
              tot += matrix[0][0] * sampleNearest(src,float2(curPt.x-1.0,curPt.y-1.0));
              tot += matrix[0][1] * sampleNearest(src,float2(curPt.x-1.0,curPt.y    ));
              tot += matrix[0][2] * sampleNearest(src,float2(curPt.x-1.0,curPt.y+1.0));
             
              tot += matrix[1][0] * sampleNearest(src,float2(curPt.x    ,curPt.y-1.0));
              tot += matrix[1][1] * sampleNearest(src,float2(curPt.x    ,curPt.y    ));
              tot += matrix[1][2] * sampleNearest(src,float2(curPt.x    ,curPt.y+1.0));
             
              tot += matrix[2][0] * sampleNearest(src,float2(curPt.x+1.0,curPt.y-1.0));
              tot += matrix[2][1] * sampleNearest(src,float2(curPt.x+1.0,curPt.y    ));
              tot += matrix[2][2] * sampleNearest(src,float2(curPt.x+1.0,curPt.y+1.0));
             
              dst = tot/divider + bias;
          }
      }