5 Replies Latest reply on Jan 30, 2011 7:20 AM by chubakueno

    Edge Detection Help

    rosem.com

      Hey Everyone,

       

      I'm trying to create an edge detection kernal, very similar to the one in Adobe Photoshops Poster Edges filter. I want to be able to use this in flash, so I'm trying to port it over.

       

      So far I've ported over Canny Edge Detection, and Sobel Edge Detection, without much luck.

       

      Can anyone point me to some reading on how to Poster Edges filter is done?

       

      Thanks,

      Mike

        • 1. Re: Edge Detection Help
          alruden2 Level 1

          At first you should posterize the input image. Then use the find edge matrix

          |  -1 -1 -1 |

          |  -1  8 -1 |

          |  -1 -1 -1 |

          for each image pixel.

           

          If you use graph then you should create two conected kernels

           

          first kernel posterize

           

          parameter float posterPar; //posterize amount

           

          ............................................................

          void
          evaluatePixel()
          {

               dst =  sampleNearest(src,outCoord());

               dst.r = floor(dst.r * posterValue)/posterValue;
               dst.g = floor(dst.g * posterValue)/posterValue;
               dst.b = floor(dst.b * posterValue)/posterValue;

          }

           

          ........................................................

           

          second kernel find edges and multiply by posterized pixel

           

          ....................................................

           

              void
              evaluatePixel()
              {
                  float2 pSize = pixelSize(src);
                  float4 inpPix;
                  dst =  sampleNearest(src,outCoord());
                  float dst_a = dst.a;
                  inpPix = dst;
                  dst *= float4(8.0, 8.0, 8.0, 8.0);
                  dst -= sampleNearest(src,outCoord() + float2(pSize.x, 0.0));
                  dst -= sampleNearest(src,outCoord() - float2(pSize.x, 0.0));
                  dst -= sampleNearest(src,outCoord() + float2(0.0, pSize.y));
                  dst -= sampleNearest(src,outCoord() - float2(0.0, pSize.y));
                  dst -= sampleNearest(src,outCoord() + float2(pSize.x, pSize.y));
                  dst -= sampleNearest(src,outCoord() - float2(pSize.x, pSize.y));
                  dst -= sampleNearest(src,outCoord() + float2(pSize.x, -pSize.y));
                  dst -= sampleNearest(src,outCoord() - float2(pSize.x, -pSize.y));
                  float maxVal = max(dst.r, max(dst.g, dst.b));
                  dst = float4(1.0,1.0,1.0,dst_a) - float4(maxVal, maxVal, maxVal, 0.0);
                  dst *= inpPix;
                  dst = posterizePixel(inpPix, 5.0);
              }

           

          .....................................................

           

          Or use one kernel

           

              parameter float posterPar
              <      
                  minValue:float(1.0);
                  maxValue:float(256.0);
                  defaultValue:float(10.0);
              >;
             
             
              float4 posterizePixel(float4 pix, float posterValue)
              {
                  float4 result;
                  result.r = floor(pix.r * posterValue)/posterValue;
                  result.g = floor(pix.g * posterValue)/posterValue;
                  result.b = floor(pix.b * posterValue)/posterValue;
                  result.a = pix.a;
                  return result;
              }

              void
              evaluatePixel()
              {
                  float2 pSize = pixelSize(src);
                  float4 inpPix;
                  dst =  posterizePixel(sampleNearest(src,outCoord()), posterPar);
                  float dst_a = dst.a;
                  inpPix = dst;
                  dst *= float4(8.0, 8.0, 8.0, 8.0);
                  dst -= posterizePixel(sampleNearest(src,outCoord() + float2(pSize.x, 0.0)), posterPar);
                  dst -= posterizePixel(sampleNearest(src,outCoord() - float2(pSize.x, 0.0)), posterPar);
                  dst -= posterizePixel(sampleNearest(src,outCoord() + float2(0.0, pSize.y)), posterPar);
                  dst -= posterizePixel(sampleNearest(src,outCoord() - float2(0.0, pSize.y)), posterPar);
                  dst -= posterizePixel(sampleNearest(src,outCoord() + float2(pSize.x, pSize.y)), posterPar);
                  dst -= posterizePixel(sampleNearest(src,outCoord() - float2(pSize.x, pSize.y)), posterPar);
                  dst -= posterizePixel(sampleNearest(src,outCoord() + float2(pSize.x, -pSize.y)), posterPar);
                  dst -= posterizePixel(sampleNearest(src,outCoord() - float2(pSize.x, -pSize.y)), posterPar);
                  float maxVal = max(dst.r, max(dst.g, dst.b));
                  dst = float4(1.0,1.0,1.0,dst_a) - float4(maxVal, maxVal, maxVal, 0.0);
                  dst *= inpPix;
              

              }
          }

           

          ..............................................................

          • 2. Re: Edge Detection Help
            rosem.com Level 1

            Thank you so much for replying.

             

            I tried this today, but I can't seem to get it to work...

             

            Are you saying you just posterize the image, and then do edge detection, or am I missing something? Copy and pasting your code doesn't seem to be working.

            • 3. Re: Edge Detection Help
              alruden2 Level 1

              This is full code

               

               

              <languageVersion : 1.0;>

              kernel NewFilter
              <   namespace : "Your Namespace";
                  vendor : "Your Vendor";
                  version : 1;
                  description : "your description";
              >
              {
                  input image4 src;
                  output pixel4 dst;
                 
                  parameter float posterPar
                  <      
                      minValue:float(1.0);
                      maxValue:float(256.0);
                      defaultValue:float(10.0);
                  >;
                 
                 
                  float4 posterizePixel(float4 pix, float posterValue)
                  {
                      float4 result;
                      result.r = floor(pix.r * posterValue)/posterValue;
                      result.g = floor(pix.g * posterValue)/posterValue;
                      result.b = floor(pix.b * posterValue)/posterValue;
                      result.a = pix.a;
                      return result;
                  }

                  void
                  evaluatePixel()
                  {
                      float2 pSize = pixelSize(src);
                      float4 inpPix;
                      dst =  posterizePixel(sampleNearest(src,outCoord()), posterPar);
                      float dst_a = dst.a;
                      inpPix = dst;
                      dst *= float4(8.0, 8.0, 8.0, 8.0);
                      dst -= posterizePixel(sampleNearest(src,outCoord() + float2(pSize.x, 0.0)), posterPar);
                      dst -= posterizePixel(sampleNearest(src,outCoord() - float2(pSize.x, 0.0)), posterPar);
                      dst -= posterizePixel(sampleNearest(src,outCoord() + float2(0.0, pSize.y)), posterPar);
                      dst -= posterizePixel(sampleNearest(src,outCoord() - float2(0.0, pSize.y)), posterPar);
                      dst -= posterizePixel(sampleNearest(src,outCoord() + float2(pSize.x, pSize.y)), posterPar);
                      dst -= posterizePixel(sampleNearest(src,outCoord() - float2(pSize.x, pSize.y)), posterPar);
                      dst -= posterizePixel(sampleNearest(src,outCoord() + float2(pSize.x, -pSize.y)), posterPar);
                      dst -= posterizePixel(sampleNearest(src,outCoord() - float2(pSize.x, -pSize.y)), posterPar);
                      float maxVal = max(dst.r, max(dst.g, dst.b));
                      dst = float4(1.0,1.0,1.0,dst_a) - float4(maxVal, maxVal, maxVal, 0.0);
                      dst *= inpPix;
                  }
              }

               

               

              If use graph it work faster

              • 4. Re: Edge Detection Help
                rosem.com Level 1

                I see, I have it working now. It looks pretty good, but the befunky.com example I'm trying to replicate is a little different still. Any ideas on how they did this?

                 

                befunky_artwork.jpg

                • 5. Re: Edge Detection Help
                  chubakueno

                  maybe edge detectoin + selective comic-like dots(more dark = bigger dots), but that is a specialized and composed algorithm they have created.Sorry for my bad english