Is this what you want in Imagemagick?
Unix syntax:
magick img.jpg \( +clone -colorspace gray -negate \) -alpha off -compose copy_opacity -composite result.png