Advertisement
Guest User

Untitled

a guest
Apr 8th, 2016
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. function init()
  2.   setName("Differ")
  3.   setDesc("A poor man's edge detection")
  4.   setSize(100, 24+64+16+16+16+4)
  5.   addOutput(24+32)
  6.   addInput("Texture", 24+64+8)
  7.   addParameter("Delta", "Detection sensitivity", 24+64+16+8, 20, 1, 200)
  8.   addParameter("N'hood", "0 - Moore (normal), 1 - Moore (skinny), 2 - Von Neumann, 3 - Horizontal Only, 4 - Vertical Only", 24+64+16+16+8, 0, 0, 4)
  9. end
  10.  
  11. function apply()
  12.   size = getTileSize()
  13.   temp = {}
  14.   delta = getValue(1, 0, 0, 400)
  15.   neigh = getValue(2, 0, 0, 1)
  16.  
  17.   for i = 0, size*size - 1 do
  18.     temp[i] = 0
  19.     x = i%size
  20.     y = math.floor(i/size)
  21.     v = getValue(0, x, y, 1)
  22.     if neigh == 0 then
  23.       dif = math.max(math.abs(v - getValue(0, x + 1, y, 1)), math.abs(v - getValue(0, x + 1, y + 1, 1)), math.abs(v - getValue(0, x, y + 1, 1)), math.abs(v - getValue(0, x + 1, y - 1, 1)))
  24.     elseif neigh == 1 then
  25.       dif = math.max(math.abs(v - getValue(0, x + 1, y, 1)), math.abs(v - getValue(0, x + 1, y + 1, 1)), math.abs(v - getValue(0, x, y + 1, 1)))
  26.     elseif neigh == 2 then
  27.       dif = math.max(math.abs(v - getValue(0, x + 1, y, 1)), math.abs(v - getValue(0, x, y + 1, 1)))
  28.     elseif neigh == 3 then
  29.       dif = math.abs(v - getValue(0, x + 1, y, 1))
  30.     elseif neigh == 4 then
  31.       dif = math.abs(v - getValue(0, x, y + 1, 1))
  32.     end
  33.     if dif >= delta then temp[i] = 1 end
  34.   end
  35.  
  36.   for i = 0, size*size - 1 do
  37.     setPixel(0, i%size, math.floor(i/size), temp[i], temp[i], temp[i])
  38.   end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement