3 Replies Latest reply on Jul 6, 2009 1:03 AM by souldreamer

    Removing White color from the image


      I am developing application in Flex3 and have following issue.

      I am creating small application where user can remove whilte color including colors nearest to white from the image.

      I have used ColorMatrixFileter, but it some time dull the other colors, and also tried with Bitmap.threshold, but it needs specific range of colors.


      Please help me if you have any idea on this.



        • 1. Re: Removing White color from the image

          As your post is in the pixelbender forum, i'm guessing it's a possible solution for you. I quickly wrote a kernel that would set the alpha of the colors closest to white by a certain amount (by computing the luminosity of the color and checking that) to something proportional (pure white will get alpha 0 and pure black (if amount is 1) will still have alpha 100%). You can change the luminosity function used (the one in the example is the YIQ (used in NTSC) luminosity), and the one commented out would be a pure average of the sum of the color components; you can try others out, just make sure the coefficients add up to 1). You can also choose not to blend the alpha, and just have original alpha for colors that weren't cut out, and alpha 0 for the colors that you extracted by changing the if(Y...)'s statement to if(...) alphaMult = 0.0;


          <languageVersion : 1.0;>
          kernel FloatR
          <   namespace : "filters";
              vendor : "seventh-shape";
              version : 1;
              description : "desaturates the input image by the specified amount";
              input image4 src;
              output pixel4 dst;
              parameter float amount
                  minValue : float(0);
                  maxValue : float(1);
                  defaultValue : float(0);
              void evaluatePixel() {
                  float4 inputColor = sampleNearest(src, outCoord());
                  float Y = 0.299 * inputColor.r + 0.114 * inputColor.b + 0.587 * inputColor.g;
                  //Y = 0.333 * inputColor.r + 0.333 * inputColor.b + 0.334 * inputColor.g;
                  float alphaMult = 1.0;
                  if(Y > 1.0-amount) alphaMult = 1.0-smoothStep(1.0-amount, 1.0, Y);
                  dst.r = inputColor.r;
                  dst.g = inputColor.g;
                  dst.b = inputColor.b;
                  dst.a = inputColor.a * alphaMult;

          1 person found this helpful
          • 2. Re: Removing White color from the image
            kaushal_bs Level 1

            Thanks for the answer, this is almost working for me,

            but I am using Flex 3 SDK, does this solution work for it?

            • 3. Re: Removing White color from the image
              souldreamer Level 1

              It should. For more info on how to make it work, look at another thread in this forum, called "Lookup Table (LUT) implementation" if I remember correctly. Either use the code that person ended up writing or follow my advice there and look at the videos i linked.