photomosaic एक तकनीक है, जहां हम अपनी छवि को वर्गों के ग्रिड में विभाजित कर सकते हैं। प्रत्येक वर्ग को कुछ अन्य छवियों या रंगों से बदल दिया जाएगा। इसलिए जब हम वास्तविक छवि को एक निश्चित दूरी से देखना चाहते हैं, तो हम वास्तविक छवि देख सकते हैं, लेकिन अगर हम करीब आते हैं, तो हम विभिन्न रंगीन ब्लॉकों की ग्रिड देख सकते हैं।
इस मामले में हम फोटोमोसाइक नामक एक पायथन मॉड्यूल का उपयोग कर रहे हैं। इस मॉड्यूल का उपयोग करके, हम आसानी से कुछ फोटोमोसाइक बना सकते हैं। इसे स्थापित करने के लिए कृपया इस लिंक का अनुसरण करें। यह स्किकिट लर्न . को भी डाउनलोड करेगा मॉड्यूल।
sudo pip3 install photomosaic
इस मॉड्यूल में कुछ विशेषताएं हैं। ये नीचे सूचीबद्ध हैं -
- यहां हम विभिन्न आकार की टाइलों का उपयोग कर सकते हैं।
- हम चित्र के विस्तृत भाग के लिए छोटी टाइलें सेट कर सकते हैं।
- टाइल के रूप में उपयोग करने के लिए छवियों का बड़ा संग्रह प्राप्त करने के लिए झिलमिलाहट एपीआई का उपयोग करें
इस लेख में, हम देखेंगे कि कैसे एक बहुत ही सरल तरीके से photomosaics के लिए इस मॉड्यूल को लागू किया जाए।
हम स्किमेज लाइब्रेरी से एक इमेज का उपयोग कर रहे हैं।
मुख्य छवि
<केंद्र>
फ़ोटोमोज़ेक बनाने के चरण
- वास्तविक छवि लें (यहां स्किमेज लाइब्रेरी से छवि)
- ग्रिड टाइल के आकार को परिभाषित करें
- रंगीन RGB छवि ब्लॉक को पूल के रूप में बनाने के लिए एक स्थान प्रदान करें
- फ़ोटोमोज़ेक के लिए फ़ोल्डर को पूल के रूप में सेट करें
- पूल और ग्रिड आकार का उपयोग करके फोटोमोज़ेक में बदलें।
- छवि सहेजें
- बाहर निकलें
उदाहरण कोड
from skimage.io import *
import sys
import photomosaic asphmos
from skimage import data
image = data.coffee() #Get coffee image from skimage
#Get the mosaic size from the command line argument.
mos_size = (int(sys.argv[1]), int(sys.argv[2]))
#create all image squares and generate pool
phmos.rainbow_of_squares('square/')
square_pool = phmos.make_pool('square/*.png')
#Create the mosaic image and save
mosaic = phmos.basic_mosaic(image, square_pool, mos_size)
imsave('mosaic_op.png', mosaic)
आउटपुट (पहला रन, ग्रिड आकार 100 x 100 है)
$ python3 225.Photomosaic.py 100 100
5832it [00:02, 2506.05it/s]
analyzing pool: 100%|| 5832/5832 [00:08<00:00, 717.90it/s]
/usr/local/lib/python3.6/dist-packages/skimage/transform/_warps.py:105: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15.
warn("The default mode, 'constant', will be changed to 'reflect' in "
/usr/local/lib/python3.6/dist-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
partitioning: depth 0: 100%|| 10000/10000 [00:00<00:00, 852292.94it/s]
analyzing tiles: 100%|| 10000/10000 [00:00<00:00, 93084.50it/s]
matching: 100%|| 10000/10000 [00:00<00:00, 30864.50it/s]
drawing mosaic: 100%|| 10000/10000 [00:00<00:00, 13227.12it/s]
/usr/local/lib/python3.6/dist-packages/skimage/util/dtype.py:141: UserWarning: Possible precision loss when converting from float64 to uint8
.format(dtypeobj_in, dtypeobj_out))
<केंद्र>
आउटपुट (दूसरा रन, ग्रिड आकार 500 x 500 है)
$ python3 225.Photomosaic.py 500 500
5832it [00:02, 2634.16it/s]
analyzing pool: 100%|| 5832/5832 [00:08<00:00, 709.54it/s]
/usr/local/lib/python3.6/dist-packages/skimage/transform/_warps.py:105: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15.
warn("The default mode, 'constant', will be changed to 'reflect' in "
/usr/local/lib/python3.6/dist-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
partitioning: depth 0: 100%|| 250000/250000 [00:00<00:00, 456159.45it/s]
analyzing tiles: 100%|| 250000/250000 [00:02<00:00, 113937.01it/s]
matching: 100%|| 250000/250000 [00:07<00:00, 32591.43it/s]
drawing mosaic: 100%|| 250000/250000 [00:02<00:00, 104349.90it/s]
/usr/local/lib/python3.6/dist-packages/skimage/util/dtype.py:141: UserWarning: Possible precision loss when converting from float64 to uint8
.format(dtypeobj_in, dtypeobj_out))
<केंद्र>