mirror of https://github.com/GNOME/gimp.git
let the caller specify a region of interest. Call the progress function
2006-03-22 Sven Neumann <sven@gimp.org> * app/base/siox.[ch] (siox_foreground_extract): let the caller specify a region of interest. Call the progress function more often. * app/core/gimpdrawable-foreground-extract.c (gimp_drawable_foreground_extract_siox): pass a region of interest to siox_foreground_extract() to speed up the SIOX tool.
This commit is contained in:
parent
de7546f5c0
commit
aab10d11d2
|
@ -1,3 +1,12 @@
|
||||||
|
2006-03-22 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* app/base/siox.[ch] (siox_foreground_extract): let the caller
|
||||||
|
specify a region of interest. Call the progress function more often.
|
||||||
|
|
||||||
|
* app/core/gimpdrawable-foreground-extract.c
|
||||||
|
(gimp_drawable_foreground_extract_siox): pass a region of interest
|
||||||
|
to siox_foreground_extract() to speed up the SIOX tool.
|
||||||
|
|
||||||
2006-03-22 Michael Natterer <mitch@gimp.org>
|
2006-03-22 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
* tools/pdbgen/pdb/image.pdb: reordered vectors procedures.
|
* tools/pdbgen/pdb/image.pdb: reordered vectors procedures.
|
||||||
|
|
|
@ -35,18 +35,23 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include "config.h"
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
|
||||||
#include "libgimpmath/gimpmath.h"
|
#include "libgimpmath/gimpmath.h"
|
||||||
|
|
||||||
#include "base-types.h"
|
#include "base-types.h"
|
||||||
#include "base-enums.h"
|
|
||||||
#include "paint-funcs/paint-funcs.h"
|
#include "paint-funcs/paint-funcs.h"
|
||||||
|
|
||||||
#include "cpercep.h"
|
#include "cpercep.h"
|
||||||
#include "pixel-region.h"
|
#include "pixel-region.h"
|
||||||
|
#include "tile.h"
|
||||||
#include "tile-manager.h"
|
#include "tile-manager.h"
|
||||||
#include "siox.h"
|
#include "siox.h"
|
||||||
|
|
||||||
|
|
||||||
/* Thresholds in the mask:
|
/* Thresholds in the mask:
|
||||||
* pixels < SIOX_LOW are known background
|
* pixels < SIOX_LOW are known background
|
||||||
* pixels > SIOX_HIGH are known foreground
|
* pixels > SIOX_HIGH are known foreground
|
||||||
|
@ -774,17 +779,28 @@ siox_init (TileManager *pixels,
|
||||||
* @refinement: #SioxRefinementType
|
* @refinement: #SioxRefinementType
|
||||||
* @mask: a mask indicating sure foreground (255), sure background (0)
|
* @mask: a mask indicating sure foreground (255), sure background (0)
|
||||||
* and undecided regions ([1..254]).
|
* and undecided regions ([1..254]).
|
||||||
|
* @x1: region of interest
|
||||||
|
* @y1: region of interest
|
||||||
|
* @x2: region of interest
|
||||||
|
* @y2: region of interest
|
||||||
* @sensitivity: a double array with three entries specifing the accuracy,
|
* @sensitivity: a double array with three entries specifing the accuracy,
|
||||||
* a good value is: { 0.64, 1.28, 2.56 }
|
* a good value is: { 0.64, 1.28, 2.56 }
|
||||||
* @smoothness: boundary smoothness (a good value is 3)
|
* @smoothness: boundary smoothness (a good value is 3)
|
||||||
* @multiblob: allow multiple blobs (true) or only one (false)
|
* @multiblob: allow multiple blobs (true) or only one (false)
|
||||||
*
|
*
|
||||||
* Writes the resulting segmentation into @mask.
|
* Writes the resulting segmentation into @mask. The region of
|
||||||
|
* interest as specified using @x1, @y1, @x2 and @y2 defines the
|
||||||
|
* bounding box of the background and undecided areas. No changes to
|
||||||
|
* the mask are done outside this rectangle.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
siox_foreground_extract (SioxState *state,
|
siox_foreground_extract (SioxState *state,
|
||||||
SioxRefinementType refinement,
|
SioxRefinementType refinement,
|
||||||
TileManager *mask,
|
TileManager *mask,
|
||||||
|
gint x1,
|
||||||
|
gint y1,
|
||||||
|
gint x2,
|
||||||
|
gint y2,
|
||||||
gint smoothness,
|
gint smoothness,
|
||||||
const gdouble sensitivity[3],
|
const gdouble sensitivity[3],
|
||||||
gboolean multiblob,
|
gboolean multiblob,
|
||||||
|
@ -802,11 +818,15 @@ siox_foreground_extract (SioxState *state,
|
||||||
lab *surefg = NULL;
|
lab *surefg = NULL;
|
||||||
gint surebgcount = 0;
|
gint surebgcount = 0;
|
||||||
gint surefgcount = 0;
|
gint surefgcount = 0;
|
||||||
gint i, j;
|
gint n, tiles;
|
||||||
gfloat limits[3];
|
gfloat limits[3];
|
||||||
|
|
||||||
g_return_if_fail (state != NULL);
|
g_return_if_fail (state != NULL);
|
||||||
g_return_if_fail (mask != NULL && tile_manager_bpp (mask) == 1);
|
g_return_if_fail (mask != NULL && tile_manager_bpp (mask) == 1);
|
||||||
|
g_return_if_fail (x1 >= 0);
|
||||||
|
g_return_if_fail (x2 > x1 && x2 < tile_manager_width (mask));
|
||||||
|
g_return_if_fail (y1 >= 0);
|
||||||
|
g_return_if_fail (y2 > y1 && y2 < tile_manager_height (mask));
|
||||||
g_return_if_fail (smoothness >= 0);
|
g_return_if_fail (smoothness >= 0);
|
||||||
g_return_if_fail (progress_data == NULL || progress_callback != NULL);
|
g_return_if_fail (progress_data == NULL || progress_callback != NULL);
|
||||||
|
|
||||||
|
@ -826,7 +846,6 @@ siox_foreground_extract (SioxState *state,
|
||||||
|
|
||||||
siox_progress_update (progress_callback, progress_data, 0.0);
|
siox_progress_update (progress_callback, progress_data, 0.0);
|
||||||
|
|
||||||
|
|
||||||
if (refinement & SIOX_REFINEMENT_CHANGE_SENSITIVITY)
|
if (refinement & SIOX_REFINEMENT_CHANGE_SENSITIVITY)
|
||||||
{
|
{
|
||||||
refinement = SIOX_REFINEMENT_RECALCULATE;
|
refinement = SIOX_REFINEMENT_RECALCULATE;
|
||||||
|
@ -885,8 +904,6 @@ siox_foreground_extract (SioxState *state,
|
||||||
if (refinement & SIOX_REFINEMENT_ADD_BACKGROUND)
|
if (refinement & SIOX_REFINEMENT_ADD_BACKGROUND)
|
||||||
surebg = g_new (lab, surebgcount);
|
surebg = g_new (lab, surebgcount);
|
||||||
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
siox_progress_update (progress_callback, progress_data, 0.1);
|
siox_progress_update (progress_callback, progress_data, 0.1);
|
||||||
|
|
||||||
/* create inputs for color signatures */
|
/* create inputs for color signatures */
|
||||||
|
@ -900,6 +917,8 @@ siox_foreground_extract (SioxState *state,
|
||||||
|
|
||||||
if (! (refinement & SIOX_REFINEMENT_ADD_FOREGROUND))
|
if (! (refinement & SIOX_REFINEMENT_ADD_FOREGROUND))
|
||||||
{
|
{
|
||||||
|
gint i = 0;
|
||||||
|
|
||||||
for (;pr != NULL; pr = pixel_regions_process (pr))
|
for (;pr != NULL; pr = pixel_regions_process (pr))
|
||||||
{
|
{
|
||||||
const guchar *src = srcPR.data;
|
const guchar *src = srcPR.data;
|
||||||
|
@ -926,6 +945,8 @@ siox_foreground_extract (SioxState *state,
|
||||||
}
|
}
|
||||||
else if (! (refinement & SIOX_REFINEMENT_ADD_BACKGROUND))
|
else if (! (refinement & SIOX_REFINEMENT_ADD_BACKGROUND))
|
||||||
{
|
{
|
||||||
|
gint i = 0;
|
||||||
|
|
||||||
for ( ;pr != NULL; pr = pixel_regions_process (pr))
|
for ( ;pr != NULL; pr = pixel_regions_process (pr))
|
||||||
{
|
{
|
||||||
const guchar *src = srcPR.data;
|
const guchar *src = srcPR.data;
|
||||||
|
@ -952,7 +973,8 @@ siox_foreground_extract (SioxState *state,
|
||||||
}
|
}
|
||||||
else /* both changed */
|
else /* both changed */
|
||||||
{
|
{
|
||||||
j = 0;
|
gint i = 0;
|
||||||
|
gint j = 0;
|
||||||
|
|
||||||
for ( ;pr != NULL; pr = pixel_regions_process (pr))
|
for ( ;pr != NULL; pr = pixel_regions_process (pr))
|
||||||
{
|
{
|
||||||
|
@ -1018,6 +1040,12 @@ siox_foreground_extract (SioxState *state,
|
||||||
|
|
||||||
siox_progress_update (progress_callback, progress_data, 0.4);
|
siox_progress_update (progress_callback, progress_data, 0.4);
|
||||||
|
|
||||||
|
/* Reduce the working area to the region of interest */
|
||||||
|
x = x1;
|
||||||
|
y = y1;
|
||||||
|
width = x2 - x1;
|
||||||
|
height = y2 - y1;
|
||||||
|
|
||||||
/* Classify - the cached way....Better: Tree traversation? */
|
/* Classify - the cached way....Better: Tree traversation? */
|
||||||
|
|
||||||
#ifdef SIOX_DEBUG
|
#ifdef SIOX_DEBUG
|
||||||
|
@ -1030,9 +1058,11 @@ siox_foreground_extract (SioxState *state,
|
||||||
FALSE);
|
FALSE);
|
||||||
pixel_region_init (&mapPR, mask, x, y, width, height, TRUE);
|
pixel_region_init (&mapPR, mask, x, y, width, height, TRUE);
|
||||||
|
|
||||||
for (pr = pixel_regions_register (2, &srcPR, &mapPR);
|
tiles = (1 + width / TILE_WIDTH) * (1 + height / TILE_HEIGHT);
|
||||||
|
|
||||||
|
for (pr = pixel_regions_register (2, &srcPR, &mapPR), n = 0;
|
||||||
pr != NULL;
|
pr != NULL;
|
||||||
pr = pixel_regions_process (pr))
|
pr = pixel_regions_process (pr), n++)
|
||||||
{
|
{
|
||||||
const guchar *src = srcPR.data;
|
const guchar *src = srcPR.data;
|
||||||
guchar *map = mapPR.data;
|
guchar *map = mapPR.data;
|
||||||
|
@ -1048,6 +1078,7 @@ siox_foreground_extract (SioxState *state,
|
||||||
gfloat minbg, minfg, d;
|
gfloat minbg, minfg, d;
|
||||||
classresult *cr;
|
classresult *cr;
|
||||||
gint key;
|
gint key;
|
||||||
|
gint i;
|
||||||
|
|
||||||
if (*m < SIOX_LOW || *m > SIOX_HIGH)
|
if (*m < SIOX_LOW || *m > SIOX_HIGH)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1119,6 +1150,10 @@ siox_foreground_extract (SioxState *state,
|
||||||
src += srcPR.rowstride;
|
src += srcPR.rowstride;
|
||||||
map += mapPR.rowstride;
|
map += mapPR.rowstride;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (n % 8 == 0)
|
||||||
|
siox_progress_update (progress_callback, progress_data,
|
||||||
|
0.4 + 0.4 * ((gdouble) n / (gdouble) tiles));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SIOX_DEBUG
|
#ifdef SIOX_DEBUG
|
||||||
|
@ -1147,7 +1182,7 @@ siox_foreground_extract (SioxState *state,
|
||||||
siox_progress_update (progress_callback, progress_data, 0.9);
|
siox_progress_update (progress_callback, progress_data, 0.9);
|
||||||
|
|
||||||
/* smooth again - as user specified */
|
/* smooth again - as user specified */
|
||||||
for (i = 0; i < smoothness; i++)
|
for (n = 0; n < smoothness; n++)
|
||||||
smooth_mask (mask, x, y, width, height);
|
smooth_mask (mask, x, y, width, height);
|
||||||
|
|
||||||
/* search the biggest connected component again to kill jitter */
|
/* search the biggest connected component again to kill jitter */
|
||||||
|
|
|
@ -62,6 +62,10 @@ SioxState * siox_init (TileManager *pixels,
|
||||||
void siox_foreground_extract (SioxState *state,
|
void siox_foreground_extract (SioxState *state,
|
||||||
SioxRefinementType refinement,
|
SioxRefinementType refinement,
|
||||||
TileManager *mask,
|
TileManager *mask,
|
||||||
|
gint x1,
|
||||||
|
gint y1,
|
||||||
|
gint x2,
|
||||||
|
gint y2,
|
||||||
gint smoothness,
|
gint smoothness,
|
||||||
const gdouble sensitivity[3],
|
const gdouble sensitivity[3],
|
||||||
gboolean multiblob,
|
gboolean multiblob,
|
||||||
|
|
|
@ -123,6 +123,9 @@ gimp_drawable_foreground_extract_siox (GimpDrawable *mask,
|
||||||
gboolean multiblob,
|
gboolean multiblob,
|
||||||
GimpProgress *progress)
|
GimpProgress *progress)
|
||||||
{
|
{
|
||||||
|
gint x1, y1;
|
||||||
|
gint x2, y2;
|
||||||
|
|
||||||
g_return_if_fail (GIMP_IS_DRAWABLE (mask));
|
g_return_if_fail (GIMP_IS_DRAWABLE (mask));
|
||||||
g_return_if_fail (gimp_drawable_bytes (mask) == 1);
|
g_return_if_fail (gimp_drawable_bytes (mask) == 1);
|
||||||
|
|
||||||
|
@ -133,7 +136,20 @@ gimp_drawable_foreground_extract_siox (GimpDrawable *mask,
|
||||||
if (progress)
|
if (progress)
|
||||||
gimp_progress_start (progress, _("Foreground Extraction"), FALSE);
|
gimp_progress_start (progress, _("Foreground Extraction"), FALSE);
|
||||||
|
|
||||||
siox_foreground_extract (state, refinement, gimp_drawable_data (mask),
|
if (GIMP_IS_CHANNEL (mask))
|
||||||
|
{
|
||||||
|
gimp_channel_bounds (GIMP_CHANNEL (mask), &x1, &y1, &x2, &y2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x1 = 0;
|
||||||
|
y1 = 0;
|
||||||
|
x2 = gimp_item_width (GIMP_ITEM (mask));
|
||||||
|
y2 = gimp_item_height (GIMP_ITEM (mask));
|
||||||
|
}
|
||||||
|
|
||||||
|
siox_foreground_extract (state, refinement,
|
||||||
|
gimp_drawable_data (mask), x1, y1, x2, y2,
|
||||||
smoothness, sensitivity, multiblob,
|
smoothness, sensitivity, multiblob,
|
||||||
(SioxProgressFunc) gimp_progress_set_value,
|
(SioxProgressFunc) gimp_progress_set_value,
|
||||||
progress);
|
progress);
|
||||||
|
@ -141,10 +157,7 @@ gimp_drawable_foreground_extract_siox (GimpDrawable *mask,
|
||||||
if (progress)
|
if (progress)
|
||||||
gimp_progress_end (progress);
|
gimp_progress_end (progress);
|
||||||
|
|
||||||
gimp_drawable_update (mask,
|
gimp_drawable_update (mask, x1, y1, x2, y2);
|
||||||
0, 0,
|
|
||||||
gimp_item_width (GIMP_ITEM (mask)),
|
|
||||||
gimp_item_height (GIMP_ITEM (mask)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue