Dotted chars

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Dotted chars

Post by xpt »

NOTE, the OP has been edited to a QA style to give the scenario/request and solution.

> I'm wondering how feasible it is to use ImageMagick tools to produce dotted characters for kids, so they can practice writing following those dotted letters.

Sure, if there is a will, there will be a solution in ImageMagick.
Thanks a lot to Fred (AKA fmw42)'s excellent work, the result is now acceptable (NB, it was already acceptable ever since my reply to Fred's first proposal).

As Fred stated in the first reply, there are several way to do it. Note that the purpose for this is for kids to practice writing following the dotted letters, so anything close enough can be the answer. My solution goes with the 3rd one, i.e., "create a dotted pattern, then tile that out the size of the edge image. Then use the edge image as a mask to over the dotted pattern so that the result might be a set of dotted lines rather than continuous ones." The result is close-enough to me.

> I think the most challenging part is that the letters has to be big enough for kids to follow yet the dots has to be small enough so as to be covered even by regular pencil/ball-pen.

To turn big and bulky letters into thin dots, several tricks has been played.

- 1st is to thin the image with "-morphology dilate disk:3.5"
- 2nd is to dot the edge instead of the whole stroke.

Detail steps as follows:

Code: Select all

# create Letter image
convert -font Arial -pointsize 96 label:ABC -morphology dilate disk:3.5 -negate tmp1.png

# Generates a edge image
convert tmp1.png -negate -morphology EdgeIn Diamond tmp2.png

# create grid of dots pattern 
convert \( -size 1x1 xc:white xc:black +append \) \
\( -clone 0 -negate \) \
-append -write mpr:tile -+delete \
-size 199x109 tile:mpr:tile -negate tmp3.png

# composite edged image over grid of dot pattern, black on white, for priniting
convert tmp3.png tmp2.png -compose multiply -composite -negate tmp.png 
tmp1.png
Image

tmp.png
Image

Thanks
Last edited by xpt on 2011-08-14T20:27:05-07:00, edited 8 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dotted chars

Post by fmw42 »

One way, though rather manually intensive, is to create a binary image of the character, say letter A, as large as you want it say white on black. You can use label:A to create it. See http://www.imagemagick.org/Usage/text/#label. Then use -edge to get an edge outline. Then manally measure the corner points. The use -draw to draw line with a dashed black stroke on a white background to create the dotted letter. This is probably the most sure way to get the dashed pattern the way you want.

You may be able to convert the edge outline into a vector format and then draw the vectors with some dashed pattern. see http://www.imagemagick.org/Usage/transform/#edge_bitmap and http://www.imagemagick.org/Usage/transform/#edge_vector

Another way, might be to create a dotted pattern, then tile that out the size of the edge image. Then use the edge image as a mask to over the dotted pattern so that the result might be a set of dotted lines rather than continuous ones. This one has the possibility of the dots missing some of the lines or breaking up at the corners of the letters.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Dotted chars

Post by Bonzo »

