match 2D patterns with perl

F

FangQ

hi

I am doing a very interesting work. The altimate goal is to generate a
new style of bitmap font from an existing one. This involves finding
and replacing 2D patterns.

Here is an example, the original glyph looks like

0000000000000000
1111111111111111
0000000000000000
0011111110000000
0010000010000000
0010000010000000
0010000010000000
0010000010000000
0011111110000000
0010000010000000
0000000000000000
0000000000000000
0000000000000000

which contains a square-like pattern. I want to change it to

0000000000000000
1111111111111111
0000000000000000
0001111100000000
0010000010000000
0010000010000000
0010000010000000
0010000010000000
0010000010000000
0001111100000000
0000000000000000
0000000000000000
0000000000000000

which has a rounded rectangle. Note that the all-0-regions in the two
glyphs can have other patterns, but I want to keep them the same. Note
2: the edge-lengths of the square pattern could be different from one
to another, one glyph may contain multiple of these square patterns.

here is my question:

1. can I do this maching and replacement easily in perl? can you give
me a short example?
2. if not, what is the best tool for this purpose? (I can always write
loops and exhaust all possible combinations with C or other programming
languages, but I think they are not elegant.)

thanks

Qianqian
 
J

John Bokma

FangQ said:
1. can I do this maching and replacement easily in perl? can you give
me a short example?


If you just want to change the 6 indicated 1's to zeroes in each, it's a
piece of cake to do that. But not sure if you want to do that.
 
F

FangQ

no, as I said, I want to match any rectangular structure, no matter
what width/height and positions in the array.
 
J

John Bokma

FangQ said:
no, as I said, I want to match any rectangular structure, no matter
what width/height and positions in the array.

Your writing was quite vague, to say the least. At first read you wanted
to have each rectangle to have rounded corners. Then I noticed that
the line below the rectangle:

0010000010000000

became:

0000000000000000

contradicting what I just had gathered from your message.
 
T

Ted Zlatanov

I am doing a very interesting work. The altimate goal is to generate a
new style of bitmap font from an existing one. This involves finding
and replacing 2D patterns.

Having actually done bitmap font scaling by hand, I can promise you
this is much harder than you think. It's probably easier and cheaper
to have a human scale the glyphs from the start, and you'll get much
better results. The reason is that you're limited to two colors and
very few pixels, and you have to make each shape recognizable and
readable.

Ted
 
R

Ralf Muschall

FangQ wrote:
....
Here is an example, the original glyph looks like
which contains a square-like pattern. I want to change it to

No - it contains an 'A'-like shape. Is this intentional
or a typo?
1. can I do this maching and replacement easily in perl? can you give
me a short example?
2. if not, what is the best tool for this purpose? (I can always write
loops and exhaust all possible combinations with C or other programming
languages, but I think they are not elegant.)

You might try this:

1. replace 011..110 by 021..120
2. transpose the array (i.e. swap rows and columns)
3. replace 021..120 by 001..100
4. transpose again

This probably breaks on more complicated patterns.

Ralf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top