BlenderCN论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1348|回复: 3

blender中处理图片的笔记

[复制链接]
发表于 2014-4-18 22:09:01 | 显示全部楼层 |阅读模式
本帖最后由 luxuy 于 2014-4-18 22:11 编辑

1.如何取得图片像素信息

http://lists.blender.org/pipermail/bf-blender-cvs/2011-April/035179.htmlhttp://blender.stackexchange.com/questions/3673/why-is-accessing-image-data-so-slow
Image pixel acces, through Image.pixels as floating point values.访问pixel得到的而是浮点数。It's not the most efficient solution, but this can be optimized later. It'sbest to copy out all the pixels at once into a list, rather than accessingthem one by one.最有效率的方法是将整个pixels数据一汽考出来,而不是直接一个一个像素访问。
2.如何直接在blender中用python创建图片http://blender.stackexchange.com/questions/643/is-it-possible-to-create-image-data-and-save-to-a-file-from-a-script


3.代码片段
  1. >>> pixels = D.images[-1].pixels
  2. >>> len(pixels)
  3. 8294400
复制代码
  1. img = bpy.data.images['Untitled']

  2. pixels = img.pixels[:] # create a copy

  3. # Use the tuple objects, which is way faster than direct access to Image.pixels
  4. for i in range(0, len(pixels), 4):
  5.     pixels[i] = 1.0 - pixels[i] # invert red channel

  6. # Write back to image.
  7. # Slice notation here means to replace in-place, not sure if it's faster...
  8. img.pixels[:] = pixels

  9. # Should probably update image
  10. img.update()
复制代码



4.解释
所有像素从0,1,2,3……开始编号,
0----r
1----g
2----b
3----a

比如300x300的图片,pixels就是300*300*4=360000

5.辅助工具

xxx.png

发表于 2014-4-20 00:31:01 | 显示全部楼层
相关基础笔记 关于贴图像素
http://bbs.blendercn.org/forum.p ... &extra=page%3D6
回复 支持 反对

使用道具 举报

发表于 2014-4-26 23:37:04 | 显示全部楼层
我试了试,出现如下的错误(V2.7):
>>> for i in range(0,len(pixels),4):
...     pixels[i]=1.0-pixels[i]
...     
Traceback (most recent call last):
  File "<blender_console>", line 2, in <module>
TypeError: 'tuple' object does not support item assignment

最后改成这样才行:
import bpy

img = bpy.data.images['Untitled']

pixels = img.pixels[:] # create a copy
pixels = list(pixels)

# Use the tuple objects, which is way faster than direct access to Image.pixels
for i in range(0, len(pixels)):
    pixels[i] = 1.0#assign to white color

# Write back to image.
# Slice notation here means to replace in-place, not sure if it's faster...
pixels=tuple(pixels)
img.pixels[:] = pixels

# Should probably update image
img.update()

点评

谢谢更正  详情 回复 发表于 2014-4-27 14:33
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-4-27 14:33:18 | 显示全部楼层
learn 发表于 2014-4-26 23:37
我试了试,出现如下的错误(V2.7):
>>> for i in range(0,len(pixels),4):
...     pixels=1.0-pixels

谢谢更正
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

Blender最新中文教学视频|Blender头条|小黑屋|手机版|Archiver|Blender中国 ( 蜀ICP备17002929号 )360网站安全检测平台

GMT+8, 2019-12-6 07:15 , Processed in 0.019596 second(s), 24 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表