Classes | Defines | Enumerations | Functions

ipSegmentation.h File Reference

#include <mitkIpPic.h>

Go to the source code of this file.

Classes

struct  tCutResult

Defines

#define ipMITKSegmentationTYPE   mitkIpUInt1_t
 Defines the data type of the segmentation images.
#define ipMITKSegmentationTYPE_ID   mitkIpPicUInt
#define ipMITKSegmentationBPE   8
#define tagSEGMENTATION_EMPTY   "SEGMENTATION_EMPTY"

Enumerations

enum  LogicalOp {
  IPSEGMENTATION_OP, IPSEGMENTATION_AND, IPSEGMENTATION_OR, IPSEGMENTATION_XOR,
  IPSEGMENTATION_OP, IPSEGMENTATION_AND, IPSEGMENTATION_OR, IPSEGMENTATION_XOR
}
 

The type of logical operation.

More...

Functions

mitkIpPicDescriptor * ipMITKSegmentationNew (mitkIpPicDescriptor *image)
 Initializes the segmentation.
void ipMITKSegmentationFree (mitkIpPicDescriptor *segmentation)
 Destroys the segmentation.
void ipMITKSegmentationClear (mitkIpPicDescriptor *segmentation)
 Clears the segmentation data, i.e. the pixels will be set to zero.
mitkIpPicDescriptor * ipMITKSegmentationInterpolate (mitkIpPicDescriptor *pic1, mitkIpPicDescriptor *pic2, const mitkIpFloat4_t ratio)
 Interpolates the shape of segmentations.
void ipMITKSegmentationCombineRegion (mitkIpPicDescriptor *segmentation, const mitkIpInt4_t *const points, const int num, mitkIpPicDescriptor *mask, const int operation, int value)
 Combines the region with the segmentation image.
void ipMITKSegmentationUndoEnable (mitkIpPicDescriptor *segmentation, const mitkIpUInt1_t level)
 Enables the undo operation for the specified segmentation.
void ipMITKSegmentationUndoDisable (mitkIpPicDescriptor *segmentation)
 Disables the undo operation for the specified segmentation. The available data will be discarded.
mitkIpBool_t ipMITKSegmentationUndoIsEnabled (mitkIpPicDescriptor *segmentation)
 Checks if the undo operation is enabled.
mitkIpBool_t ipMITKSegmentationUndoAvailable (mitkIpPicDescriptor *segmentation)
 Checks if any data for undo is available. pending?
void ipMITKSegmentationUndoSave (mitkIpPicDescriptor *segmentation)
 Save the segmentation image before it is changed.
void ipMITKSegmentationUndo (mitkIpPicDescriptor *segmentation)
 Steps to the previous undo level. The data which has been saved before the last modifications will be restored.
mitkIpPicDescriptor * ipMITKSegmentationGrowRegion4N (mitkIpPicDescriptor *src, int startOfs, bool relativeBounds, float lowerBound, float upperBound, int maxIterations, mitkIpPicDescriptor *segBuffer, mitkIpPicDescriptor *histBuffer=0)
mitkIpPicDescriptor * ipMITKSegmentationGrowRegion4N (mitkIpPicDescriptor *src, int startOfs, bool relativeBounds, float lowerBound, float upperBound, int maxIterations, mitkIpPicDescriptor *segBuffer, int &contourOfs, float &startCol, mitkIpPicDescriptor *histBuffer=0)
int ipMITKSegmentationReplaceRegion4N (mitkIpPicDescriptor *seg, int startOfs, mitkIpInt1_t newValue)
float * ipMITKSegmentationGetContour8N (const mitkIpPicDescriptor *seg, int startOfs, int &numPoints, int &sizeBuffer, float *pointBuffer=0)
tCutResult ipMITKSegmentationGetCutPoints (mitkIpPicDescriptor *seg, mitkIpPicDescriptor *history, int ofs)
mitkIpPicDescriptor * ipMITKSegmentationCreateGrowerHistory (mitkIpPicDescriptor *seg, int startOfs, mitkIpPicDescriptor *histBuffer)
void ipMITKSegmentationSplitContour (float *contour, int sizeContour, float *cutCoords, float *part1, int &size1, float *part2, int &size2)
bool ipMITKSegmentationIsInsideContour (float *contour, int sizeContour, float x, float y)

Define Documentation

#define ipMITKSegmentationBPE   8

Definition at line 45 of file ipSegmentation.h.

