0

I'm on Windows 10, using Imagemagick version 7.1.0 Q16-HDRI (64-bit).

I would like to add a little white space between letters on an image like this:

Image Link

Here is the same image, which I edited using paint. I moved each letter a little bit to the right. It's a tiny difference, but it's there:

Edited Image Link

I just want to add white space and therefore increasing the space between the letters.

I think that using "Connected Components" can do this, but after googling and trying various things, I just can't figure it out.

xenoid
  • 8,396
  • 3
  • 23
  • 49
Scorpys
  • 3
  • 4
  • See -kerning at https://imagemagick.org/script/command-line-options.php#kerning – fmw42 Jan 05 '22 at 21:43
  • Yeah but kerning seems to be for Creating an image. I don't need to create images, I need to edit/convert existing images (where I don't know the letters/characters beforehand). – Scorpys Jan 05 '22 at 21:56
  • ImageMagick cannot do that. You need to use tesseract to read the text from an image into ascii characters. Then put the text back into an image with more space between the letters. – fmw42 Jan 05 '22 at 23:38
  • haha funny. The reason I'm trying to add this space is in order to improve the accuracy of Tesseract when reading the image. Because when the letters are too close together, Tesseract often adds 2 characters in place of one, such as s$ and #f etc. Can't imagemagick do this somehow by using connected-components? – Scorpys Jan 05 '22 at 23:47
  • 1
    You can do exactly as you suggest... find the individual components and their current positions https://stackoverflow.com/a/28429090/2836621 Then create a new, wider canvas, paste each component in with a bigger gap. But as you appear to be trying to evade a Captcha (questionable in itself) the letters don't make a word anyway, so you may as well pass individual letters to tesseract. Also, Windows is not a very easy/rational environment for such things IMHO. – Mark Setchell Jan 06 '22 at 08:23
  • Thanks Mark, I decided to try what you said. But I run into a problem when I get the position of the connected components, they're not in any order. I would need them to be in order either from left to right or right to left. Is that possible? – Scorpys Jan 09 '22 at 20:23
  • The x,y coordinates of each connected component are available to you, so there's nothing stopping you sorting by `x` if you want them left-to-right. – Mark Setchell Jan 09 '22 at 20:28
  • Okay I think I understand it now. So in this | 3: 24x29+276+32 288.5,46.2 516 gray(255) | 1: 28x29+180+32 197.1,46.9 385 gray(255) | 8: 37x22+110+39 129.4,48.0 373 gray(255) | the order would be 3, then 1, then 8. Can Imagemagick do the sorting by itself though? – Scorpys Jan 09 '22 at 20:48
  • I mean, I would like the results that Imagemagick gives me to be sorted using x. – Scorpys Jan 09 '22 at 20:56
  • Nope. ImageMagick isn't going to sort by `x` for you. That's not the way Unix works. Each tool does one thing and does it well. If you want it sorted differently that's up to you to add an additional tool. – Mark Setchell Jan 09 '22 at 22:04
  • Understood. Thank you. – Scorpys Jan 10 '22 at 03:20

0 Answers0