summaryrefslogtreecommitdiff
path: root/html/examples/process_new.lua
diff options
context:
space:
mode:
authorscuri <scuri>2009-06-26 17:14:56 +0000
committerscuri <scuri>2009-06-26 17:14:56 +0000
commit193cd3427108bd127e09f391f7fe51f6b62590e9 (patch)
tree7dfd83dec634c15f87f578266f6fdb0df046613a /html/examples/process_new.lua
parent734afa90c3dda1232e9490d08346be4f2ffefec1 (diff)
*** empty log message ***
Diffstat (limited to 'html/examples/process_new.lua')
-rw-r--r--html/examples/process_new.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/html/examples/process_new.lua b/html/examples/process_new.lua
new file mode 100644
index 0000000..93ebcce
--- /dev/null
+++ b/html/examples/process_new.lua
@@ -0,0 +1,44 @@
+require"imlua"
+require"imlua_process"
+
+function save_histogram (hist, filename, format)
+ local height = 200 -- altura da imagem
+ local max = math.max(unpack(hist)) -- pega o maior valor do histograma
+ local n = table.getn(hist) + 1 -- zero-based
+ local image = im.ImageCreate(n, height, im.GRAY, im.BYTE) -- cria a imagem
+ local white = 255
+ local black = 0
+
+ local render = function (x, y, d, param)
+ local v = hist[x] / max
+ local h = v * height
+ if y <= h then return black end
+ return white
+ end
+
+ im.ProcessRenderOp(image, render, "histogram", {}, 0)
+ image:Save(filename, format)
+end
+
+local filename = "lena.jpg"
+
+local image = im.FileImageLoad(filename)
+
+save_histogram(im.CalcHistogram(image, 0, 0), "lena_histogram_R.gif", "GIF")
+save_histogram(im.CalcHistogram(image, 1, 0), "lena_histogram_G.gif", "GIF")
+save_histogram(im.CalcHistogram(image, 2, 0), "lena_histogram_B.gif", "GIF")
+save_histogram(im.CalcGrayHistogram(image, 0), "lena_histogram_gray.gif", "GIF")
+
+local r, g, b = im.ProcessSplitComponentsNew(image)
+r:Save("lena_r.jpg", "JPEG")
+g:Save("lena_g.jpg", "JPEG")
+b:Save("lena_b.jpg", "JPEG")
+
+local rgb = im.ProcessMergeComponentsNew({r, g, b})
+rgb:Save("lena_rgb.jpg", "JPEG")
+
+local replace = im.ProcessReplaceColorNew(image, { 146, 93, 145 }, { 255, 0, 255 })
+replace:Save("lena_replace.jpg", "JPEG")
+
+local bitmask = im.ProcessBitMaskNew(image, "01111010", im.BIT_XOR)
+replace:Save("lena_bitmask.jpg", "JPEG")