#define ipMITKSegmentationTYPE   mitkIpUInt1_t
#define ipMITKSegmentationTYPE_ID   mitkIpPicUInt

Definition at line 44 of file ipSegmentation.h.

#define tagSEGMENTATION_EMPTY   "SEGMENTATION_EMPTY"

Definition at line 46 of file ipSegmentation.h.

Referenced by ipMITKSegmentationReplaceRegion4N().


Enumeration Type Documentation

enum LogicalOp

The type of logical operation.

Enumerator:
IPSEGMENTATION_OP 

copy of input image

IPSEGMENTATION_AND 

logical and operator

IPSEGMENTATION_OR 

the or operator

IPSEGMENTATION_XOR 

the exclusive-or operator

IPSEGMENTATION_OP 

copy of input image

IPSEGMENTATION_AND 

logical and operator

IPSEGMENTATION_OR 

the or operator

IPSEGMENTATION_XOR 

the exclusive-or operator

Definition at line 79 of file ipSegmentation.h.


Function Documentation

void ipMITKSegmentationClear ( mitkIpPicDescriptor *  segmentation )

Clears the segmentation data, i.e. the pixels will be set to zero.

Parameters:
segmentationthe segmentation

Referenced by mitk::ContourUtils::FillContourInSlice().

void ipMITKSegmentationCombineRegion ( mitkIpPicDescriptor *  segmentation,
const mitkIpInt4_t *const   points,
const int  num,
mitkIpPicDescriptor *  mask,
const int  operation,
int  value 
)

Combines the region with the segmentation image.

Parameters:
pointsthe array of points, each point is represented by a 2-D vector (x, y)
segmentationthe segmentation.
numthe number of points
maskthe image which restricts the operation to a particular region
operationthe operation which will be performed (see above)
valuethe operand value of the operation
Note:
The last point is automatically connected with the first one.

Referenced by mitk::ContourUtils::FillContourInSlice(), and mitk::CorrectorAlgorithm::TobiasHeimannCorrectionAlgorithm().

mitkIpPicDescriptor* ipMITKSegmentationCreateGrowerHistory ( mitkIpPicDescriptor *  seg,
int  startOfs,
mitkIpPicDescriptor *  histBuffer 
)

Creates a grower history (i.e. the order in which a region grower would have segmented the area) of the given segmentation, origin of the grower is startOfs. histBuffer must be a 16bit unsigned int or 0, in the latter case the pic is created.

Definition at line 23 of file ipSegmentationGrowerHistory.cpp.

References int(), and mitkIpPicDescriptor.

Referenced by mitk::RegionGrowingTool::OnMousePressedInside().

