8

I have the following png image:

enter image description here

I want to convert the edges that aren't black to black. I have tried

convert <input> -threshold 80% <output>

but this gives

enter image description here

which has changed the look of the graph.

How can I do this without changing the way to graph looks, apart from the color?

Simd
  • 927
  • 6
  • 14
  • 28
  • Did you see this answer here and try this with the example values, etc. to see what output you get: https://superuser.com/questions/893476/converting-from-color-to-true-black-and-white-in-imagemagick – Vomit IT - Chunky Mess Style Jul 30 '23 at 14:50
  • @VomitIT-ChunkyMessStyle Yes. Sadly the double negate method makes everything thicker. – Simd Jul 30 '23 at 15:04
  • The problem is what your mental model of the world tell you what you want and what you actually want are two different things. You actually don't want to turn all non-white pixels black. You want to make them grayscale. There is actually very little black in your image. For example the `10/10` is not black at all - it's a bunch of grays and blues and some tiny amount of yellow. – slebetman Aug 01 '23 at 00:13
  • @slebetman you are right. It's still not obvious how to do it correctly – Simd Aug 01 '23 at 03:38

1 Answers1

16

Part of the issue is that not only do you have to find a good crossover value for the reds, but also yellows & blues, because the 'black' text is horribly antialiased in colour.

enter image description here

If you apply a simple threshold filter, then the yellows & blues in this affect how the apparently black lettering changes, as well as the reds.
This is what makes the font weights & red line look wrong.

enter image description here

In something like Photoshop [& probably Gimp too, which does run on nix] you can ease this out to give a smoother result.

enter image description here

This is how much manipulation it takes to try balance it up

enter image description here

This is still guesswork & not exactly perfect, but gives this at original size

tweak

The font & line weights at least now look vaguely similar. A bit more patience and trial & error & you could probably get even closer.

Tetsujin
  • 47,296
  • 8
  • 108
  • 135
  • 11
    Those colorful anti-aliasing artifacts are probably caused by [ClearType](https://learn.microsoft.com/en-us/typography/cleartype/), Microsoft's subpixel text rendering system that's used by most programs on Windows. It makes fonts more readable by taking into account that every pixel on a digital screen is actually 3 pixels (red, green and blue) next to each other. The leftmost pixels of the black font appear yellow-ish, because they only switch off the rightmost sub-pixel (blue). The right ones appear blueish, because they only switch off the left sub-pixels (red and green). – Philipp Jul 31 '23 at 13:44
  • @Philipp - Yeah, I'd assumed that's what it must be. I'm on Mac which just doesn't do that in such a horrible way, it stays black/greys - similar shot of part of your comment, enlarged the same way - https://i.stack.imgur.com/Gm0j0.png – Tetsujin Jul 31 '23 at 14:39
  • 10
    It's not "horrible", it's actually a pretty clever system. And from personal experience with Windows I can attest that it actually works really great in practice. Those colors are completely invisible on the screen. Black fonts look perfectly black, even though they actually are not. The only situation where the colors become visible is when you take a screenshot and upscale it. And that's a rather niche use-case. – Philipp Jul 31 '23 at 14:45
  • @Philipp - I've been predominantly on Mac for so long that Windows text rendering just looks terrible to me, even before you enlarge it. I guess it's what you get used to. I do use Win occasionally, but I've been Mac for over 30 years. https://i.stack.imgur.com/Q0BO6.png ;)) – Tetsujin Jul 31 '23 at 14:51
  • @Tetsujin My experience with Mac is that the text looks beautiful on its own high-density display, but if you hook up a standard external monitor, it's pretty hard to read at small font sizes. Windows rendering does a better job compensating for standard-density displays. – A. R. Jul 31 '23 at 15:27
  • @AR-solidarityforModstrike - I don't use any high density displays [retina] just a couple of good & accurately-calibrated 2k 27" [1440p] which I've had a decade - & use extensively for colour work. Looks fine to me. My partner has one, sure it's sharper but not enough to make me buy a pair. – Tetsujin Jul 31 '23 at 15:30
  • I had assumed the image came from LaTeX/Tikz. – Simd Jul 31 '23 at 16:36
  • 1
    @Tetsujin Macs do the same thing. The "weirdness" is not from the subpixel rendering, it's from from using different anti-aliasing settings. A PC using out of the box settings generally anti-aliases text for sharpness to make it more readable for people who struggle with contrast perception. Mac defaults for smoothness which makes the text "prettier", but harder to read at lower background contrasts. However, if you go to Personalization > Fonts > Adjust ClearType you can adjust the settings to look indistinguishable from a Mac's default. – Nosajimiki Aug 01 '23 at 01:10