2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

①Pythonで画像から色情報抜き出す、②PythonでShade3Dスクリプトで濃淡絵を書く、③3Dプリンタで書き出す

Posted at

①Pythonで画像から色情報抜き出す
(1)画像を準備(縦横400pixcel(マス目は40x40))
400x400.jpg
(2)Pythonで色情報を抜き出す

out_img.py
#coding: utf-8

from PIL import Image

im = Image.open("./400x400.jpg")
rgb_im = im.convert('RGB')

f = open('./Ein400x400.txt', 'w')

for i in range(5,401,10):
    f.write("(\n")
    for j in range(5,401,10):
        r, g, b = rgb_im.getpixel((i, j))
        f.write("("+str(((i/5)+1)/2) +"," + str(((j/5)+1)/2) + "," + str(r) + "),\n")
    f.write("),\n")

f.close()

②PythonでShade3Dスクリプトで濃淡絵を書く
(1)スクリプト

script_for_shade3d.py
import math
import random
scene = xshade.scene()
scene.begin_creating()

a = ((
(1,1,66),
(1,2,64),



(40,39,130),
(40,40,120),
),
)

for n in range(0,40,1):
	for m in range(0,40,1):

		s = 0.5
		x = n
		y = 0
		z = m
		hgt = 8 - a[n][m][2] * 8 / 255 

		scene.create_primitive_box(None, 3, True, 1, 1, 1, [x+s, y-s, z-s], [x+s, y-s, z+s], [x-s,y-s, z+s], [x-s, y-s, z-s], [0, 2+hgt, 0], True, True)

scene.end_creating()

(2)Shade3D

35model.jpg

③3Dプリンタで書き出す
(1)
rCIMG3069.jpg

(2)
rCIMG3073.jpg

(3)
35_2a.jpg

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?