{
  std::queue<int> ofsQueue;

  if (!seg) return 0;
  if (!histBuffer) {
    histBuffer = mitkIpPicCopyHeader( seg, histBuffer );
    histBuffer->type = mitkIpPicUInt;
    histBuffer->bpe = 16; 
    mitkIpUInt4_t size = _mitkIpPicSize( histBuffer );
    histBuffer->data = malloc( size );
    memset( histBuffer->data, 0, size );  // clear buffer
  }
  else {
    // check if dimension of histBuffer is valid, if not: change it!
    if (histBuffer->n[0] != seg->n[0] || histBuffer->n[1] != seg->n[1]) {
      histBuffer->n[0] = seg->n[0];
      histBuffer->n[1] = seg->n[1];
      mitkIpUInt4_t size = _mitkIpPicSize( histBuffer );
      histBuffer->data = realloc( histBuffer->data, size );
      if (histBuffer->data == 0) return 0;
      memset( histBuffer->data, 0, size );  // clear buffer
    }
  }

  // create a clear buffer to check wether a point has already been visited
  // (seg cannot be modifier and histBuffer can contain any value)
  mitkIpPicDescriptor *flagBuffer = mitkIpPicCopyHeader( seg, 0 );
  mitkIpUInt4_t size = _mitkIpPicSize( flagBuffer );
  flagBuffer->data = malloc( size );
  memset( flagBuffer->data, 0, size );
  *((mitkIpUInt1_t*)flagBuffer->data+startOfs) = 1;    // flag pixel as visited
    
  int line = seg->n[0];
  int maxOfs = (int)(line * seg->n[1]);
  int testOfs;
  mitkIpUInt1_t segVal, flagVal;
  int iteration = 0;
  int currentWave = 1;
  int nextWave = 0;
  
  ofsQueue.push( startOfs );

  while (!ofsQueue.empty()) {
    int nextOfs = ofsQueue.front();
    ofsQueue.pop();
    currentWave--;
    *((mitkIpUInt2_t*)histBuffer->data+nextOfs) = (mitkIpUInt2_t)(iteration+1);  // seed point should get history = 1

    // check right:
    testOfs = nextOfs+1;
    if (testOfs%line!=0) {
      segVal = *((mitkIpUInt1_t*)seg->data+testOfs);
      flagVal = *((mitkIpUInt1_t*)flagBuffer->data+testOfs);
      if ( segVal != 0 && flagVal == 0) {
        ofsQueue.push( testOfs );
        *((mitkIpUInt1_t*)flagBuffer->data+testOfs) = 1;    // flag pixel as visited
        nextWave++;
      }
    }
    // check top:
    testOfs = nextOfs-line;
    if (testOfs > 0) {
      segVal = *((mitkIpUInt1_t*)seg->data+testOfs);
      flagVal = *((mitkIpUInt1_t*)flagBuffer->data+testOfs);
      if ( segVal != 0 && flagVal == 0) {
        ofsQueue.push( testOfs );
        *((mitkIpUInt1_t*)flagBuffer->data+testOfs) = 1;    // flag pixel as visited
        nextWave++;
      }
    }
    // check left:
    testOfs = nextOfs-1;
    if (nextOfs%line!=0) {
      segVal = *((mitkIpUInt1_t*)seg->data+testOfs);
      flagVal = *((mitkIpUInt1_t*)flagBuffer->data+testOfs);
      if ( segVal != 0 && flagVal == 0) {
        ofsQueue.push( testOfs );
        *((mitkIpUInt1_t*)flagBuffer->data+testOfs) = 1;    // flag pixel as visited
        nextWave++;
      }
    }
    // check bottom:
    testOfs = nextOfs+line;
    if (testOfs < maxOfs) {
      segVal = *((mitkIpUInt1_t*)seg->data+testOfs);
      flagVal = *((mitkIpUInt1_t*)flagBuffer->data+testOfs);
      if ( segVal != 0 && flagVal == 0) {
        ofsQueue.push( testOfs );
        *((mitkIpUInt1_t*)flagBuffer->data+testOfs) = 1;    // flag pixel as visited
        nextWave++;
      }
    }
    // check for number of iterations:
    if (currentWave == 0) {
      currentWave = nextWave;
      nextWave = 0;
      iteration++;
    }
  }

  mitkIpPicFree( flagBuffer );
  return histBuffer;
}
void ipMITKSegmentationFree ( mitkIpPicDescriptor *  segmentation )
float* ipMITKSegmentationGetContour8N ( const mitkIpPicDescriptor *  seg,
int  startOfs,
int &  numPoints,
int &  sizeBuffer,
float *  pointBuffer = 0 
)

Same as above, but for the 8 neighbourhood contour.

Definition at line 194 of file ipSegmentationContourExtraction.cpp.

References tmGetContour8N().

Referenced by ipMITKSegmentationGetCutPoints(), mitk::SetRegionTool::OnMousePressed(), mitk::RegionGrowingTool::PerformRegionGrowingAndUpdateContour(), mitk::CorrectorAlgorithm::TobiasHeimannCorrectionAlgorithm(), and mitk::PaintbrushTool::UpdateContour().

{
  float *newBuffer = NULL;
  mitkIpPicTypeMultiplexR4( tmGetContour8N, seg, newBuffer, startOfs, numPoints, sizeBuffer, pointBuffer );
  return newBuffer;
}
tCutResult ipMITKSegmentationGetCutPoints ( mitkIpPicDescriptor *  seg,
mitkIpPicDescriptor *  history,
int  ofs 
)

Calculates a path from ofs to the origin of the growing process, when possible on the skeleton of the segmented area. The narrowest part of this path is used to create two cut points that are part of the contour and can later be used to split the segmentation. This funtion is useful for detecting and removing leaks in region growing.

Definition at line 92 of file ipSegmentationRegionCutter.cpp.

