【Python】關(guān)于圖片操作(續(xù))
與上篇內(nèi)容區(qū)別:將導(dǎo)入圖片的分別率大小改變再進(jìn)行操作。
__author__ = "RhinoCode BiliBili"
__version__ = "2023.03.30"
import System.Drawing as sd
import Rhino.Geometry as rg
#導(dǎo)入圖片
image_path = "D:\LG\Record\C_封面\gg.jpg"
image = sd.Bitmap(image_path)
#獲取圖片分辨率
width, height = image.Width, image.Height
#改變圖片分別率
re_width, re_height = int(width/10), int(height/10)
resize_image = sd.Bitmap(re_width,re_height)
graphics = sd.Graphics.FromImage(resize_image)
graphics.DrawImage(image,0,0,re_width,re_height)
graphics.Dispose()
#在圖片范圍內(nèi)生成點(diǎn),點(diǎn)的z值為點(diǎn)對應(yīng)圖片位置顏色RGB的B通道值
colors = []
points = []
for x in range(re_width):
? ? for y in range(re_height):
? ? ? ? color = resize_image.GetPixel(x,y)
? ? ? ? colors.append(color)
? ? ? ? point = rg.Point3d(x,y,color.B/100)
? ? ? ? points.append(point)
#輸出
a = colors
b = points