This project has moved. For the latest updates, please go here.

Extract logo from the images

Aug 17, 2015 at 1:20 PM
Hi,
I am trying to get rid of the background color of the image and extract the logo in that image. Sample image looks like Image

I tried with code
 using (MagickImage image = new MagickImage(@"E:\Development\DOTNET\LOGOExtracter\LOGOExtracterSample\SampleApp\images-input\19045997.PCX"))
            {

                WritablePixelCollection p = image.GetWritablePixels();
                Pixel pp = p.GetPixel(1,2);

                MagickColor c = pp.ToColor();
                MagickColor fill = new MagickColor(255, 255, 255);
                image.Opaque(c, fill);
                image.ClassType = ImageMagick.ClassType.Pseudo;
                
                image.Write(@"E:\Development\DOTNET\LOGOExtracter\LOGOExtracterSample\SampleApp\images-output\19045997.jpg");
                image.Dispose();
            }
please help
Coordinator
Aug 17, 2015 at 7:43 PM
You are only replacing colors that have the exact same color as the pixel at 1,2. If you want to get colors 'close' to that you need to set the ColorFuzz of the image. For this image setting it to 10% seems to be okay, not sure about other images though.
using (MagickImage image = new MagickImage("19045997.pcx"))
{
  using (PixelCollection p = image.GetReadOnlyPixels())
  {
    Pixel pp = p.GetPixel(1, 2);
    MagickColor c = pp.ToColor();
    MagickColor fill = new MagickColor(255, 255, 255);
    image.ColorFuzz = new Percentage(10);
    image.Opaque(c, fill);
    image.ClassType = ImageMagick.ClassType.Pseudo;

    image.Write("19045997.jpg");
  }
}