References QuadProgPP::abs(), tCutResult::absMin, annAllocPt(), annAllocPts(), annDeallocPt(), annDeallocPts(), ANNkd_tree::annkSearch(), annTree, tCutResult::cutCoords, tCutResult::cutIt, tCutResult::deleteCurve, tCutResult::deleteSize, QuadProgPP::dist(), dists, int(), ipMITKSegmentationGetContour8N(), ipMITKSegmentationIsInsideContour(), ipMITKSegmentationSplitContour(), nnIdx, tCutResult::numPoints, tCutResult::onGradient, PROCESS_PIXEL, QUERY_DIST, queryPt, QuadProgPP::sqrt(), and tCutResult::traceline.

Referenced by mitk::RegionGrowingTool::OnMousePressedInside().

{
  bool debug(false);
  tCutResult res;
  int resContourSize = 5000;
  res.traceline = (float*)malloc( resContourSize*sizeof(float)*2 );
  res.onGradient = (bool*)malloc( resContourSize*sizeof(bool) );
  res.numPoints = 0;
  res.absMin = 0;
  res.cutIt = false;
  res.deleteCurve = 0;

  if (!history) return res;                  // no history!
  if (*((mitkIpUInt2_t*)history->data + ofs) == 0) return res;  // ofs not inside known history

  // get one point on the contour:
  mitkIpUInt1_t *ptr = (mitkIpUInt1_t*)seg->data + ofs;
    int endLine = ((ofs / seg->n[0]) + 1) * seg->n[0] -1;
  int contourOfs = ofs;
  while (contourOfs!=endLine && *ptr!=0) {
    ptr++;
    contourOfs++;
  }
  if (*ptr == 0) contourOfs--;  // get back on the contour!

  // extract the contour:
  int sizeContour, sizeBuffer;
  float *contour = ipMITKSegmentationGetContour8N( seg, contourOfs, sizeContour, sizeBuffer );
  // init ANN tree with contour points:
  queryPt    = annAllocPt( 2 );
    ANNpointArray dataPts  = annAllocPts( sizeContour, 2 );
    nnIdx    = new ANNidx[10];
    dists    = new ANNdist[10];
    for (int i=0; i<sizeContour; i++) {
        (dataPts[i])[0] = contour[2*i];
        (dataPts[i])[1] = contour[2*i+1];
    }
    annTree = new ANNkd_tree( dataPts, sizeContour, 2 );

  // trace to center:
  int line = history->n[0];

  int maxOfs = line * history->n[1];
  QUERY_DIST(ofs)
  float maxDist = dists[0];
  float minDist = 10000;  // current minimum distance from border
  float oldDist = 0;
  int candOfs = ofs;
  int nextOfs = -1;
  int oldOfs, testOfs, gradCand=-1;
  float grad, minGrad;
  bool skelettonReached = false;
  mitkIpUInt2_t histVal;
  mitkIpUInt1_t segVal;
  mitkIpUInt2_t maxHist = 10000;
  if (maxHist==0 && debug) printf( "maxHist = 0!\n" );
  do {
    oldOfs = nextOfs;
    nextOfs = candOfs;
    // store point info:
    if (res.numPoints < resContourSize) {
      res.traceline[2*res.numPoints] = (float)(nextOfs % line) + 0.5;
      res.traceline[2*res.numPoints+1] = (float)(nextOfs / line) + 0.5;
      if (nextOfs==gradCand) res.onGradient[res.numPoints] = true;
      else res.onGradient[res.numPoints] = false;
      
      if (debug)
      {
        printf( "(%.f,%.f): H=%i, G=%i\n", res.traceline[2*res.numPoints], 
        res.traceline[2*res.numPoints+1], 
        *((mitkIpUInt2_t*)history->data+nextOfs), 
        res.onGradient[res.numPoints] );
      }
      res.numPoints++;
      
      if (res.numPoints == resContourSize)
      {
        resContourSize *= 2; // explodes, but such contours must be very strange
        res.traceline = (float*)realloc( res.traceline,  resContourSize*sizeof(float)*2 );
        res.onGradient = (bool*)realloc( res.onGradient, resContourSize*sizeof(bool) );
        if ((res.traceline == NULL) || (res.onGradient == NULL))
        {
          res.numPoints = 0;
          res.cutIt = false;
          return res;
        }
      }
    }

    maxHist = *((mitkIpUInt2_t*)history->data + nextOfs);  // don't exceed this history!
    maxDist = 0;  // clear maxDist
    minGrad = 1.0;  // clear minGrad

    int traceSinceMin = res.numPoints - 1 - res.absMin;
    float weight = 20.0 / (20.0+traceSinceMin);
    if (weight < 0.5) weight = 0.5;
    QUERY_DIST(nextOfs)
    if (!skelettonReached && dists[0] < oldDist) {
      skelettonReached = true;
                        if (debug) printf( "skeletton reached at %i, oldDist=%.1f, currentDist=%.1f\n", 
        res.numPoints - 1, oldDist, dists[0] );
    }
    oldDist = dists[0];
    if (skelettonReached && weight*dists[0] < minDist) {
      minDist = dists[0];
      res.absMin = res.numPoints - 1;  // has already been increased
    }

    // check right:
    testOfs = nextOfs+1;
    if (testOfs%line!=0) {
      // check top right:
      PROCESS_PIXEL
      testOfs = nextOfs-line;
      if (testOfs > 0) {
        testOfs++;
        PROCESS_PIXEL
      }
      // check bottom right:
      testOfs = nextOfs+line;
      if (testOfs < maxOfs) {
        testOfs++;
        PROCESS_PIXEL
      }
    }
    // check top:
    testOfs = nextOfs-line;
    if (testOfs > 0) {
      PROCESS_PIXEL
    }
    // check left:
    testOfs = nextOfs-1;
    if (nextOfs%line!=0) {
      PROCESS_PIXEL
      // check top left:
      testOfs = nextOfs-line;
      if (testOfs > 0) {
        testOfs--;
        PROCESS_PIXEL
      }
      // check bottom left:
      testOfs = nextOfs+line;
      if (testOfs < maxOfs) {
        testOfs--;
        PROCESS_PIXEL
      }
    }
    // check bottom:
    testOfs = nextOfs+line;
    if (testOfs < maxOfs) {
      PROCESS_PIXEL
    }
    // check for run on gradient:
    if (minGrad < 0.5) {
      candOfs = gradCand;
                        if (debug) printf( "." );
    }
    else if (debug) printf( "x" );
  } while (candOfs != nextOfs && maxHist > 0);

  if (res.absMin < (res.numPoints-10)) {
    res.absMin += (int)(sqrt(minDist)/2.0);
//  int cutX = (int)(res.traceline[2*res.absMin]-0.5); 
//  int cutY = (int)(res.traceline[2*res.absMin+1]-0.5);
//  int cutOfs = cutX + line*cutY;
//  histVal = *((mitkIpUInt2_t*)history->data+cutOfs);
//  printf( "histVal at Cut=%i\n", histVal );
//  if (histVal > 1) {
    res.cutIt = true;
    float cutXf = (float)res.traceline[2*res.absMin]; 
    float cutYf = (float)res.traceline[2*res.absMin+1];
    queryPt[0] = cutXf;
    queryPt[1] = cutYf;
    annTree->annkSearch( queryPt, 1, nnIdx, dists );
    int cutIdx1 = nnIdx[0];
    res.cutCoords[0] = contour[2*cutIdx1];
    res.cutCoords[1] = contour[2*cutIdx1+1];
    int cutIdx2 = cutIdx1;
    float minDist = 100000000;
    int testCnt = 0;
    for (int i=0; i<sizeContour; i++) {
      int idxDif = abs(cutIdx1-i);
      // take wraparound into account:
      if (idxDif > (sizeContour/2)) idxDif = sizeContour - idxDif;
      if ( idxDif > 50 ) {
        float dist = (cutXf-contour[2*i])*(cutXf-contour[2*i]) + (cutYf-contour[2*i+1])*(cutYf-contour[2*i+1]);
        if (dist < minDist) {
          minDist = dist;
          cutIdx2 = i;
        }
      }
      else testCnt++;
    }
    res.cutCoords[2] = contour[2*cutIdx2];
    res.cutCoords[3] = contour[2*cutIdx2+1];
    if (debug) printf( "idx1=%i, idx2=%i, %i pts not evaluated.\n", cutIdx1, cutIdx2, testCnt );

                if ((res.cutCoords[0] == res.cutCoords[2]) &&
                    (res.cutCoords[1] == res.cutCoords[3]))
                {
                  free( contour );
                  // free ANN stuff:
                  annDeallocPt( queryPt );
                  annDeallocPts( dataPts );
                  delete[] nnIdx;
                  delete[] dists;
                  delete annTree;

                  res.cutIt = false;

                  return res;
                }
    float *curve1 = (float*)malloc( 2*sizeof(float)*sizeContour );
    float *curve2 = (float*)malloc( 2*sizeof(float)*sizeContour );
    int    sizeCurve1, sizeCurve2;
    ipMITKSegmentationSplitContour( contour, sizeContour, res.cutCoords, curve1, sizeCurve1, curve2, sizeCurve2 );
    float clickX = (float)(ofs % line) + 0.5;
    float clickY = (float)(ofs / line) + 0.5;
    if (ipMITKSegmentationIsInsideContour( curve1, sizeCurve1, clickX, clickY )) {
      res.deleteCurve = curve1;
      res.deleteSize = sizeCurve1;
      free( curve2 );
    }
    else {
      res.deleteCurve = curve2;
      res.deleteSize = sizeCurve2;
      free( curve1 );
    }
  }

  
  free( contour );
  // free ANN stuff:
  annDeallocPt( queryPt );
  annDeallocPts( dataPts );
  delete[] nnIdx;
  delete[] dists;
  delete annTree;

  return res;
}
mitkIpPicDescriptor* ipMITKSegmentationGrowRegion4N ( mitkIpPicDescriptor *  src,
int  startOfs,
bool  relativeBounds,
float  lowerBound,
float  upperBound,
int  maxIterations,
mitkIpPicDescriptor *  segBuffer,
mitkIpPicDescriptor *  histBuffer = 0 
)

