Separating characters in a font file
Posted: 2018-05-30T12:39:47-07:00
I'm using ImageMagick 7.0.7-35 Q16 x64 2018-05-21 on win7pro.
I'm looking to separate the characters in a 'bitmap-font-file'. Suppose I had a file like this: http://users.telenet.be/guy.lateur/IM/t ... ropped.png
I want to calculate the bounding rectangles around each character. Let's assume that every adjacent pair of letters has at least 1 vertical line between them that contains only the background (BG) color (black in this example). Here would be the pseudo code:
horizontal (main) scan:
. start at horizontal position (HP) 0, ie, the left of the image
. increase HP by 1 until you reach a vertical line that contains more than just the BG color
. mark this HP as the start/left of the current char
. increase HP by 1 until you reach a vertical line that contains only the BG color
. mark (this HP - 1) as the end/right of the current char
this can easily be extended to cover the entire horizontal range, ie all characters
for each char found, do a vertical scan:
. start at vertical position (VP) 0, ie, the top of the image
. increase the VP by 1 (ie, go down) until you reach a line that contains more than just the BG color
. mark this VP as the top of the character
. do the same for the bottom VP of the character, going up from the bottom VP of the image
Can I do this using IM? If so, can somebody please point me to a couple of command line options I could look into?
As a bonus question: would it be possible to generate an output image containing the lines depicting these bounding rectangles? That way I could easily check the algorithm works, ie, by overlaying in onto the original in my favourite gimp application..
Total noob, here, sorry.
TIA for any pointers!
I'm looking to separate the characters in a 'bitmap-font-file'. Suppose I had a file like this: http://users.telenet.be/guy.lateur/IM/t ... ropped.png
I want to calculate the bounding rectangles around each character. Let's assume that every adjacent pair of letters has at least 1 vertical line between them that contains only the background (BG) color (black in this example). Here would be the pseudo code:
horizontal (main) scan:
. start at horizontal position (HP) 0, ie, the left of the image
. increase HP by 1 until you reach a vertical line that contains more than just the BG color
. mark this HP as the start/left of the current char
. increase HP by 1 until you reach a vertical line that contains only the BG color
. mark (this HP - 1) as the end/right of the current char
this can easily be extended to cover the entire horizontal range, ie all characters
for each char found, do a vertical scan:
. start at vertical position (VP) 0, ie, the top of the image
. increase the VP by 1 (ie, go down) until you reach a line that contains more than just the BG color
. mark this VP as the top of the character
. do the same for the bottom VP of the character, going up from the bottom VP of the image
Can I do this using IM? If so, can somebody please point me to a couple of command line options I could look into?
As a bonus question: would it be possible to generate an output image containing the lines depicting these bounding rectangles? That way I could easily check the algorithm works, ie, by overlaying in onto the original in my favourite gimp application..
Total noob, here, sorry.
TIA for any pointers!