[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master e55594d: New Arithmetic operator to fill holes
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master e55594d: New Arithmetic operator to fill holes in a binary dataset |
Date: |
Thu, 26 Jul 2018 19:22:23 -0400 (EDT) |
branch: master
commit e55594de238dcc88df4c054a9a9e66754922e77a
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
New Arithmetic operator to fill holes in a binary dataset
The necessary library function was already there, so it wasn't too hard to
add this operator to Arithmetic. Currently the `maxsize' argument to the
library function in Arithmetic is `-1' (no maximum!). Maybe later we can
add a max hole size operand to fill-holes is well.
---
NEWS | 1 +
bin/arithmetic/arithmetic.c | 55 +++++++++++++++++++++++++++++++--------------
bin/arithmetic/arithmetic.h | 1 +
doc/gnuastro.texi | 17 +++++++++-----
4 files changed, 52 insertions(+), 22 deletions(-)
diff --git a/NEWS b/NEWS
index d4edc7f..388ec6d 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ GNU Astronomy Utilities NEWS -*-
outline -*-
- `set-A': Set a name (`A' in this case) for the popped dataset. This
allows only reading the dataset it into memory once and
possibly using it many times.
+ - `fill-holes': Flip background (0) pixels surrounded by foreground (1).
- `collapse-sum': collapse/remove a dimension by summing over it.
- `collapse-mean': collapse/remove a dimension by averaging over it.
- `collapse-number': Number of elements included in the collapse.
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index ba8ef38..c2a2bb1 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -503,8 +503,8 @@ wrapper_for_filter(struct arithmeticparams *p, char *token,
int operator)
/************* Other functions *************/
/***************************************************************/
static int
-arithmetic_binary_conn_sanity_checks(gal_data_t *in, gal_data_t *conn,
- char *operator)
+arithmetic_binary_sanity_checks(gal_data_t *in, gal_data_t *conn,
+ char *operator)
{
int conn_int;
@@ -552,19 +552,14 @@ arithmetic_erode_dilate(struct arithmeticparams *p, char
*token, int op)
gal_data_t *conn = operands_pop(p, token);
gal_data_t *in = operands_pop(p, token);
- /* Do the sanity checks and */
+ /* Do the sanity checks. */
+ conn_int=arithmetic_binary_sanity_checks(in, conn, token);
+
+ /* Do the operation. */
switch(op)
{
- case ARITHMETIC_OP_ERODE:
- conn_int=arithmetic_binary_conn_sanity_checks(in, conn, "erode");
- gal_binary_erode(in, 1, conn_int, 1);
- break;
-
- case ARITHMETIC_OP_DILATE:
- conn_int=arithmetic_binary_conn_sanity_checks(in, conn, "dilate");
- gal_binary_dilate(in, 1, conn_int, 1);
- break;
-
+ case ARITHMETIC_OP_ERODE: gal_binary_erode(in, 1, conn_int, 1); break;
+ case ARITHMETIC_OP_DILATE: gal_binary_dilate(in, 1, conn_int, 1); break;
default:
error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to fix the "
"problem. The operator code %d not recognized", __func__,
@@ -573,8 +568,6 @@ arithmetic_erode_dilate(struct arithmeticparams *p, char
*token, int op)
/* Push the result onto the stack. */
operands_add(p, NULL, in);
-
- /* Recall that`conn' was freed in the sanity check. */
}
@@ -592,8 +585,7 @@ arithmetic_connected_components(struct arithmeticparams *p,
char *token)
gal_data_t *in = operands_pop(p, token);
/* Basic sanity checks. */
- conn_int=arithmetic_binary_conn_sanity_checks(in, conn,
- "connected-components");
+ conn_int=arithmetic_binary_sanity_checks(in, conn, token);
/* Do the connected components labeling. */
gal_binary_connected_components(in, &out, conn_int);
@@ -610,6 +602,29 @@ arithmetic_connected_components(struct arithmeticparams
*p, char *token)
static void
+arithmetic_fill_holes(struct arithmeticparams *p, char *token)
+{
+ int conn_int;
+
+ /* Pop the two necessary operands. */
+ gal_data_t *conn = operands_pop(p, token);
+ gal_data_t *in = operands_pop(p, token);
+
+ /* Basic sanity checks. */
+ conn_int=arithmetic_binary_sanity_checks(in, conn, token);
+
+ /* Fill the holes */
+ gal_binary_holes_fill(in, conn_int, -1);
+
+ /* Push the result onto the stack. */
+ operands_add(p, NULL, in);
+}
+
+
+
+
+
+static void
arithmetic_invert(struct arithmeticparams *p, char *token)
{
gal_data_t *in = operands_pop(p, token);
@@ -958,6 +973,8 @@ reversepolish(struct arithmeticparams *p)
{ op=ARITHMETIC_OP_DILATE; nop=0; }
else if (!strcmp(token->v, "connected-components"))
{ op=ARITHMETIC_OP_CONNECTED_COMPONENTS; nop=0; }
+ else if (!strcmp(token->v, "fill-holes"))
+ { op=ARITHMETIC_OP_FILL_HOLES; nop=0; }
else if (!strcmp(token->v, "invert"))
{ op=ARITHMETIC_OP_INVERT; nop=0; }
else if (!strcmp(token->v, "interpolate-medianngb"))
@@ -1051,6 +1068,10 @@ reversepolish(struct arithmeticparams *p)
arithmetic_connected_components(p, token->v);
break;
+ case ARITHMETIC_OP_FILL_HOLES:
+ arithmetic_fill_holes(p, token->v);
+ break;
+
case ARITHMETIC_OP_INVERT:
arithmetic_invert(p, token->v);
break;
diff --git a/bin/arithmetic/arithmetic.h b/bin/arithmetic/arithmetic.h
index 4144006..67bff24 100644
--- a/bin/arithmetic/arithmetic.h
+++ b/bin/arithmetic/arithmetic.h
@@ -38,6 +38,7 @@ enum arithmetic_prog_operators
ARITHMETIC_OP_ERODE,
ARITHMETIC_OP_DILATE,
ARITHMETIC_OP_CONNECTED_COMPONENTS,
+ ARITHMETIC_OP_FILL_HOLES,
ARITHMETIC_OP_INVERT,
ARITHMETIC_OP_INTERPOLATE_MEDIANNGB,
ARITHMETIC_OP_COLLAPSE_SUM,
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index c3ab4fe..537ddb2 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -11599,6 +11599,13 @@ If your input dataset doesn't have a binary type, but
you know all its
values are 0 or 1, you can use the @code{uint8} operator (below) to convert
it to binary.
address@hidden fill-holes
+Flip background (0) pixels surrounded by foreground (1) in a binary
+dataset. This operator takes two operands (similar to
address@hidden): the first popped operand is the connectivity
+(to define a hole) and the second is the binary (0 or 1 valued) dataset to
+fill holes in.
+
@item invert
Invert an unsigned integer dataset. This is the only operator that ignores
blank values (which are set to be the maximum values in the unsigned
@@ -27204,11 +27211,11 @@ pixels will have a value of @code{-1}. The total
number of holes will be
written where @code{numholes} points to.
@end deftypefun
address@hidden void gal_binary_holes_fill (gal_data_t @code{*input}, int
@code{connectivity})
-Fill all the holes (0 valued pixels surrounded by 1 valued pixels) within a
-region of the binary @code{input} dataset. The connectivity of the holes
-can be set with @code{connectivity}. This function currently only works on
-a 2D dataset.
address@hidden void gal_binary_holes_fill (gal_data_t @code{*input}, int
@code{connectivity}, size_t @code{maxsize})
+Fill all the holes (0 valued pixels surrounded by 1 valued pixels) of the
+binary @code{input} dataset. The connectivity of the holes can be set with
address@hidden Holes larger than @code{maxsize} are not filled. This
+function currently only works on a 2D dataset.
@end deftypefun
@node Labeled datasets, Convolution functions, Binary datasets, Gnuastro
library
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master e55594d: New Arithmetic operator to fill holes in a binary dataset,
Mohammad Akhlaghi <=