Starts a 4 neighbourhood region growing at startOfs (y*picWidth+x) of the 2D image src. If relativeBounds is true, the region grows in [base-lowerBound, base+upperBound], in which base is the average color of the 9 pixels around startOfs. If relativeBounds is false, the region grows in [lowerBound, upperBound]. If maxIterations is > 0, the growing process is stopped after maxIterations. If segBuffer is 0, new memory for the segmented image is allocated and returned, else the segBuffer is used to store the result (has to be an 8-bit datatype, e.g. mitkIpUInt1_t). histBuffer must be 0 or a pointer to a 16-bit mitkIpPicUInt image of the same size as src. In case of the latter, history data is written to that buffer: the seed pixel gets a 1, all direct neighbours 2 etc. The buffer is not cleared in this function and can thus hold history data of several growing processes in different areas.

Definition at line 196 of file ipSegmentationRegionGrower.cpp.

References ipMITKSegmentationUndoIsEnabled(), ipMITKSegmentationUndoSave(), mitkIpPicDescriptor, and tmGrowRegion4N().

Referenced by mitk::RegionGrowingTool::PerformRegionGrowingAndUpdateContour().

{
  mitkIpPicDescriptor *result = 0;
  int contourOfs;
  float startCol;
  
  if (ipMITKSegmentationUndoIsEnabled (segBuffer)) {
    ipMITKSegmentationUndoSave (segBuffer);
  }

  mitkIpPicTypeMultiplexR9( tmGrowRegion4N, src, result, startOfs, relativeBounds, lowerBound, upperBound, maxIterations, segBuffer, contourOfs, startCol, histBuffer );
  return result;
}
mitkIpPicDescriptor* ipMITKSegmentationGrowRegion4N ( mitkIpPicDescriptor *  src,
int  startOfs,
bool  relativeBounds,
float  lowerBound,
float  upperBound,
int  maxIterations,
mitkIpPicDescriptor *  segBuffer,
int &  contourOfs,
float &  startCol,
mitkIpPicDescriptor *  histBuffer = 0 
)

