Skip to content

Commit

Permalink
added pixel remapping func
Browse files Browse the repository at this point in the history
  • Loading branch information
oguyon committed Sep 22, 2023
1 parent 57ef928 commit 9cd744d
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/COREMOD_arith/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/COREMOD_arith/COREMOD_arith.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#include "image_set_row.h"
#include "image_setzero.h"

#include "image_pixremap.h"

#include "image_total.h"
#include "imfunctions.h"

Expand Down Expand Up @@ -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;
}

Expand Down
158 changes: 158 additions & 0 deletions src/COREMOD_arith/image_pixremap.c
Original file line number Diff line number Diff line change
@@ -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; pixi<nbpix; pixi++)
{
imgout.im->array.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;
}
6 changes: 6 additions & 0 deletions src/COREMOD_arith/image_pixremap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef COREMOD_ARITH_PIXREMAP_H
#define COREMOD_ARITH_PIXREMAP_H

errno_t CLIADDCMD_COREMODE_arith__pixremap();

#endif

0 comments on commit 9cd744d

Please sign in to comment.