0

I would like to erase solid color background from a picture like this:

Object on opaque background

Representation of result as it would appear in graphics editing software:

Object on checkers background

Is there a straight forward way to do this in Magick.NET, ImageMagick or maybe even System.Drawing.Common?

I am fine with the object being single color instead of grayscale, as I can just repeat the process for black and white pixels separately.

I already learned how to apply composite operators, filters like grayscale and such.

Something like ImageMagick's level-colors looks like it might do the job but I am failing at trying to work with the operators.

I also know that as a last resort I can do some pixel math manually like this

foreach (var pixel in magickImageClone.GetPixels())
{

}

but I am trying to avoid to do so.

Honestly I can't do much more than trial and error here because Magick.NET function names like OutDst don't really tell me me much.

1 Answer 1

0

In Imagemagick 6 command line (sorry I do not know C#), try

enter image description here

convert img.png -colorspace gray -alpha copy result.png

enter image description here

Is that what you want?

If on Imagemagick 7, change convert to magick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.