Same as the other ipMITKSegmentationGrowRegion4N with two additional return values: contourOfs holds the lowest point of the resulting region and is thus guaranteed to be part of the contour Take care: if the region could not grow at all (e.g. with fixed borders) contourOfs will be -1 !!! startCol holds the color that was used as base if relativeBounds is true

Definition at line 213 of file ipSegmentationRegionGrower.cpp.

References ipMITKSegmentationUndoIsEnabled(), ipMITKSegmentationUndoSave(), mitkIpPicDescriptor, and tmGrowRegion4N().

{
  mitkIpPicDescriptor *result = 0;

  if (ipMITKSegmentationUndoIsEnabled (segBuffer)) {
    ipMITKSegmentationUndoSave (segBuffer);
  }

  mitkIpPicTypeMultiplexR9( tmGrowRegion4N, src, result, startOfs, relativeBounds, lowerBound, upperBound, maxIterations, segBuffer, contourOfs, startCol, histBuffer );
  return result;
}
mitkIpPicDescriptor* ipMITKSegmentationInterpolate ( mitkIpPicDescriptor *  pic1,
mitkIpPicDescriptor *  pic2,
const mitkIpFloat4_t  ratio 
)

Interpolates the shape of segmentations.

Parameters:
pic1,pic2the images of the segmentation
ratiothe ratio of the images, the ratios 0.0 and 1.0 will produce pic1 and pic2, accordingly.

