9 Replies Latest reply on Feb 28, 2010 12:26 AM by Kevin Goldsmith

    Different application of a filter on Toolkit and in Flex/Flash

    Javier de la Torre

      Hi all,

       

      I am just starting to play with pixelbender and this looks great. But I am facing an issue that is struggling me for some days. I have created a little Flex application to demonstrate it.

       

      Basically, the same pixel bender applied on the toolkit and on Flex on the same image has different results for the default values.

       

      I have uploaded the pixel bender Kernel file to

       

      http://vizzuality.s3.amazonaws.com/pixelbendertest/threshold.pbk

       

      And the image that I am applying the filter to:

       

      http://vizzuality.s3.amazonaws.com/pixelbendertest/gmaps2.png

       

      Also here you have an screenshot of the Pixel Bender Toolkit with the Kernel loaded and the defaults applied:

       

      http://vizzuality.s3.amazonaws.com/pixelbendertest/pixelbenderThreshold.png

       

      And finally a Flex application applying the same default values to a Shader and applying it to the same image (source code enabled):

       

      http://vizzuality.s3.amazonaws.com/pixelbendertest/pixelbendertest.html

       

      As you can see I get a different output for the image in Pixel Bender Toolkit than in Flash, and what I get in Pixel Bender is what it should be.

      Any idea if creating a ShaderFilter with default parameters do not work... because a filter is clearly being applied... but not in the way i was expecting.

       

      Thanks in advance.

       

      Javier

      @jatorre

        • 1. Re: Different application of a filter on Toolkit and in Flex/Flash
          Kevin Goldsmith Level 3


          The current version of the toolkit doesn't do a great job of approximating what a filter will look like in Flash. This will be much better in the next version. If you are doing Flash development primarily, one thing to do is to set "Premultiply/unmultiply color by alpha" in the preferences "Flash Player" tab.

           

          That said, I took a look at your filter and I don't see a major reason why you are getting the result that you are. It looks like the input Alpha could be zero when you are loading the image, or your filter is producing a zero value in the alpha channel on the output (Flash premultiplies each pixel by alpha before passing into the Pixel Bender filter and divides each channel by alpha on the way out).

           

          Another issue could be this line:

          "parameter float vegCodes[20];"

           

          I don't think this is supported in the Player, so it could be a compiler problem.

           

          This line:

          pix.rgba==pixel4( 0.0, 0.0, 0.0, 1.0 )

           

          will almost never be true (see http://forums.adobe.com/thread/497374?tstart=0)

           

          I took the liberty of rewriting the filter to make it a bit clearer. Let me know if this works for you:

           


          kernel NewThresholdFilter
          <
          namespace : "com.adobe.example";
          vendor : "Adobe Systems Inc.";
          version : 1;
          description : "Filter for http://forums.adobe.com/post!reply.jspa?thread=585064";
          >
          {
              input image4 inputImage;
              parameter float3 minColor
              < minValue: float3(0.0);
                maxValue: float3(1.0);
                defaultValue: float3(0.0);>;
              parameter float3 maxColor
              < minValue: float3(0.0);
                maxValue: float3(1.0);
                defaultValue: float3(1.0);>;


              output pixel4 outPixel;
              void evaluatePixel()
              {
                  pixel4 notAcceptedColor = pixel4( 0.0, 0.0, 0.0, 1.0 );
                  pixel4 acceptedColor = pixel4( 1.0, 1.0, 1.0, 0.0 );
                  pixel4 pix = sampleNearest( inputImage, outCoord() );

                  bool morethanmax = any(greaterThan( pix.rgb, maxColor ));
                  bool lessthanmin = any(lessThan( pix.rgb, minColor ));
                  bool isEqualToZero = all(equal(pix, pixel4( 0.0, 0.0, 0.0, 1.0 )));

                  if( morethanmax || lessthanmin || isEqualToZero )
                  {
                      outPixel = notAcceptedColor;
                  }
                  else
                  {
                      outPixel = acceptedColor;
                  }
              }
          }
          • 2. Re: Different application of a filter on Toolkit and in Flex/Flash
            Kevin Goldsmith Level 3

            I tested my version of the filter with Flash and it seems to work correctly on your image.


            • 3. Re: Different application of a filter on Toolkit and in Flex/Flash
              Javier de la Torre Level 1

              Thanks for taking the care of rewriting the Kernel, much appreciated.

               

              But Still it does not work to me using your code. The params I then send from Flex are:

               

               

                shader.data.maxColor.value = [1.0,1.0,1.0];

                shader.data.minColor.value = [0.0,0.0,0.0];

               

               

               

              And what I get is:

               

              Screen shot 2010-02-25 at 8.46.25 PM.png

               

              And If you see in PixelBender it is:

               

              Screen shot 2010-02-25 at 8.46.37 PM.png

               

              As you can see the pixels with value 1 in the red channel dissapear. Is the same I was getting.

              (Look at South America)

               

              Thanks!

              • 4. Re: Different application of a filter on Toolkit and in Flex/Flash
                Kevin Goldsmith Level 3

                I think there might be a bug with any in Flash.

                 

                I changed the kernel to:

                <languageVersion : 1.0;>
                kernel ChannelScramblerFilter
                <
                namespace : "com.adobe.example";
                vendor : "Adobe Systems Inc.";
                version : 1;description : "Changes the color channel order from rgba to gbra.";
                >
                {
                    input image4 inputImage;
                    parameter float3 minColor
                    < minValue: float3(0.0);
                      maxValue: float3(1.0);
                      defaultValue: float3(0.0);>;
                    parameter float3 maxColor
                    < minValue: float3(0.0);
                      maxValue: float3(1.0);
                      defaultValue: float3(1.0);>;


                    output pixel4 outPixel;
                    void evaluatePixel()
                    {
                        pixel4 notAcceptedColor = pixel4( 0.0, 0.0, 0.0, 1.0 );
                        pixel4 acceptedColor = pixel4( 1.0, 1.0, 1.0, 0.0 );
                        pixel4 pix = sampleNearest( inputImage, outCoord() );

                        bool3 morethanmax3 = greaterThan( pix.rgb, maxColor );
                        bool morethanmax = (morethanmax3[0] || morethanmax3[1] || morethanmax3[2]);
                        //bool morethanmax = any(greaterThan( pix.rgb, maxColor ));
                       
                        bool3 lessthanmin3 = lessThan( pix.rgb, minColor );
                        bool lessthanmin = (lessthanmin3[0] || lessthanmin3[1] || lessthanmin3[2]);
                        //bool lessthanmin = any(lessThan( pix.rgb, minColor ));
                        bool isEqualToZero = all( lessThan( abs( pix - pixel4( 0.0, 0.0, 0.0, 1.0 ) ), pixel4( 0.001 ) ) );
                        //bool isEqualToZero = all(equal(pix, pixel4( 0.0, 0.0, 0.0, 1.0 )));

                        if( morethanmax || lessthanmin || isEqualToZero )
                        {
                            outPixel = notAcceptedColor;
                        }
                        else
                        {
                            outPixel = acceptedColor;
                        }
                    }
                }

                 

                And that seemed to work better, although still have the issues that you are seeing. I'm going to ask some other folks on the team for their input.

                • 5. Re: Different application of a filter on Toolkit and in Flex/Flash
                  Kevin Goldsmith Level 3

                  AIF Bob, pointed out that if ANY is broken in flash, ALL might be broken also. Not using the ALL function seems to get the correct results for Flash. I'll get bugs filed ASAP.

                   

                  This seems to work right:

                   

                  <languageVersion : 1.0;>
                  kernel ChannelScramblerFilter
                  <
                  namespace : "com.adobe.example";
                  vendor : "Adobe Systems Inc.";
                  version : 1;description : "Changes the color channel order from rgba to gbra.";
                  >
                  {
                      input image4 inputImage;
                      parameter float3 minColor
                      < minValue: float3(0.0);
                        maxValue: float3(1.0);
                        defaultValue: float3(0.0);>;
                      parameter float3 maxColor
                      < minValue: float3(0.0);
                        maxValue: float3(1.0);
                        defaultValue: float3(1.0);>;


                      output pixel4 outPixel;
                      void evaluatePixel()
                      {
                          pixel4 notAcceptedColor = pixel4( 0.0, 0.0, 0.0, 1.0 );
                          pixel4 acceptedColor = pixel4( 1.0, 1.0, 1.0, 0.0 );
                          pixel4 pix = sampleNearest( inputImage, outCoord() );

                          bool3 morethanmax3 = greaterThan( pix.rgb, maxColor );
                          bool morethanmax = (morethanmax3[0] || morethanmax3[1] || morethanmax3[2]);
                          //bool morethanmax = any(greaterThan( pix.rgb, maxColor ));
                         
                          bool3 lessthanmin3 = lessThan( pix.rgb, minColor );
                          bool lessthanmin = (lessthanmin3[0] || lessthanmin3[1] || lessthanmin3[2]);
                          //bool lessthanmin = any(lessThan( pix.rgb, minColor ));
                   
                          bool4 isEqualToZero4 = lessThan( abs( pix - pixel4( 0.0, 0.0, 0.0, 1.0 ) ), pixel4( 0.001 ) );
                          bool isEqualToZero = isEqualToZero4[ 0 ] && isEqualToZero4[ 1 ] && isEqualToZero4[ 2 ] && isEqualToZero4[ 3 ];

                          //bool isEqualToZero = all( lessThan( abs( pix - pixel4( 0.0, 0.0, 0.0, 1.0 ) ), pixel4( 0.001 ) ) );
                          //bool isEqualToZero = all(equal(pix, pixel4( 0.0, 0.0, 0.0, 1.0 )));

                          if( morethanmax || lessthanmin || isEqualToZero )
                          {
                              outPixel = notAcceptedColor;
                          }
                          else
                          {
                              outPixel = acceptedColor;
                          }
                      }
                  }
                  • 6. Re: Different application of a filter on Toolkit and in Flex/Flash
                    Javier de la Torre Level 1

                    Thanks. I am trying it, but I always have to change slightly the code you give me because the Toolkit always tells me that booleans are not supported in Hydra, therefore in Flash I suppose.

                     

                    In any case, thank you very much, i am gonna try it now.

                    • 7. Re: Different application of a filter on Toolkit and in Flex/Flash
                      Javier de la Torre Level 1

                      It worked great!

                       

                      Thank you very much.  This is the adaptation of your code finally:

                       

                      <languageVersion : 1.0;>

                      kernel ChannelScramblerFilter

                      <

                      namespace : "com.adobe.example";

                      vendor : "Adobe Systems Inc.";

                      version : 1;description : "Changes the color channel order from rgba to gbra.";

                      >

                      {

                          input image4 inputImage;

                          parameter float3 minColor

                          <

                          minValue: float3(0.0);

                          maxValue: float3(1.0);

                          defaultValue: float3(0.0);

                          >;

                          parameter float3 maxColor

                          <

                          minValue: float3(0.0);

                          maxValue: float3(1.0);

                          defaultValue: float3(1.0);

                          >;

                          output pixel4 outPixel;

                       

                          void evaluatePixel() {

                       

                          pixel4 notAcceptedColor = pixel4( 0.0, 0.0, 0.0, 1.0 );

                          pixel4 acceptedColor = pixel4( 1.0, 1.0, 1.0, 0.0 );

                          pixel4 pix = sampleNearest( inputImage, outCoord() );

                       

                          if( (greaterThan( pix.rgb, maxColor )[0] || greaterThan( pix.rgb, maxColor )[1] || greaterThan( pix.rgb, maxColor )[2]) ||

                              (lessThan( pix.rgb, minColor )[0] || lessThan( pix.rgb, minColor )[1] || lessThan( pix.rgb, minColor )[2])

                          || lessThan( abs( pix - pixel4( 0.0, 0.0, 0.0, 1.0 ) ), pixel4( 0.001 ) )[ 0 ] && lessThan( abs( pix - pixel4( 0.0, 0.0, 0.0, 1.0 ) ), pixel4( 0.001 ) )[ 1 ] && lessThan( abs( pix - pixel4( 0.0, 0.0, 0.0, 1.0 ) ), pixel4( 0.001 ) )[ 2 ] && lessThan( abs( pix - pixel4( 0.0, 0.0, 0.0, 1.0 ) ), pixel4( 0.001 ) )[ 3 ] )

                          {

                              outPixel = notAcceptedColor;

                          }

                          else

                          {

                              outPixel = acceptedColor;

                          }

                          }

                      }

                      • 8. Re: Different application of a filter on Toolkit and in Flex/Flash
                        Javier de la Torre Level 1

                        Just for completition I have uploaded the final test app at:

                         

                        http://vizzuality.s3.amazonaws.com/pixelbendertest2/pixelbendertest.html

                         

                        With view source enabled.

                         

                        Thanks again.

                         

                        Javier.

                        • 9. Re: Different application of a filter on Toolkit and in Flex/Flash
                          Kevin Goldsmith Level 3

                          Are you running Pixel Bender Toolkit 1.5.1?

                           

                          Booleans are supported in Pixel Bender for Flash, but there was a bug in the toolkit because at one point before release they weren't

                           

                              Kevin

                           

                          // Kevin Goldsmith

                          // Senior Engineering Manager

                          // Adobe Image Foundation

                          // Core Technologies Group

                          // Adobe Systems, Inc.

                          // Seattle, WA

                          1 person found this helpful