NzF

Mosaify Im­age Fil­ter

Jonathan Frech
Abstract.
Guest post writ­ten and il­lus­trated by ⁠ ⁠Jo­na­than Frecha.
This Py­thon pro­gram mosai­fies a given im­age. By pseu­do-ran­domly draw­ing lines, poly­gons are de­fined which are then fill­ed with the orig­i­nal im­age’s co­lors.

Gast­bei­trag von ⁠ ⁠Jo­na­than Frecha ge­schrieben und be­bil­dert.
Die­ses Py­thon-Pro­gramm mo­sai­fi­ziert ein ge­ge­be­nes Bild. Die­ser Ef­fekt wird da­durch er­reicht, dass pseu­do­zu­fäl­lige Stre­cken ge­zeich­net wer­den, welche durch ih­re Schnitt­punkte Poly­gone de­fi­nie­ren. Eben­diese wer­den an­schlie­ßend mit den Farb­da­ten des ur­sprüng­li­chen Bil­des ge­füllt.

Mosaify is an im­age fil­ter writ­ten in ⁠ ⁠Py­thon 2.7b [1] uti­lizing the Py­thon Im­ag­ing Li­brary [2]. It takes in an in­put im­age and out­puts a mosai­fied ver­sion of it. (🗎⁠ ⁠Source­codec)

Start­ing with a blank can­vas the size of the orig­i­nal im­age, lines are ran­domly drawn, which will most like­ly in­ter­sect to form poly­gons of dif­fer­ent sizes and shapes. Said poly­gons are fill­ed with the orig­i­nal im­age’s col­or at each poly­gon’s most top-left pixel po­si­tion.

As a fi­nal touch, the lines drawn at the be­gin­ning are fill­ed in with one pseu­do-ran­domly chosen sur­rounding pixel. Be­cause of this, edges are a bit fraz­zled.

Other ap­pear­ances can be achieved by changing pa­ram­e­ters n and k, which de­fine the num­ber of lines drawn and their dis­tri­bu­tion (both float­ing-point numb­ers larger than zero, by de­fault n = 5 and k = 1). It may also help to run the fil­ter a few times to get a vi­su­al­ly pleas­ing out­put, as the poly­gons are pseu­do-ran­domly de­ter­mined.

The pro­gram usage is as fol­lows: python mosaify.py <image file name> [n] [k]

Martin and ivy, mosaified with n=5 and k=1 (which are the default parameters)
Mar­tin and ivy, mosai­fied with n = 5 and k = 1 (which are the de­fault 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
Mar­tin 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
Mar­tin and ivy, be­fore pro­cess­ing
Martin and ivy, before processing

Fußnoten.
1(2025-03-02, Jonathan Frech): Py­thon 2 hat mich viele Jahre be­glei­tet. 2020 wur­de die Spra­che ab­ge­wick­elt. Viel Mensch­heits­zeit und -arbeit wur­de ver­nich­tet, da ih­re Nach­fol­ger­in in vie­ler­lei, oft sub­ti­ler Wei­se in­kom­pa­ti­bel ist. Ich habe gerne Py­thon 2 ge­schrieben und ab 2017 gerne ge­golft. Py­thon 2 hat­te für mich ei­nen Charme, der un­wie­der­bring­lich fort ist.
2Py­thon Im­ag­ing Li­brary (PIL): https://www.pythonware.com/products/pil/. No longer live as of 2025-03-02. In­ter­net ar­chive: ⁠ ⁠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 Im­age Fil­ter«. 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 Im­age Fil­ter},
	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 Im­age Fil­ter«. In: Notizen zur Fotografie, 2017-08-15. Online: https://www.medienfrech.de/foto/NzF/2017-08-15_Jonathan-Frech_Mosaify-Image-Filter.html$1