IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15996


Ignore:
Timestamp:
Jan 4, 2008, 2:06:49 AM (18 years ago)
Author:
eugene
Message:

initial release of the histogram 3d color cube

Location:
branches/eam_branch_20071222/Ohana/src/kapa2
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20071222/Ohana/src/kapa2/Makefile

    r15935 r15996  
    7878$(SRC)/PSimage.$(ARCH).o                  $(SRC)/PSPixmap.$(ARCH).o           \
    7979$(SRC)/PSOverlay.$(ARCH).o                $(SRC)/SetChannel.$(ARCH).o         \
    80 $(SRC)/SetColorScale.$(ARCH).o
     80$(SRC)/SetColorScale.$(ARCH).o            $(SRC)/ColorCube.$(ARCH).o          \
     81$(SRC)/ColorHistogram.$(ARCH).o           $(SRC)/sort.$(ARCH).o
    8182
    8283OBJ  =  $(KAPA)
  • branches/eam_branch_20071222/Ohana/src/kapa2/include/constants.h

    r15935 r15996  
    1212# define NCHANNELS 3
    1313# define NPIXELS_DYNAMIC 128
    14 # define NPIXELS_STATIC 1024
     14
     15// XXX for the moment, this is set to match the values in SetColorScale3D_CC
     16# define NPIXELS_STATIC 3000
    1517
    1618# define PAD1  3
     
    3335typedef enum {
    3436    KAPA_SCALE_1D,
    35     KAPA_SCALE_3D
     37    KAPA_SCALE_3D_RUFF,
     38    KAPA_SCALE_3D_FULL
    3639} KapaColorScaleMode;
    3740
     
    4750  LABELLR
    4851} KapaLabelMode;
     52
     53typedef enum {
     54  KAPA_CHANNEL_RED,
     55  KAPA_CHANNEL_GREEN,
     56  KAPA_CHANNEL_BLUE,
     57} KapaChannels;
     58
     59// use an enum to identify the 3 dimensions:
     60typedef enum {
     61  CC_X,
     62  CC_Y,
     63  CC_Z,
     64} CCDimen;
    4965
    5066/* EVENT_MASK consists of:
  • branches/eam_branch_20071222/Ohana/src/kapa2/include/prototypes.h

    r15935 r15996  
    142142void          SetColorScale       PROTO((Graphic *graphic, KapaImageWidget *image));
    143143void          SetColorScale1D     PROTO((Graphic *graphic, KapaImageWidget *image));
    144 void          SetColorScale3D     PROTO((Graphic *graphic, KapaImageWidget *image));
     144int           SetColorScale3D     PROTO((Graphic *graphic, KapaImageWidget *image));
    145145void          Remap               PROTO((Graphic *graphic, KapaImageWidget *image));
    146146void          Remap8              PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
     
    223223void InvertButton (Graphic *graphic, Button *button);
    224224void bDrawOverlay (KapaImageWidget *image, int N);
     225
     226/* color cube tools */
     227CCNode *CCNodeAlloc ();
     228CCNode *CCFindChild (CCNode *node, float x, float y, float z);
     229int CCSplitNode (CCNode *node);
     230int CCSplitNodeIterate (CCNode *node, int current, int max);
     231void CCNodeFree (CCNode *node);
     232CCNode *CCFindBottom (CCNode *top, float x, float y, float z);
     233int CCNodeExtractCounts (CCNode *node, float **values, int *nvalues, int *NVALUES);
     234int CCNodeDivideLimit (CCNode *node, float minValue);
     235int CCNodeInitCounts (CCNode *node, float value);
     236
     237/* 3D color histogram */
     238void ColorHistogram (KapaImageWidget *image, CCNode *cube);
     239void CCNodeSetColorPixels (KapaImageWidget *image, CCNode *cube);
     240int CCNodeSetColorMap (CCNode *node, XColor *cmap, int Npixels, int *current);
     241
     242int SetColorScale3D_CC (Graphic *graphic, KapaImageWidget *image);
     243
     244void sort (float *value, int N);
  • branches/eam_branch_20071222/Ohana/src/kapa2/include/structures.h

    r15935 r15996  
    6666} TextBox;
    6767
     68/*** 3C color cube histogram tree thingy ***/
     69typedef struct CCNode {
     70  // for the moment, this structure is specific to the color-histogram analysis.  if
     71  // this were a void *pointer and we defined some additional apis, we could use this
     72  // structure to track any 3D space
     73  int count;   
     74  int pixel;
     75  char bottom;
     76  float min[3]; // min value for each of the 3 dimensions for this node
     77  float mid[3]; // mid-point for each of the 3 dimensions for this node
     78  float max[3]; // max value for each of the 3 dimensions for this node
     79  struct CCNode *sub[2][2][2];
     80} CCNode;
     81
    6882/**************** general structures ****************/
    6983typedef struct {
  • branches/eam_branch_20071222/Ohana/src/kapa2/src/ButtonFunctions.c

    r15935 r15996  
    2929  char *name;
    3030  name = HEAT;
    31   SetColormap (name);
     31  SetColormap ("ruffcolor");
    3232  CreateColorbar (image, graphic);
    3333  SetColorScale (graphic, image);
  • branches/eam_branch_20071222/Ohana/src/kapa2/src/SetColorScale.c

    r15935 r15996  
    77      SetColorScale1D (graphic, image);
    88      break;
    9     case KAPA_SCALE_3D:
    10       SetColorScale3D (graphic, image);
     9    case KAPA_SCALE_3D_RUFF:
     10      // fall-back on 1D colors (ie, if images are mis-matched)
     11      if (!SetColorScale3D (graphic, image)) {
     12        graphic[0].ColorScaleMode = KAPA_SCALE_1D;
     13        SetColorScale1D (graphic, image);
     14      }
     15      break;
     16    case KAPA_SCALE_3D_FULL:
     17      // fall-back on 1D colors (ie, if images are mis-matched)
     18      if (!SetColorScale3D_CC (graphic, image)) {
     19        graphic[0].ColorScaleMode = KAPA_SCALE_1D;
     20        SetColorScale1D (graphic, image);
     21      }
    1122      break;
    1223    default:
     
    6071
    6172// in 3D we use channels 0,1,2 to choose the pixel from the cube
    62 void SetColorScale3D (Graphic *graphic, KapaImageWidget *image) {
     73// XXX this uses a crude, uniform-spacing cube
     74int SetColorScale3D (Graphic *graphic, KapaImageWidget *image) {
    6375  int i, j, DX, DY, value, nPixels, rValue, gValue, bValue;
    6476  float *rData, *bData, *gData;
     
    6779  float redStart, blueStart, greenStart;
    6880
     81  DX = image[0].channel[KAPA_CHANNEL_RED].matrix.Naxis[0];
     82  DY = image[0].channel[KAPA_CHANNEL_RED].matrix.Naxis[1];
     83
     84  if (DX != image[0].channel[KAPA_CHANNEL_GREEN].matrix.Naxis[0]) return FALSE;
     85  if (DY != image[0].channel[KAPA_CHANNEL_GREEN].matrix.Naxis[1]) return FALSE;
     86  if (DX != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[0]) return FALSE;
     87  if (DY != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[1]) return FALSE;
     88
    6989  // define the color transform parameters
    7090  unsigned short maxRed = graphic[0].nRed - 1;
     
    7393
    7494  // set start & slope for red (channel 0)
    75   if (image[0].channel[0].range != 0.0) {
    76     redSlope = graphic[0].nRed / image[0].channel[0].range;
    77     redStart = graphic[0].nRed * image[0].channel[0].zero / image[0].channel[0].range;
     95  if (image[0].channel[KAPA_CHANNEL_RED].range != 0.0) {
     96    redSlope = graphic[0].nRed / image[0].channel[KAPA_CHANNEL_RED].range;
     97    redStart = graphic[0].nRed * image[0].channel[KAPA_CHANNEL_RED].zero / image[0].channel[KAPA_CHANNEL_RED].range;
    7898  } else {
    7999    redSlope = 1.0;
    80     redStart = image[0].channel[0].zero;
     100    redStart = image[0].channel[KAPA_CHANNEL_RED].zero;
    81101  }
    82102  // set start & slope for blue (channel 0)
    83   if (image[0].channel[1].range != 0.0) {
    84     blueSlope = graphic[0].nBlue / image[0].channel[1].range;
    85     blueStart = graphic[0].nBlue * image[0].channel[1].zero / image[0].channel[1].range;
     103  if (image[0].channel[KAPA_CHANNEL_BLUE].range != 0.0) {
     104    blueSlope = graphic[0].nBlue / image[0].channel[KAPA_CHANNEL_BLUE].range;
     105    blueStart = graphic[0].nBlue * image[0].channel[KAPA_CHANNEL_BLUE].zero / image[0].channel[KAPA_CHANNEL_BLUE].range;
    86106  } else {
    87107    blueSlope = 1.0;
    88     blueStart = image[0].channel[1].zero;
     108    blueStart = image[0].channel[KAPA_CHANNEL_BLUE].zero;
    89109  }
    90110  // set start & slope for green (channel 0)
    91   if (image[0].channel[2].range != 0.0) {
    92     greenSlope = graphic[0].nGreen / image[0].channel[2].range;
    93     greenStart = graphic[0].nGreen * image[0].channel[2].zero / image[0].channel[2].range;
     111  if (image[0].channel[KAPA_CHANNEL_GREEN].range != 0.0) {
     112    greenSlope = graphic[0].nGreen / image[0].channel[KAPA_CHANNEL_GREEN].range;
     113    greenStart = graphic[0].nGreen * image[0].channel[KAPA_CHANNEL_GREEN].zero / image[0].channel[KAPA_CHANNEL_GREEN].range;
    94114  } else {
    95115    greenSlope = 1.0;
    96     greenStart = image[0].channel[2].zero;
    97   }
    98 
    99   DX = image[0].channel[0].matrix.Naxis[0];
    100   DY = image[0].channel[0].matrix.Naxis[1];
    101   // check on equal size for channel[1] and channel[2]
     116    greenStart = image[0].channel[KAPA_CHANNEL_GREEN].zero;
     117  }
    102118
    103119  nPixels = DX*DY;
     
    108124
    109125  oData = image[0].pixmap;
    110   rData = (float *) image[0].channel[0].matrix.buffer;
    111   bData = (float *) image[0].channel[1].matrix.buffer;
    112   gData = (float *) image[0].channel[2].matrix.buffer;
     126  rData = (float *) image[0].channel[KAPA_CHANNEL_RED].matrix.buffer;
     127  bData = (float *) image[0].channel[KAPA_CHANNEL_BLUE].matrix.buffer;
     128  gData = (float *) image[0].channel[KAPA_CHANNEL_GREEN].matrix.buffer;
    113129
    114130  // convert pixel data values to pixel index values (0 - Npixel)
     
    128144    *oData = gValue + bValue * (maxGreen + 1) + rValue * (maxGreen + 1) * (maxBlue + 1);
    129145  }
    130 }
     146  return TRUE;
     147}
     148
     149// in 3D we use channels 0,1,2 to choose the pixel from the cube
     150int SetColorScale3D_CC (Graphic *graphic, KapaImageWidget *image) {
     151
     152  int i, DX, DY, Nvalues, NVALUES, Npixels, Nmin;
     153  float *values, *colors;
     154  CCNode *cube;
     155
     156  DX = image[0].channel[KAPA_CHANNEL_RED].matrix.Naxis[0];
     157  DY = image[0].channel[KAPA_CHANNEL_RED].matrix.Naxis[1];
     158  if (DX != image[0].channel[KAPA_CHANNEL_GREEN].matrix.Naxis[0]) return FALSE;
     159  if (DY != image[0].channel[KAPA_CHANNEL_GREEN].matrix.Naxis[1]) return FALSE;
     160  if (DX != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[0]) return FALSE;
     161  if (DY != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[1]) return FALSE;
     162
     163  // create the top-level cube
     164  cube = CCNodeAlloc();
     165  cube->min[CC_X] = cube->min[CC_Y] = cube->min[CC_Z] = 0.0;
     166  cube->max[CC_X] = cube->max[CC_Y] = cube->max[CC_Z] = 1.0;
     167  cube->mid[CC_X] = cube->mid[CC_Y] = cube->mid[CC_Z] = 0.5;
     168
     169  // subdivide cube into first, uniform division (4x4x4)
     170  CCSplitNodeIterate (cube, 0, 2);
     171
     172  // need to allocate at least 1184 pixels
     173  // 64, 288, 512, 736, 960, 1184
     174  for (i = 0; i < 8; i++) {
     175    // generate histogram
     176    ColorHistogram (image, cube);
     177
     178    // extract histogram values
     179    values  = NULL;
     180    Nvalues = 0;
     181    NVALUES = 0;
     182    CCNodeExtractCounts (cube, &values, &Nvalues, &NVALUES);
     183 
     184    // select top N cells
     185    sort (values, Nvalues);
     186
     187    // split nodes with more than value[n]
     188    Nmin = MAX (0, Nvalues - 50);
     189    CCNodeDivideLimit (cube, values[Nmin]);
     190    free (values);
     191
     192    CCNodeInitCounts (cube, 0.0);
     193  }
     194
     195  // generate histogram
     196  ColorHistogram (image, cube);
     197 
     198  // convert histogram 3D values to cmap colors
     199  Npixels = 0;
     200  CCNodeSetColorMap (cube, graphic[0].cmap, graphic[0].Npixels, &Npixels);
     201
     202  // store the colors
     203  if (USE_XWINDOW) {
     204    if (graphic[0].visualclass) {
     205      XStoreColors(graphic[0].display, graphic[0].colormap, graphic[0].cmap, Npixels);
     206    } else {
     207      for (i = 0; i < Npixels; i++) {
     208        if (XAllocColor (graphic[0].display, graphic[0].colormap, &graphic[0].cmap[i]) == 0) {
     209          fprintf (stderr, "error on %d\n", i);
     210        }
     211      }
     212    }
     213  }
     214  CCNodeSetColorPixels (image, cube);
     215  return TRUE;
     216}
     217
  • branches/eam_branch_20071222/Ohana/src/kapa2/src/SetColormap.c

    r15935 r15996  
    1919  graphic = GetGraphic();
    2020
     21  // the "fullcolor" colormap is uniquely defined for each image;
     22  // defer to the 'SetColorScale' step
     23  if (!strcasecmp (name, "fullcolor")) {
     24    graphic[0].ColorScaleMode = KAPA_SCALE_3D_FULL;
     25    return TRUE;
     26  }
     27
    2128  // very simple color model: evenly spaced cube
    22   if (!strcasecmp (name, "fullcolor")) {
     29  if (!strcasecmp (name, "ruffcolor")) {
    2330      graphic[0].nRed  = pow (graphic[0].Npixels, 0.333);
    2431      graphic[0].nBlue = pow (graphic[0].Npixels, 0.333);
     
    4350
    4451      // all other modes are 1D: set the flag:
    45       graphic[0].ColorScaleMode = KAPA_SCALE_3D;
     52      graphic[0].ColorScaleMode = KAPA_SCALE_3D_RUFF;
    4653      goto store_colors;
    4754  }
  • branches/eam_branch_20071222/Ohana/src/kapa2/test/input

    r15934 r15996  
    2323  tv R 0 256
    2424  tvchannel 1
     25  tv G 0 256
     26  tvchannel 2
    2527  tv B 0 256
    26   tvchannel 2
    27   tv G 0 256
    2828end
Note: See TracChangeset for help on using the changeset viewer.