Referenced by mitk::ShapeBasedInterpolationAlgorithm::Interpolate().

bool ipMITKSegmentationIsInsideContour ( float *  contour,
int  sizeContour,
float  x,
float  y 
)

Returns true if the specified point lies insede the contour, else returns false.

Definition at line 94 of file ipSegmentationContourUtils.cpp.

Referenced by ipMITKSegmentationGetCutPoints(), mitk::SetRegionTool::OnMousePressed(), and mitk::RegionGrowingTool::PerformRegionGrowingAndUpdateContour().

{

  int i, j;
  bool res = false;
  for ( i=0, j=sizeContour-1;
        i<sizeContour; 
        j=i++) 
  {
    if (
            (     ((contour[2*i+1]<=y) && (y<contour[2*j+1])) 
               || ((contour[2*j+1]<=y) && (y<contour[2*i+1]))  ) 
         &&
            (  x < (contour[2*j] - contour[2*i]) * (y - contour[2*i+1]) / (contour[2*j+1] - contour[2*i+1]) + contour[2*i])
       )

      res = !res;
  }
  return res;
}
mitkIpPicDescriptor* ipMITKSegmentationNew ( mitkIpPicDescriptor *  image )

Initializes the segmentation.

Parameters:
imagethe original image which will be segmented
Returns:
the segmentation.

Referenced by mitk::ContourUtils::FillContourInSlice().

int ipMITKSegmentationReplaceRegion4N ( mitkIpPicDescriptor *  seg,
int  startOfs,
mitkIpInt1_t  newValue 
)

Replaces the 4 neighbourhood region around startOfs (y*picWidth+x) of the 2D segmented image seg with newValue. Seg has to be an 8-bit datatype, e.g. mitkIpUInt1_t. Returns the number of replaced pixels. If newValue is the same as the old value, the function returns 0.

Definition at line 22 of file ipSegmentationReplaceRegion.cpp.

References int(), ipMITKSegmentationUndoIsEnabled(), ipMITKSegmentationUndoSave(), and tagSEGMENTATION_EMPTY.

Referenced by mitk::CorrectorAlgorithm::modifySegment(), and mitk::RegionGrowingTool::PerformRegionGrowingAndUpdateContour().

{
  mitkIpPicTSV_t* tag;

  std::queue<int> ofsQueue;

  if (ipMITKSegmentationUndoIsEnabled (seg)) {
    ipMITKSegmentationUndoSave (seg);
  }
  tag = mitkIpPicDelTag (seg, tagSEGMENTATION_EMPTY);
  if (tag) {
    mitkIpPicFreeTag (tag);
  }

  if (seg->bpe != 8) return 0;

  int line = seg->n[0];
  int maxOfs = (int)(line * seg->n[1]);
  int testOfs;
  mitkIpInt1_t replaceMe = *((mitkIpInt1_t*)seg->data + startOfs);
  if (replaceMe == newValue) return 0;
  
  mitkIpInt1_t segVal;
  ofsQueue.push( startOfs );
  *((mitkIpInt1_t*)seg->data+startOfs) = newValue;
  int regionSize = 0;

  while (!ofsQueue.empty()) {
    int nextOfs = ofsQueue.front();
    ofsQueue.pop();
    regionSize++;
    // check right:
    testOfs = nextOfs+1;
    if (testOfs%line!=0) {
      segVal = *((mitkIpInt1_t*)seg->data+testOfs);
      if ( segVal == replaceMe ) {
        ofsQueue.push( testOfs );
        *((mitkIpInt1_t*)seg->data+testOfs) = newValue;
      }
    }
    // check top:
    testOfs = nextOfs-line;
    if (testOfs >= 0) {
      segVal = *((mitkIpInt1_t*)seg->data+testOfs);
      if ( segVal == replaceMe ) {
        ofsQueue.push( testOfs );
        *((mitkIpInt1_t*)seg->data+testOfs) = newValue;
      }
    }
    // check left:
    testOfs = nextOfs-1;
    if (nextOfs%line!=0) {
      segVal = *((mitkIpInt1_t*)seg->data+testOfs);
      if ( segVal == replaceMe ) {
        ofsQueue.push( testOfs );
        *((mitkIpInt1_t*)seg->data+testOfs) = newValue;
      }
    }
    // check bottom:
    testOfs = nextOfs+line;
    if (testOfs < maxOfs) {
      segVal = *((mitkIpInt1_t*)seg->data+testOfs);
      if ( segVal == replaceMe ) {
        ofsQueue.push( testOfs );
        *((mitkIpInt1_t*)seg->data+testOfs) = newValue;
      }
    }
  }
  return regionSize;
}
void ipMITKSegmentationSplitContour ( float *  contour,
int  sizeContour,
float *  cutCoords,
float *  part1,
int &  size1,
float *  part2,
int &  size2 
)

