summaryrefslogtreecommitdiff
path: root/html/examples/analyze.lua
diff options
context:
space:
mode:
authorscuri <scuri>2010-01-21 18:24:22 +0000
committerscuri <scuri>2010-01-21 18:24:22 +0000
commit9e0b6cc2b063749832f1bf49109989917e0a0226 (patch)
tree582b7bfc72b696cc85afe8b70ec3186ba2ff671b /html/examples/analyze.lua
parent18116f799593a916d590239dbd5a5d6dbbb92b61 (diff)
Fixed: incomplete initialization of the array in imAnalyzeMeasureArea.
Diffstat (limited to 'html/examples/analyze.lua')
-rw-r--r--html/examples/analyze.lua29
1 files changed, 12 insertions, 17 deletions
diff --git a/html/examples/analyze.lua b/html/examples/analyze.lua
index 7f06496..bc4a78e 100644
--- a/html/examples/analyze.lua
+++ b/html/examples/analyze.lua
@@ -1,28 +1,23 @@
require"imlua"
require"imlua_process"
-local filename = "lena.jpg"
+local filename = "rice.png" -- image must be im.GRAY and im.BYTE for this script
local image = im.FileImageLoad(filename)
-local gray = im.ImageCreate(image:Width(), image:Height(), im.GRAY, image:DataType())
-local binary = im.ImageCreate(image:Width(), image:Height(), im.BINARY, image:DataType())
-local region = im.ImageCreate(image:Width(), image:Height(), im.GRAY, im.USHORT)
-
--- make it grayscale
-im.ConvertColorSpace(image, gray)
-gray:Save("lena_gray.jpg", "JPEG")
+local binary = im.ImageCreateBased(image, nil, nil, im.BINARY, nil)
+local region = im.ImageCreateBased(image, nil, nil, nil, im.USHORT)
-- make it binary
-im.ProcessSliceThreshold(gray, binary, 0, 128)
-binary:Save("lena_binary.jpg", "JPEG")
+im.ProcessPercentThreshold(image, binary, 70) --lots of background
-local count = im.AnalyzeFindRegions(binary, region, 4, 1)
+-- search for closed regions, don't count objects that touches the image borders
+local count = im.AnalyzeFindRegions(binary, region, 4, 0)
print("regions: ", count)
-local region2 = im.ImageCreate(image:Width(), image:Height(), im.GRAY, im.BYTE)
-im.ConvertDataType(region, region2, 0, 0, 0, 0)
+local area = im.AnalyzeMeasureArea(region, count)
+local major_slope, major_length, minor_slope, minor_length = im.AnalyzeMeasurePrincipalAxis(region, area, nil, nil, count)
-local region3 = im.ImageCreate(image:Width(), image:Height(), im.MAP, im.BYTE)
-im.ConvertColorSpace(region2, region3)
-region3:SetPalette(im.PaletteHighContrast(), 256)
-region3:Save("lena_region.gif", "GIF")
+print("object", "area", "major length", "minor length")
+for r=1, count do
+ print(r, area[r-1], string.format("%5.5g", major_length[r-1]), string.format("%5.5g", minor_length[r-1]))
+end