-
Notifications
You must be signed in to change notification settings - Fork 2
/
edge_detect.lua
41 lines (38 loc) · 1.16 KB
/
edge_detect.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--original made by navot
function init()
setName("Edge Detect")
setDesc("Highlights edges")
setSize(120, 24+64+8+8+18+7+4)
addOutput(24+32)
addInput("Texture", 24+64+8+8)
addParameter("Intensity", "Height intensity", 24+64+8+8+18, 100, 0, -1, true)
end
function apply()
sobelH = {-1, -2, -1, 0, 0, 0, 1, 2, 1}
sobelV = {-1, 0, 1, -2, 0, 2, -1, 0, 1}
cDat = { }
tileSize = getTileSize()
for i=0, tileSize*tileSize-1 do
x = i%tileSize
y = math.floor(i/tileSize)
cr = 0
cg = 0
cb = 0
cgrayV = 0
cgrayH = 0
for k=0, 2 do
for j=0, 2 do
t = j+k*3
tr, tg, tb = getValue(0, x+k-1, y+j-1, 1)
cgray = (cr+cg+cb)/3*getValue(1, 0, 0, 100)
tgray = (tr+tg+tb)/3*getValue(1, 0, 0, 100)
cgrayV = (cgrayV+tgray*sobelV[t+1])
cgrayH = (cgrayH+tgray*-sobelH[t+1])
end
end
cr = math.sqrt(cgrayV*cgrayV+cgrayH*cgrayH)*getValue(1, 0, 0, 100)
cg = cr
cb = cr
setPixel(0, x, y, cr, cg, cb)
end
end