There was a post a while ago where the user was placing tiny images of band members? onto letters in a stadium to spell out names. That would work but I can not remember where the post is now. I only deleted the image off my laptop last week :(
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Re: Dotted chars

Post by xpt »

This is probably the most sure way to get the dashed pattern the way you want.
Oh, no, I don't need to be that accurate. Closely-enough would be fine. E.g.,

Code: Select all

  . .     . . .       . . .   . . .    
 .     .   .     .   .         .     .  
 . . . .   . . .     .         .     .  
 .     .   .     .   .         .     .  
 .     .   . . .       . . .   . . .    
Another way, might be to create a dotted pattern,
Yeah, that was what I've been thinking. Could you elaborate the steps in detail command please?

Thanks a lot!
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Re: Dotted chars

Post by xpt »

Bonzo wrote:There was a post a while ago where the user was placing tiny images of band members? onto letters in a stadium to spell out names.
Oh, I remember that post. Yeah, that could work.
will try to dig it out...

thanks
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Re: Dotted chars

Post by xpt »

will try to dig it out...
<sigh>, can't find it any more myself either...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dotted chars

Post by fmw42 »

try this, though it is not very good at all

# create Letter A image
convert -font Arial -pointsize 96 label:A -negate tmp.png

# create grid of dots
convert \( -size 5x5 xc:black -size 10x10 xc:white +append \) \
\( +clone -flop \) -append -write mpr:tile +delete \
-size 67x109 tile:mpr:tile -negate tmp0.png

# composite letter A over grid of dots
convert tmp0.png tmp.png -compose multiply -composite tmp1.png


The problem is the grid does not align well with the letter A.

I still think converting the letter image to vector format (perhaps after thinning using -morphology erode) and then drawing with a dotted pattern would be best. Anthony is more experienced with that as he created the heart example. Perhaps he can come up with something on that idea or can find some other way to do what I have above in a better way.
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Re: Dotted chars

Post by xpt »

try this, though it is not very good at all
Nice, almost there.

Thanks a lot for your help.
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Re: Dotted chars

Post by xpt »

Here is what I come up with so far,

# create Letter A image
convert -font Arial -pointsize 96 label:A -negate tmp.png

# Generates a edge image
convert tmp.png -negate -morphology EdgeIn Diamond tmp_.png

# create grid of dots
convert \( -size 1x1 xc:black -size 2x2 xc:white +append \) \
\( +clone -flop \) -append -write mpr:tile +delete \
-size 67x109 tile:mpr:tile -negate tmp0.png

# composite edged A over grid of dots, black on white
convert tmp0.png tmp_.png -compose multiply -composite -negate tmp1.png

which is already "acceptable" to me, if I can put 2 dots in that 2x2 space like "\", I think that'd be super.

BTW, can we start with black on white from the very beginning (instead in the last step)?

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dotted chars

Post by fmw42 »

convert -background white -fill black -font Arial -pointsize 96 label:A tmp1.png

convert tmp1.png -negate -morphology EdgeIn Diamond tmp2.png

convert \( -size 1x1 xc:black -size 2x2 xc:white +append \) \
\( +clone -flop \) -append -write mpr:tile +delete \
-size 67x109 tile:mpr:tile -negate tmp3.png

convert tmp3.png tmp2.png -compose multiply -composite -negate -morphology erode disk:1 tmp.png

I have added another morphology step at the end to make the dots bigger.

The mask image (outline) must be white on black to work properly, but your result needs to be black on white. So you need the -negate at the end. I have removed the other negates. The letter A image can be black on white or white on black and still get a white outline on black background.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dotted chars

Post by fmw42 »

Try this also, it thins the A image first. You may want to spread out your dot pattern a little more.


convert -background white -fill black -font Arial -pointsize 96 label:A -morphology dilate disk:3.5 tmp1.png

convert tmp1.png -negate -morphology EdgeIn Diamond tmp2.png

convert \( -size 1x1 xc:black -size 2x2 xc:white +append \) \
\( +clone -flop \) -append -write mpr:tile +delete \
-size 67x109 tile:mpr:tile -negate tmp3.png

convert tmp3.png tmp2.png -compose multiply -composite -negate -morphology erode disk:1 tmp.png
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Re: Dotted chars

Post by xpt »

Thank you for all your helps.
You may want to spread out your dot pattern a little more.
Yep, that's what I wanted too. But I don't know how to do. I think it'd be super if I can put 2 dots in that 2x2 space like "\". I.e., within that 2x2 space, it should be

Code: Select all

#O
O#
where '#' means dot and 'o' means blank. how to do that?

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dotted chars

Post by fmw42 »

try this

convert -size 1x1 xc:white xc:black +append \
\( -clone 0 -flop \) -append -write mpr:tile +delete \
-size 67x109 tile:mpr:tile tmp3.png
xpt
Posts: 59
Joined: 2010-10-06T20:18:24-07:00
Authentication code: 8675308

Re: Dotted chars

Post by xpt »

2 dots in that 2x2 space
or maybe make the dot pattern like
Image

or (better?)

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dotted chars

Post by fmw42 »

a 2x2 space can only have 4 pixels in it. so you cannot make those complicated patterns with only a 2x2 space. the patterns you want need 5x5 or 3x3 spaces

This is your first pattern:


convert \( -size 1x1 xc:white -size 3x1 xc:black +append \) \
\( -size 1x1 xc:black xc:white xc:black xc:white +append \) \
\( -size 2x1 xc:black -size 1x1 xc:white xc:black +append \) \
-clone 1 \
-append -write mpr:tile +delete \
-size 67x109 tile:mpr:tile -negate tmp3.png


This is your second pattern:


convert \( -size 1x1 xc:white xc:black +append \) \
\( -clone 0 -negate \) \
-append -write mpr:tile -+delete \
-size 67x109 tile:mpr:tile -negate tmp3.png
Last edited by fmw42 on 2011-08-14T18:13:36-07:00, edited 1 time in total.
Post Reply