summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--html/en/history.html3
-rw-r--r--html/examples/analyze.lua29
-rw-r--r--src/lua5/imlua_aux.c4
-rw-r--r--src/process/im_analyze.cpp5
4 files changed, 20 insertions, 21 deletions
diff --git a/html/en/history.html b/html/en/history.html
index 8c7f892..4f100f5 100644
--- a/html/en/history.html
+++ b/html/en/history.html
@@ -37,6 +37,9 @@
<li dir="ltr"><span style="color: #008000"><span style="color: #ff0000">Fixed:</span><span
style="color: #000000"> alpha support in image:<strong>CopyPlane</strong>()
and in channel indexing in Lua.</span></span></li>
+ <li dir="ltr"><span style="color: #008000"><span style="color: #ff0000">Fixed:</span><span
+ style="color: #000000"> incomplete initialization of the array in
+ <strong>imAnalyzeMeasureArea</strong>.</span></span></li>
</ul>
<h3 dir="ltr">
<a href="http://sourceforge.net/projects/imtoolkit/files/3.5/">Version 3.5</a> (02/Oct/2009)</h3>
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
diff --git a/src/lua5/imlua_aux.c b/src/lua5/imlua_aux.c
index e472dca..b26df93 100644
--- a/src/lua5/imlua_aux.c
+++ b/src/lua5/imlua_aux.c
@@ -2,7 +2,7 @@
* \brief IM Lua 5 Binding
*
* See Copyright Notice in im_lib.h
- * $Id: imlua_aux.c,v 1.2 2009/08/04 21:35:26 scuri Exp $
+ * $Id: imlua_aux.c,v 1.3 2010/01/21 18:24:22 scuri Exp $
*/
#include <memory.h>
@@ -46,7 +46,7 @@ int imlua_newarrayint (lua_State *L, int *value, int count, int start)
lua_newtable(L);
for (i = 0; i < count; i++)
{
- lua_pushnumber(L, value[i]);
+ lua_pushinteger(L, value[i]);
lua_rawseti(L, -2, i+start);
}
return 1;
diff --git a/src/process/im_analyze.cpp b/src/process/im_analyze.cpp
index 02748f0..551f043 100644
--- a/src/process/im_analyze.cpp
+++ b/src/process/im_analyze.cpp
@@ -2,7 +2,7 @@
* \brief Image Analysis
*
* See Copyright Notice in im_lib.h
- * $Id: im_analyze.cpp,v 1.3 2009/11/20 18:59:08 scuri Exp $
+ * $Id: im_analyze.cpp,v 1.4 2010/01/21 18:24:23 scuri Exp $
*/
@@ -402,7 +402,8 @@ int imAnalyzeFindRegions(const imImage* image, imImage* NewImage, int connect, i
void imAnalyzeMeasureArea(const imImage* image, int* data_area, int region_count)
{
imushort* img_data = (imushort*)image->data[0];
- memset(data_area, 0, region_count*sizeof(imushort));
+
+ memset(data_area, 0, region_count*sizeof(int));
for (int i = 0; i < image->count; i++)
{