Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "path"
- require "gd"
- local chemin1 = path({point(156, 118), point(748, 104)})
- local chemin2 = path({point(136, 172), point(737, 166)})
- local npaths = 10
- local chemins = {}
- local x1step = (chemin2[1].x-chemin1[1].x)/(npaths-1)
- local x2step = (chemin2[2].x-chemin1[2].x)/(npaths-1)
- local y1step = (chemin2[1].y-chemin1[1].y)/(npaths-1)
- local y2step = (chemin2[2].y-chemin1[2].y)/(npaths-1)
- for n = 1, npaths do
- table.insert(chemins, path({
- point(chemin1[1].x+(n-1)*x1step,
- chemin1[1].y+(n-1)*y1step),
- point(chemin1[2].x+(n-1)*x2step,
- chemin1[2].y+(n-1)*y2step)}
- ):subdivide())
- end
- local canvas = gd.createFromPng("frms/frm_1.png")
- local red = canvas:colorResolve(255, 0, 0)
- local f = io.open("fronts.txt", "w")
- local l1 = 30
- local l2 = 30
- local cnt = 0
- for frm = 10, 180, 5 do --2, 46, 3 do
- cnt = cnt + 1
- local inputpng = gd.createFromPng("diffs/diff_"..frm..".png")
- local pf0 = nil
- for nligne, chemin in ipairs(chemins) do
- local points = {}
- local ppv = {}
- local dppv = {}
- for _, p in chemin:points() do
- local c = inputpng:getPixel(p.x, p.y)
- local r = inputpng:red(c)
- local g = inputpng:green(c)
- local b = inputpng:blue(c)
- local i = (g/3-10)*3
- -- on voit dans cristal_diff.gif que l'intensite
- -- dominante est dans le vert
- table.insert(points, i)
- end
- for i = l1+1, #points-l1 do
- local c = 0
- for j = i-l1, i+l1 do
- c = c+points[j]
- end
- c = c/(2*l1+1)
- if ppv then
- table.insert(ppv, {i, c})
- end
- end
- for i = l2+1, #points-l2 do
- local c1, c2 = 0, 0
- for j = 1, l2 do
- c1 = c1+points[i-j]
- c2 = c2+points[i+j]
- end
- c1, c2 = c1/l2, c2/l2
- table.insert(dppv, {i, c2-c1})
- end
- local avg = 0
- for _, p in ipairs(ppv) do
- avg = avg + p[2]
- end
- avg = avg / #ppv
- local ph = 0
- --nb de points qui sont au dessus de la moyenne
- for _, p in ipairs(ppv) do
- if p[2] < avg then
- ph = ph + 1
- end
- end
- local mind = 1
- for i, p in ipairs(dppv) do
- if p[2] < dppv[mind][2] then
- mind = i
- end
- end
- local pfront = dppv[mind][1]
- local pf = chemin[pfront]
- if pf then
- f:write(cnt.."\t"
- ..math.floor(pf.x).."\t"
- ..math.floor(pf.y).."\n")
- if pf0 then
- canvas:line(pf0.x, pf0.y, pf.x, pf.y,
- red)
- end
- end
- pf0 = pf
- end
- io.write(frm.."\t")
- if cnt % 8 == 0 then
- io.write("\n")
- end
- end
- f:close()
- canvas:png("fronts.png")
- io.write("\n")
Advertisement
Add Comment
Please, Sign In to add comment