diff --git a/src/COREMOD_arith/CMakeLists.txt b/src/COREMOD_arith/CMakeLists.txt index 8db5880c..939f12a5 100644 --- a/src/COREMOD_arith/CMakeLists.txt +++ b/src/COREMOD_arith/CMakeLists.txt @@ -10,6 +10,7 @@ set(SOURCEFILES image_crop.c image_cropmask.c image_merge3D.c + image_pixremap.c image_set_1Dpixrange.c image_set_2Dpix.c image_set_col.c @@ -33,6 +34,7 @@ set(INCLUDEFILES image_crop.h image_cropmask.h image_merge3D.h + image_pixremap.h image_set_1Dpixrange.h image_set_2Dpix.h image_set_col.h diff --git a/src/COREMOD_arith/COREMOD_arith.c b/src/COREMOD_arith/COREMOD_arith.c index 2e901839..9effff08 100644 --- a/src/COREMOD_arith/COREMOD_arith.c +++ b/src/COREMOD_arith/COREMOD_arith.c @@ -61,6 +61,8 @@ #include "image_set_row.h" #include "image_setzero.h" +#include "image_pixremap.h" + #include "image_total.h" #include "imfunctions.h" @@ -100,6 +102,8 @@ static errno_t init_module_CLI() CLIADDCMD_COREMOD_arith__imset_row(); CLIADDCMD_COREMOD_arith__imsetzero(); + CLIADDCMD_COREMODE_arith__pixremap(); + return RETURN_SUCCESS; } diff --git a/src/COREMOD_arith/image_pixremap.c b/src/COREMOD_arith/image_pixremap.c new file mode 100644 index 00000000..a73b1d27 --- /dev/null +++ b/src/COREMOD_arith/image_pixremap.c @@ -0,0 +1,158 @@ +#include "CommandLineInterface/CLIcore.h" + + +// input image +// +static char *insname; + + +// mapping array +// same size as output, values are pix index pointing to input +// datatype = int32 +// negative value are not mapped +// +static char *mapsname; + + +// output (remapped) image +// +static char *outsname; + + + + + +static CLICMDARGDEF farg[] = +{ + { + CLIARG_IMG, + ".insname", + "input name", + "inim", + CLIARG_VISIBLE_DEFAULT, + (void **) &insname, + NULL + }, + { + CLIARG_IMG, + ".masksname", + "mask stream name", + "maskim", + CLIARG_VISIBLE_DEFAULT, + (void **) &mapsname, + NULL + }, + { + CLIARG_IMG, + ".outsname", + "output stream name", + "outim", + CLIARG_VISIBLE_DEFAULT, + (void **) &outsname, + NULL + } +}; + + + + + +static CLICMDDATA CLIcmddata = +{ + "pixremap", "pixel remapping of image", CLICMD_FIELDS_DEFAULTS +}; + +// detailed help +static errno_t help_function() +{ + printf("Remap input image to ouput image by pixel lookup\n"); + + return RETURN_SUCCESS; +} + + + + + + + +static errno_t compute_function() +{ + DEBUG_TRACE_FSTART(); + + // connect to input + // + IMGID imgin = mkIMGID_from_name(insname); + resolveIMGID(&imgin, ERRMODE_ABORT); + int64_t insize = imgin.md->size[0]*imgin.md->size[1]; + + IMGID imgmap = mkIMGID_from_name(insname); + resolveIMGID(&imgmap, ERRMODE_ABORT); + + // read map size + // Note: currently assumes 2D ... to be updated + // + uint32_t xsize = imgmap.md->size[0]; + uint32_t ysize = imgmap.md->size[1]; + + // CONNNECT TO OR CREATE OUTPUT STREAM + IMGID imgout = stream_connect_create_2Df32(outsname, xsize, ysize); + + + // build mapping table + // + uint64_t nbpix = 0; + for(uint64_t ii = 0; ii < xsize*ysize; ii++) + { + int64_t pixindex = imgmap.im->array.SI64[ii]; + if ( ( pixindex > -1 ) + && ( pixindex < insize) ) + { + nbpix ++; + } + } + + uint64_t * __restrict map_outpixindex = (uint64_t*) malloc(sizeof(uint64_t) * nbpix); + uint64_t * __restrict map_inpixindex = (uint64_t*) malloc(sizeof(uint64_t) * nbpix); + + + INSERT_STD_PROCINFO_COMPUTEFUNC_INIT; + + + + INSERT_STD_PROCINFO_COMPUTEFUNC_LOOPSTART + { + for(uint64_t pixi=0; pixiarray.F[map_outpixindex[pixi]] = imgout.im->array.F[map_inpixindex[pixi]]; + } + processinfo_update_output_stream(processinfo, imgout.ID); + + } + INSERT_STD_PROCINFO_COMPUTEFUNC_END + + free(map_outpixindex); + free(map_inpixindex); + + DEBUG_TRACE_FEXIT(); + return RETURN_SUCCESS; +} + + + + + +INSERT_STD_FPSCLIfunctions + + + + +// Register function in CLI +errno_t +CLIADDCMD_COREMODE_arith__pixremap() +{ + + INSERT_STD_CLIREGISTERFUNC + + return RETURN_SUCCESS; +} diff --git a/src/COREMOD_arith/image_pixremap.h b/src/COREMOD_arith/image_pixremap.h new file mode 100644 index 00000000..20729b8d --- /dev/null +++ b/src/COREMOD_arith/image_pixremap.h @@ -0,0 +1,6 @@ +#ifndef COREMOD_ARITH_PIXREMAP_H +#define COREMOD_ARITH_PIXREMAP_H + +errno_t CLIADDCMD_COREMODE_arith__pixremap(); + +#endif