Splits a contour in two parts. contour is the original contour, cutCoords a pointer to an x1-y1-x2-y2 array that specifies the two points where the contour should be cut (these cutpoints must be points of the original contour!). part1 and part2 have to be float arrays of a sufficient size to store the two parts. The sizes of the two parts are returned in size1 and size2.

Input: one contour (start and end point identical). array of floats. [x1 y1 x2 y2 ...] Output: two contours (start and end point not neccessarily identical) cutCoords: two points that define the cut (must not [should not be] be identical)

S.....O . . . . . . . ------C2 S: Start of contour (two times in the array) . ------- . C1: cut point 1 C1------ . C2: cut point 2 . O . .. . .. . .. . .. O

Definition at line 40 of file ipSegmentationContourUtils.cpp.

Referenced by ipMITKSegmentationGetCutPoints().

{
  int cut1, cut2, i=0;
  bool cutReached;
  size1 = 0;
  size2 = 0;

  do {
    part1[2*size1] = contour[2*i];
    part1[2*size1+1] = contour[2*i+1];
    i++;
    size1++;
    cutReached = ( (cutCoords[0]==contour[2*i] && cutCoords[1]==contour[2*i+1]) ||
             (cutCoords[2]==contour[2*i] && cutCoords[3]==contour[2*i+1])    );
  } while (!cutReached);
  cut1 = i;
  part1[2*size1] = contour[2*i];
  part1[2*size1+1] = contour[2*i+1];
  size1++;
  
  do {
    part2[2*size2] = contour[2*i];
    part2[2*size2+1] = contour[2*i+1];
    i++;
    size2++;
    cutReached = ( (cutCoords[0]==contour[2*i] && cutCoords[1]==contour[2*i+1]) ||
             (cutCoords[2]==contour[2*i] && cutCoords[3]==contour[2*i+1])    );
  } while (!cutReached);
  cut2 = i;
  part2[2*size2] = contour[2*i];
  part2[2*size2+1] = contour[2*i+1];
  size2++;

  do {
    part1[2*size1] = contour[2*i];
    part1[2*size1+1] = contour[2*i+1];
    i++;
    size1++;
  } while (i<sizeContour);
}
void ipMITKSegmentationUndo ( mitkIpPicDescriptor *  segmentation )

Steps to the previous undo level. The data which has been saved before the last modifications will be restored.

mitkIpBool_t ipMITKSegmentationUndoAvailable ( mitkIpPicDescriptor *  segmentation )

Checks if any data for undo is available. pending?

void ipMITKSegmentationUndoDisable ( mitkIpPicDescriptor *  segmentation )

Disables the undo operation for the specified segmentation. The available data will be discarded.

Parameters:
segmentationthe segmentation
void ipMITKSegmentationUndoEnable ( mitkIpPicDescriptor *  segmentation,
const mitkIpUInt1_t  level 
)

Enables the undo operation for the specified segmentation.

Parameters:
segmentationthe segmentation
levelthe number of undo levels
mitkIpBool_t ipMITKSegmentationUndoIsEnabled ( mitkIpPicDescriptor *  segmentation )

Checks if the undo operation is enabled.

Parameters:
segmentationthe segmentation

Referenced by ipMITKSegmentationGrowRegion4N(), and ipMITKSegmentationReplaceRegion4N().

void ipMITKSegmentationUndoSave ( mitkIpPicDescriptor *  segmentation )

Save the segmentation image before it is changed.

Parameters:
segmentationthe segmentation

Referenced by ipMITKSegmentationGrowRegion4N(), and ipMITKSegmentationReplaceRegion4N().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines