{"id":163663,"date":"2012-12-23T18:26:03","date_gmt":"2012-12-23T14:26:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=163663"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=163663","title":{"rendered":"<span class=\"post_title\">\u0418\u0433\u0440\u0430\u0435\u043c\u0441\u044f \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 Python<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u044f \u0440\u0435\u0448\u0438\u043b \u0432\u0437\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043e\u043d\u0430 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043d\u0430 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432.<br \/>  \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0434\u043b\u044f \u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0439:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/7ce\/65f\/f9d\/7ce65ff9daf3512829763b91cb41ef37.jpg\"\/><\/p>\n<h5>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h5>\n<p>  <\/p>\n<pre><code class=\"python\">import random from PIL import Image, ImageDraw #\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.   mode = int(input('mode:')) #\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043d\u043e\u043c\u0435\u0440 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f.  image = Image.open(&quot;temp.jpg&quot;) #\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.  draw = ImageDraw.Draw(image) #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f.  width = image.size[0] #\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0448\u0438\u0440\u0438\u043d\u0443.  height = image.size[1] #\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443. \t pix = image.load() #\u0412\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439.  <\/code><\/pre>\n<h5>\u041e\u0442\u0442\u0435\u043d\u043a\u0438 \u0441\u0435\u0440\u043e\u0433\u043e<\/h5>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u00ab\u0443\u0441\u0440\u0435\u0434\u043d\u0438\u0442\u044c\u00bb \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0438\u043a\u0441\u0435\u043b.  <\/p>\n<pre><code class=\"python\">if (mode == 0): \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] \t\t\tb = pix[i, j][1] \t\t\tc = pix[i, j][2] \t\t\tS = (a + b + c) \/\/ 3 \t\t\tdraw.point((i, j), (S, S, S)) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d6f\/b16\/557\/d6fb16557250c19df556f2c92a7b90b2.jpg\"\/><\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h5>\u0421\u0435\u043f\u0438\u044f<\/h5>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d0e\/8cd\/220\/d0e8cd2205cb730d288f8a08e700c7ac.png\"\/><br \/>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0435\u043f\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0432\u0437\u044f\u0442\u044c \u043a\u0430\u043a\u043e\u0439 \u2014 \u043d\u0438\u0431\u0443\u0434\u044c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442. <br \/>  middle = (R + G + B) \/ 3<br \/>  \u041f\u0435\u0440\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0430 ( R ) = middle + 2 * k<br \/>  \u0412\u0442\u043e\u0440\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0430 ( G ) = middle + k<br \/>  \u0422\u0440\u0435\u0442\u044c\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0430 ( B ) = middle  <\/p>\n<pre><code class=\"python\">if (mode == 1): \tdepth = int(input('depth:')) \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] \t\t\tb = pix[i, j][1] \t\t\tc = pix[i, j][2] \t\t\tS = (a + b + c) \/\/ 3 \t\t\ta = S + depth * 2 \t\t\tb = S + depth \t\t\tc = S \t\t\tif (a &gt; 255): \t\t\t\ta = 255 \t\t\tif (b &gt; 255): \t\t\t\tb = 255 \t\t\tif (c &gt; 255): \t\t\t\tc = 255 \t\t\tdraw.point((i, j), (a, b, c)) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/6b0\/530\/b9a\/6b0530b9a0c9b664f108b511f7018c0f.jpg\"\/><br \/>  depth = 30<\/p>\n<h5>\u041d\u0435\u0433\u0430\u0442\u0438\u0432<\/h5>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043d\u0435\u0433\u0430\u0442\u0438\u0432.<br \/>  \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0430 \u0432\u044b\u0447\u0435\u0441\u0442\u044c \u0438\u0437 255.  <\/p>\n<pre><code class=\"python\">if (mode == 2): \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] \t\t\tb = pix[i, j][1] \t\t\tc = pix[i, j][2] \t\t\tdraw.point((i, j), (255 - a, 255 - b, 255 - c)) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/84e\/f11\/b9a\/84ef11b9a0945df9347f96f8bb755b88.jpg\"\/><\/p>\n<h5>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0448\u0443\u043c\u043e\u0432<\/h5>\n<p>  \u0412\u043e\u0442 \u0442\u0443\u0442 \u0441\u043e\u0432\u0441\u0435\u043c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e.<br \/>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a \u043f\u0438\u043a\u0441\u0435\u043b\u0443 \u043a\u0430\u043a\u043e\u0435 \u2014 \u043d\u0438\u0431\u0443\u0434\u044c \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0431\u0440\u043e\u0441 \u044d\u0442\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0448\u0443\u043c\u043e\u0432.  <\/p>\n<pre><code class=\"python\">if (mode == 3): \tfactor = int(input('factor:')) \tfor i in range(width): \t\tfor j in range(height): \t\t\trand = random.randint(-factor, factor) \t\t\ta = pix[i, j][0] + rand \t\t\tb = pix[i, j][1] + rand \t\t\tc = pix[i, j][2] + rand \t\t\tif (a &lt; 0): \t\t\t\ta = 0 \t\t\tif (b &lt; 0): \t\t\t\tb = 0 \t\t\tif (c &lt; 0): \t\t\t\tc = 0 \t\t\tif (a &gt; 255): \t\t\t\ta = 255 \t\t\tif (b &gt; 255): \t\t\t\tb = 255 \t\t\tif (c &gt; 255): \t\t\t\tc = 255 \t\t\tdraw.point((i, j), (a, b, c)) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d46\/772\/43d\/d4677243dadcbbaed173e155b3e8de11.jpg\"\/><br \/>  factor = 70<\/p>\n<h5>\u042f\u0440\u043a\u043e\u0441\u0442\u044c<\/h5>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044f\u0440\u043a\u043e\u0441\u0442\u0438 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u0438\u043a\u0441\u0435\u043b\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u043e\u043d\u043e &gt; 0, \u0442\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u044f\u0440\u0447\u0435, \u0438\u043d\u0430\u0447\u0435 \u0442\u0435\u043c\u043d\u0435\u0435.  <\/p>\n<pre><code class=\"python\">if (mode == 4): \tfactor = int(input('factor:')) \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] + factor \t\t\tb = pix[i, j][1] + factor \t\t\tc = pix[i, j][2] + factor \t\t\tif (a &lt; 0): \t\t\t\ta = 0 \t\t\tif (b &lt; 0): \t\t\t\tb = 0 \t\t\tif (c &lt; 0): \t\t\t\tc = 0 \t\t\tif (a &gt; 255): \t\t\t\ta = 255 \t\t\tif (b &gt; 255): \t\t\t\tb = 255 \t\t\tif (c &gt; 255): \t\t\t\tc = 255 \t\t\tdraw.point((i, j), (a, b, c)) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/9ee\/a35\/632\/9eea356320c1e3dec5a7efbd50310c1a.jpg\"\/><br \/>  factor = 100<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d3a\/384\/8db\/d3a3848db8f57d260e0fe3540021c3f9.jpg\"\/><br \/>  factor = -100<\/p>\n<h5>\u0427\u0451\u0440\u043d\u043e \u2014 \u0431\u0435\u043b\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435<\/h5>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u044b \u043d\u0430\u0434\u043e \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043d\u0430 2 \u0433\u0440\u0443\u043f\u043f\u044b: \u0447\u0435\u0440\u043d\u044b\u0435 \u0438 \u0431\u0435\u043b\u044b\u0435.<br \/>  \u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a \u0447\u0435\u043c\u0443 \u0431\u043b\u0438\u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0438\u043a\u0441\u0435\u043b\u0430: \u043a \u0431\u0435\u043b\u043e\u043c\u0443 \u0446\u0432\u0435\u0442\u0443 \u0438\u043b\u0438 \u043a \u0447\u0451\u0440\u043d\u043e\u043c\u0443.  <\/p>\n<pre><code class=\"python\">if (mode == 5): \tfactor = int(input('factor:')) \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] \t\t\tb = pix[i, j][1] \t\t\tc = pix[i, j][2] \t\t\tS = a + b + c \t\t\tif (S &gt; (((255 + factor) \/\/ 2) * 3)): \t\t\t\ta, b, c = 255, 255, 255 \t\t\telse: \t\t\t\ta, b, c = 0, 0, 0 \t\t\tdraw.point((i, j), (a, b, c)) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/083\/aab\/726\/083aab726cf2a5c9f6903b54bfc5260e.jpg\"\/><br \/>  factor = 100<\/p>\n<h5>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h5>\n<p>  \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043a\u0438\u0441\u0442\u044c.  <\/p>\n<pre><code class=\"python\">image.save(&quot;ans.jpg&quot;, &quot;JPEG&quot;) del draw <\/code><\/pre>\n<h5>\u0418\u0442\u043e\u0433<\/h5>\n<p>  <\/p>\n<pre><code class=\"python\">import random from PIL import Image, ImageDraw    mode = int(input('mode:'))   image = Image.open(&quot;temp.jpg&quot;)   draw = ImageDraw.Draw(image)   width = image.size[0]   height = image.size[1]  \t pix = image.load()  if (mode == 0): \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] \t\t\tb = pix[i, j][1] \t\t\tc = pix[i, j][2] \t\t\tS = (a + b + c) \/\/ 3 \t\t\tdraw.point((i, j), (S, S, S)) if (mode == 1): \tdepth = int(input('depth:')) \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] \t\t\tb = pix[i, j][1] \t\t\tc = pix[i, j][2] \t\t\tS = (a + b + c) \/\/ 3 \t\t\ta = S + depth * 2 \t\t\tb = S + depth \t\t\tc = S \t\t\tif (a &gt; 255): \t\t\t\ta = 255 \t\t\tif (b &gt; 255): \t\t\t\tb = 255 \t\t\tif (c &gt; 255): \t\t\t\tc = 255 \t\t\tdraw.point((i, j), (a, b, c)) if (mode == 2): \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] \t\t\tb = pix[i, j][1] \t\t\tc = pix[i, j][2] \t\t\tdraw.point((i, j), (255 - a, 255 - b, 255 - c)) if (mode == 3): \tfactor = int(input('factor:')) \tfor i in range(width): \t\tfor j in range(height): \t\t\trand = random.randint(-factor, factor) \t\t\ta = pix[i, j][0] + rand \t\t\tb = pix[i, j][1] + rand \t\t\tc = pix[i, j][2] + rand \t\t\tif (a &lt; 0): \t\t\t\ta = 0 \t\t\tif (b &lt; 0): \t\t\t\tb = 0 \t\t\tif (c &lt; 0): \t\t\t\tc = 0 \t\t\tif (a &gt; 255): \t\t\t\ta = 255 \t\t\tif (b &gt; 255): \t\t\t\tb = 255 \t\t\tif (c &gt; 255): \t\t\t\tc = 255 \t\t\tdraw.point((i, j), (a, b, c)) if (mode == 4): \tfactor = int(input('factor:')) \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] + factor \t\t\tb = pix[i, j][1] + factor \t\t\tc = pix[i, j][2] + factor \t\t\tif (a &lt; 0): \t\t\t\ta = 0 \t\t\tif (b &lt; 0): \t\t\t\tb = 0 \t\t\tif (c &lt; 0): \t\t\t\tc = 0 \t\t\tif (a &gt; 255): \t\t\t\ta = 255 \t\t\tif (b &gt; 255): \t\t\t\tb = 255 \t\t\tif (c &gt; 255): \t\t\t\tc = 255 \t\t\tdraw.point((i, j), (a, b, c)) if (mode == 5): \tfactor = int(input('factor:')) \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] \t\t\tb = pix[i, j][1] \t\t\tc = pix[i, j][2] \t\t\tS = a + b + c \t\t\tif (S &gt; (((255 + factor) \/\/ 2) * 3)): \t\t\t\ta, b, c = 255, 255, 255 \t\t\telse: \t\t\t\ta, b, c = 0, 0, 0 \t\t\tdraw.point((i, j), (a, b, c)) image.save(&quot;ans.jpg&quot;, &quot;JPEG&quot;) del draw <\/code><\/pre>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/163663\/\"> http:\/\/habrahabr.ru\/post\/163663\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Python. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u044f \u0440\u0435\u0448\u0438\u043b \u0432\u0437\u044f\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043e\u043d\u0430 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043d\u0430 \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432.<br \/>  \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0434\u043b\u044f \u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0439:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/7ce\/65f\/f9d\/7ce65ff9daf3512829763b91cb41ef37.jpg\"\/><\/p>\n<h5>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h5>\n<p>  <\/p>\n<pre><code class=\"python\">import random from PIL import Image, ImageDraw #\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.   mode = int(input('mode:')) #\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043d\u043e\u043c\u0435\u0440 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f.  image = Image.open(&quot;temp.jpg&quot;) #\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.  draw = ImageDraw.Draw(image) #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f.  width = image.size[0] #\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0448\u0438\u0440\u0438\u043d\u0443.  height = image.size[1] #\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443. \t pix = image.load() #\u0412\u044b\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439.  <\/code><\/pre>\n<h5>\u041e\u0442\u0442\u0435\u043d\u043a\u0438 \u0441\u0435\u0440\u043e\u0433\u043e<\/h5>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u00ab\u0443\u0441\u0440\u0435\u0434\u043d\u0438\u0442\u044c\u00bb \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0438\u043a\u0441\u0435\u043b.  <\/p>\n<pre><code class=\"python\">if (mode == 0): \tfor i in range(width): \t\tfor j in range(height): \t\t\ta = pix[i, j][0] \t\t\tb = pix[i, j][1] \t\t\tc = pix[i, j][2] \t\t\tS = (a + b + c) \/\/ 3 \t\t\tdraw.point((i, j), (S, S, S)) <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d6f\/b16\/557\/d6fb16557250c19df556f2c92a7b90b2.jpg\"\/><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-163663","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/163663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=163663"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/163663\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=163663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=163663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=163663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}