Color Drop (replace with white)

Is there a way to drop all of a certain color? Like if I receive a red form. Is there a way to drop the red color (set all red pixels to white) and leave the black text?

Hi Cody,

Thank you for your inquiry.

Please provide some sample files along with details of the RED FORM so that we can have better understanding of the scenario.

I’ve attached a sample form that I would be sending through my program. Obviously when I receive it, it will be filled out. I would like to drop the red lines and leave only the black text that they filled out.

Hi Cody,

Thank you for providing sample TIFF image.

Please use the following code snippet to turn the RED color pixel WHITE. Note that the sample TIFF image that you have shared contains all of the writing and lines around it in RED. So whole document will be converted to WHITE color only the barcode image will remain back. Output TIFF image has been attached for your reference.

path = @"change_pixcel_color.tif";
using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = (TiffImage)Aspose.Imaging.Image.Load(path))
{
Aspose.Imaging.Color[] pixels = tiffImage.LoadPixels(new Aspose.Imaging.Rectangle(0, 0, tiffImage.Width, tiffImage.Height));
Aspose.Imaging.Color[] newPixels = new Aspose.Imaging.Color[pixels.Length];
for (int i = 0; i < pixels.Length; i++)
{
int deviation = 50;
if (Math.Abs(pixels[i].R - 255) < deviation && Math.Abs(pixels[i].G) < deviation && Math.Abs(pixels[i].B) < deviation)
{
newPixels[i] = Aspose.Imaging.Color.FromArgb(255, 255, 255);
}
else
{
newPixels[i] = pixels[i];
}
}
tiffImage.SavePixels(new Aspose.Imaging.Rectangle(0, 0, tiffImage.Width, tiffImage.Height), newPixels);
tiffImage.Save(@"changed_pixcel_color.tif");
}

That looks amazing! Thank you! But what about the red shading in the service line area? Is it possible to get that as well?

I ran the same tif through the same chunk of code and came out with the attached. There are red spots it left all over the place.



EDIT: Upping the deviation to 60 got rid of the speckles left over. (But not the red shading)

Hi Cody,

Thank you for writing us back.

Please use the following lines of code in the code snippet shared with you in the earlier post. This will replace the RED color with WHITE and also look for LIGHT RED or LIGHT PINK color pixels and replace them too with WHITE color.


int deviation = 20;
if (Math.Abs(255 - pixels[i].R) < deviation && Math.Abs(230 - pixels[i].G) < deviation && Math.Abs(220 - pixels[i].B) < deviation)
{
newPixels[i] = Aspose.Imaging.Color.FromArgb(255, 255, 255);
}
else
{
newPixels[i] = pixels[i];
}