NzF

Mosaify Image Filter

Jonathan Frech
Abstract.
Guest post written and il­lus­trated by ⁠ ⁠Jonathan Frecha.
This Python program mosai­fies a given image. By pseudo-randomly drawing lines, polygons are defined which are then filled with the original image’s colors.

Gast­bei­trag von ⁠ ⁠Jo­na­than Frecha ge­schrieben und bebildert.
Die­ses Python-Pro­gramm mo­sai­fi­ziert ein ge­ge­be­nes Bild. Die­ser Ef­fekt wird dadurch erreicht, dass pseu­do­zu­fäl­lige Strecken ge­zeich­net wer­den, welche durch ihre Schnitt­punkte Poly­gone de­fi­nie­ren. Eben­diese wer­den an­schlie­ßend mit den Farbdaten des ur­sprüng­li­chen Bil­des gefüllt.

Mosaify is an image filter written in ⁠ ⁠Python 2.7b1 utilizing the Python Imaging Li­brary2. It takes in an input image and outputs a mosai­fied version of it. (🗎⁠ ⁠Source­codec)

Starting with a blank canvas the size of the original image, lines are randomly drawn, which will most likely in­ter­sect to form polygons of dif­fer­ent sizes and shapes. Said polygons are filled with the original image’s color at each polygon’s most top-left pixel position.

As a final touch, the lines drawn at the be­gin­ning are filled in with one pseudo-randomly chosen sur­rounding pixel. Because of this, edges are a bit frazzled.

Other ap­pear­ances can be achieved by changing pa­ram­e­ters n and k, which define the number of lines drawn and their dis­tri­bu­tion (both floating-point numbers larger than zero, by default n = 5 and k = 1). It may also help to run the filter a few times to get a visually pleasing output, as the polygons are pseudo-randomly de­ter­mined.

The program usage is as follows: python mosaify.py <image file name> [n] [k]

Martin and ivy, mosaified with n=5 and k=1 (which are the default parameters)
Martin and ivy, mosai­fied with n = 5 and k = 1 (which are the default pa­ram­e­ters)
Martin and ivy, mosaified with n=5 and k=1 (which are the default parameters)
Martin and ivy, mosaified with n=10 and k=1
Martin and ivy, mosai­fied with n = 10 and k = 1
Martin and ivy, mosaified with n=10 and k=1
Martin and ivy, before processing
Martin and ivy, before pro­cess­ing
Martin and ivy, before processing

Fußnoten.
1(2025-03-02, Jonathan Frech): Python 2 hat mich viele Jahre begleitet. 2020 wurde die Sprache ab­ge­wick­elt. Viel Mensch­heits­zeit und -arbeit wurde ver­nich­tet, da ihre Nach­fol­ger­in in vie­ler­lei, oft subtiler Weise in­kom­pa­ti­bel ist. Ich habe gerne Python 2 ge­schrieben und ab 2017 gerne gegolft. Python 2 hatte für mich einen Charme, der un­wie­der­bring­lich fort ist.
2Python Imaging Li­brary (PIL): https://www.pythonware.com/products/pil/. No longer live as of 2025-03-02. Internet archive: ⁠ ⁠web.archive.org/web/20170815072749/https://pythonware.com/products/pil/ [2025-03-02]
ahttps://www.jfrech.com/
bhttps://docs.python.org/2/
chttps://www.medienfrech.de/foto/NzF/2017-08-15/2017-08-14_jonathan-frech_mosaify.py
Zitierempfehlung (.BibTeX, .txt):
Frech, Jonathan: »Mosaify Image Filter«. In: Notizen zur Fotografie, 2017-08-15. Online: https://www.medienfrech.de/foto/NzF/2017-08-15_Jonathan-Frech_Mosaify-Image-Filter.html
Zitierempfehlung:
@article{NzF.2017-08-15,
	author  = {Frech, Jonathan},
	date    = {2017-08-15},
	title   = {Mosaify Image Filter},
	journal = {Notizen zur Fotografie},
	url     = {https://www.medienfrech.de/foto/NzF/2017-08-15\_Jonathan-Frech\_Mosaify-Image-Filter.html},
	urldate = {$0},
}
Zitierempfehlung:
Frech, Jonathan: »Mosaify Image Filter«. In: Notizen zur Fotografie, 2017-08-15. Online: https://www.medienfrech.de/foto/NzF/2017-08-15_Jonathan-Frech_Mosaify-Image-Filter.html$1