关于im lib的问题
lua吧
全部回复
仅看楼主
level 6
image:save的时候image里面到底有什么?
我看贴吧前辈给的例子里面
local filename = "gaoyue.png"
image = im.FileImageLoad(filename)
r = image[0]
g = image[1]
b = image[2]
之后 直接修改rgb3个表里的值也会更改最后的图片
这里rgb难道是指针吗
下面po我的代码 黑白化之后 用flood_fill递归写了个线段整理 然后再image:save就没有反应了
求解答!谢谢!
--local li
bp
ng = require'libpng'
require "imlua"
local filename = "gaoyue.png"
image = im.FileImageLoad(filename)
r = image[0]
g = image[1]
b = image[2]
function largest(a,b,c,d)
if (a>=b) and (a>=c) and(a>=d) then
return a
end
if (b>=a) and (b>=c) and(b>=d) then
return b
end
if (c>=a) and (c>=b) and(c>=d) then
return c
end
if (d>=b) and (d>=c) and(d>=a) then
return d
end
end
function flood_fill(x,y,mark)
if ((x+1)<=(image:Height())) then
if r[x+1][y]==255 and (flag[x+1][y]==0) then
length[mark]=length[mark+1]
flag[x+1][y]=mark
flood_fill(x+1,y,mark)
print(x," ",y," ",mark)
end
end
if ((y+1)<=(image:Width())) then
if r[x][y+1]==255 and (flag[x][y+1]==0) then
length[mark]=length[mark+1]
flag[x][y+1]=mark
flood_fill(x,y+1,mark)
print(x," ",y," ",mark)
end
end
return
end
for row = 1, image:Height() - 2 do
for column = 1, image:Width() - 2 do
print(row)
--check1=r[row-1][column]-r[row][column]+g[row-1][column]-g[row][column]+b[row-1][column]-b[row][column]
check2=r[row+1][column]-r[row][column]+g[row+1][column]-g[row][column]+b[row+1][column]-b[row][column]
--check3=r[row][column-1]-r[row][column]+g[row][column-1]-g[row][column]+b[row][column-1]-b[row][column]
check4=r[row][column+1]-r[row][column]+g[row][column+1]-g[row][column]+b[row][column+1]-b[row][column]
check=largest(0,check2,0,check4)
if check>30 then
r[row][column] = 0
g[row][column] = 0
b[row][column] = 0
else
r[row][column] = 255
g[row][column] = 255
b[row][column] = 255
end
end
end
--标记数组初始化
flag={}
length={}
for row = 1, image:Height() do
flag[row]={}
for column = 1, image:Width() do
flag[row][column]=0
length[column+(image:Width())*(row-1)]=0
end
end
count=0
--标记线段
for row = 1, image:Height() do
for column = 1, image:Width() do
if (flag[row][column]==0) and (r[row][column]==255) then
count=count+1
flood_fill(row,column,count)
end
end
end
image:Save("test.bmp", "BMP")
2015年01月11日 15点01分 1
level 8
.... 好像在lua里的table 都是一个指向table的指针
比如
a={}
a.c=1
b=a
print(b.c) -->1
b.d=2
print(a.d) -->2
我所知道的就是这些,关于image里面是什么,官方文档应该有
http://www.tecgraf.puc-rio.br/im
2015年01月13日 10点01分 2
wtf 竟然真的是指针
2015年01月13日 12点01分
with exit code 1是什么错误?
2015年01月13日 12点01分
回复
Faceless�ڸ�
:返回值是1的错误[委屈]
2015年01月14日 04点01分
@czfshine [汗]跑完了 现在告诉我not enough memory。。。只是一个500*500像素图的线段递归……
2015年01月14日 05点01分
level 13

2015年01月13日 11点01分 3
..............你等级怎么这么高
2015年01月13日 12点01分
回复
Faceless�ڸ�
:我是很早很早就来了好不好。
2015年01月13日 12点01分
1