'ImageMagick unable to turn white in transparent without getting ugly edges

I am trying to remove the white from 5k+ pictures and turn it into transparent. Unfortunately, when I do this it leaves a ugly edge around the black parts in various gray tones.

I tried various methods including -trim and -fuzz but I am unable to get it working properly. All it should do is remove the white and leave everything else intract.

I have to crank the fuzz so high for the arrows to remotely look a little bit properly, that ImageMagick will remove other stuff that it shouldn't as well.

Can someone help me out please?

The original image:
enter image description here

The image after using ImageMagick (added green so you can see the ugly edge better): enter image description here

The image after using ImageMagick (original)

enter image description here

So basically what I want is to remove all white from the pictures and make those transparent. Anything else should NOT be affected.

The image was made in 8k resolution in Illustrator which I then exported to a single PNG image (transparent). Then I used Bramus' tile cutter script for Photoshop to cut my image into tiles (which forces a white background unfortunately).

So finally I wanted to try ImageMagick to remove the white but as you can read, I am unable to so far.

Hope someone can help me out.

The code I currently used:

for /R "C:\Users\<Username>\Desktop\map" %I in (*.png) do magick "%I" -fuzz 69% -transparent #FFFFFF "%I"

What it should look like in the end when I put it on top of my other layer(s):

enter image description here

I tried increasing the blur 0x2 for example, on big pictures that works better, but the smaller pictures lose to much detail and the lines are barely visible. It is either big pictures are oké or low pictures are oké but never both so far whatever I try.

A sample of a smaller image with the blur set to 0x2. You can see some white was left there too.

enter image description here

If it helps, I can zip a couple of small, regular and big images for testing purposes?

Original files: https://easyupload.io/8yep41
After using ImageMagick: https://easyupload.io/6xlm2f

Single image comparison: https://easyupload.io/gi5dvm

The command I used is:

for /R "C:\Users\<Username>\Desktop\map\<FolderName>" %I in (*.png) do magick "%I" -fuzz 10% -transparent white ( +clone -alpha extract -blur 0x1.2 -level 50x100% ) -alpha off -compose copyAlpha -composite "%I"

So I either have almost disappearing arrows on the low zoom ones (4 for example) but not on 6 or I have white borders. I also have white spots left at the arrow heads in multiple occasions.



Solution 1:[1]

In Imagemagick 7 on Windows, you can do

magick arrow.png -fuzz 10% -transparent white ^
( +clone -alpha extract -blur 0x1 -level 50x100% ) ^
-alpha off -compose copyAlpha -composite ^
new_arrow.png

enter image description here

If in a .bat script, I believe that you would need to double the % to %%.

ADDITION

Try this:

magick 17_original.png -fuzz 10% -transparent white ^
( +clone -alpha extract -blur 0x1.2 -level 85x100% ) ^
-alpha off -compose copyAlpha -composite ^
-background "rgb(6,120,0)" -alpha background -alpha off ^
17_original_green_fred.png

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1