Skip to content

Instantly share code, notes, and snippets.

@nagat01
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nagat01/bb9b79b1489a18d03408 to your computer and use it in GitHub Desktop.
Save nagat01/bb9b79b1489a18d03408 to your computer and use it in GitHub Desktop.
# The MIT License (MIT)
#
# Copyright (c) 2015 nagat01
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#!BPY
import bpy
import os
import numpy
# file = os.environ['HOMEPATH'] + '/My Documents/blur_result.png'
file = # ここに結果の出力先にしたい画像ファイルを指定してください
bpy.ops.render.render()
bpy.data.images['Render Result'].save_render(filepath = file)
img = bpy.data.images.load(file)
w = img.size[0]
h = img.size[1]
c = img.channels
ps = numpy.array(img.pixels)
lengthes = [8, 4, 2, 1] # ここに書いたピクセル数分だけ移動する処理を繰り返すので、ぼかしの強さを調節できます
divisor = 16 ** len(lengthes)
for len in lengthes:
for (dx, dy, endX, endY) in [(w*c, c, h, w), (c, w*c, w, h)]:
for (start, end, sign) in [(0, endX, 1), (endX-1, -1, -1)]:
dir = sign * dx
diff = dir * len
for y in range(0, dy*endY, dy):
for x in range(start*dx, end*dx - diff, dir):
for i in range(y + x, y + x + c):
ps[i] = ps[i] + ps[i + diff]
for x in range(end*dx - diff, end*dx, dir):
for i in range(y + x, y + x + c):
ps[i] = ps[i] * 2
for y in range(0, h*w*c, w*c):
for x in range(0, w*c, c):
for i in range(y + x, y + x + c):
ps[i] = ps[i] / divisor
img.pixels = ps.flatten()
img.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment