diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-03-28 23:51:12 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-03-28 23:51:12 +0000 |
commit | 4c070c9e299dc99d2fd5015fddb4991a0aa522c5 (patch) | |
tree | 5a327ccf7fca16158402d9f45a9818cc75f1ac49 /editor/specialty | |
parent | 00cbe6aa8471362bd6d0589c957c37023bb54d64 (diff) | |
download | netpbm-mirror-4c070c9e299dc99d2fd5015fddb4991a0aa522c5.tar.gz netpbm-mirror-4c070c9e299dc99d2fd5015fddb4991a0aa522c5.tar.xz netpbm-mirror-4c070c9e299dc99d2fd5015fddb4991a0aa522c5.zip |
Add -gradient
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2423 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor/specialty')
-rw-r--r-- | editor/specialty/pgmmorphconv.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/editor/specialty/pgmmorphconv.c b/editor/specialty/pgmmorphconv.c index abc4e718..5079e19f 100644 --- a/editor/specialty/pgmmorphconv.c +++ b/editor/specialty/pgmmorphconv.c @@ -116,6 +116,18 @@ erode( bit** template, int trowso2, int tcolso2, } /* erode */ +static void +subtract(gray** in1_image, gray** in2_image, gray** out_image, + int rows, int cols ){ + + int c, r; + + for( c=0; c<cols; ++c) + for( r=0; r<rows; ++r ) + out_image[r][c] = in1_image[r][c] - in2_image[r][c]; +} + + /************************************************************ * Main @@ -126,7 +138,7 @@ int main( int argc, char* argv[] ){ int argn; char operation; - const char* usage = "-dilate|-erode|-open|-close <templatefile> [pgmfile]"; + const char* usage = "-dilate|-erode|-open|-close|-gradient <templatefile> [pgmfile]"; FILE* tifp; /* template */ int tcols, trows; @@ -163,6 +175,8 @@ int main( int argc, char* argv[] ){ if( pm_keymatch( argv[argn], "-open", 2 )) { operation='o'; argn++; } else if( pm_keymatch( argv[argn], "-close", 2 )) { operation='c'; argn++; } + else + if( pm_keymatch( argv[argn], "-gradient", 2 )) { operation='g'; argn++; } if( argn == argc ) pm_usage( usage ); @@ -238,6 +252,18 @@ int main( int argc, char* argv[] ){ dilated_image, out_image, rows, cols); pgm_freearray( dilated_image, rows ); } + else if( operation == 'g' ){ + gray ** dilated_image, ** eroded_image; + dilated_image = pgm_allocarray( cols, rows ); + eroded_image = pgm_allocarray( cols, rows ); + templatecount = dilate(template, trowso2, tcolso2, + in_image, dilated_image, rows, cols); + templatecount = erode(template, trowso2, tcolso2, + in_image, eroded_image, rows, cols); + subtract(dilated_image, eroded_image, out_image, rows, cols); + pgm_freearray( dilated_image, rows ); + pgm_freearray( eroded_image, rows ); + } if(templatecount == 0 ) pm_error( "The template was empty!" ); |