예제 #1
0
void  SegmentorOTSU::MakeNanWhenLesOrEqualZero (Matrix&  m)
{
  kkint32  r, c;
  double**  data = m.DataNotConst ();
  for  (r = 0;  r < m.NumOfRows ();  ++r)
  {
    double*  dataRow = data[r];
    for  (c = 0;  c < m.NumOfCols ();  ++c)
    {
      if  (dataRow[c] <= 0.0)
        dataRow[c] = NaN;
    }
  }
}  /* MakeNanWhenLesOrEqualZero */
예제 #2
0
void  SegmentorOTSU::ZeroOutNaN (Matrix&  m)
{
  double**  data = m.DataNotConst ();
  kkuint32  numOfRows = m.NumOfRows ();
  kkuint32  numOfCols = m.NumOfCols ();

  kkuint32  r, c;
  for  (r = 0;  r < numOfRows;  ++r)
  {
    double*  dataRow = data[r];
    for  (c = 0;  c < numOfCols;  ++c)
    {
      if  (IsNaN (dataRow[c]))
        dataRow[c] = 0.0;
    }
  }
}  /* ZeroOutNaN */
예제 #3
0
Matrix  SegmentorOTSU::DotDiv (const Matrix&  left,
                               const Matrix&  right
                              )
{
  kkint32  maxNumOfRows = Max (left.NumOfRows (), right.NumOfRows ());
  kkint32  maxNumOfCols = Max (left.NumOfCols (), right.NumOfCols ());
  
  kkint32  minNumOfRows = Min (left.NumOfRows (), right.NumOfRows ());
  kkint32  minNumOfCols = Min (left.NumOfCols (), right.NumOfCols ());

  Matrix  result (maxNumOfRows, maxNumOfCols);

  double const * const * leftData   = left.Data  ();
  double const * const * rightData  = right.Data ();
  double**               resultData = result.DataNotConst ();

  kkint32  r, c;

  for  (r = 0;  r < minNumOfRows;  ++r)
  {
    double const *  leftDataRow   = leftData[r];
    double const *  rightDataRow  = rightData[r];
    double*         resultDataRow = resultData[r];

    for  (c = 0;  c < minNumOfCols;  ++c)
      resultDataRow[c] = leftDataRow[c] / rightDataRow[c];
  }

  for  (r = minNumOfRows;  r < maxNumOfRows;  ++r)
  {
    double*  resultDataRow = resultData[r];
    for  (c = minNumOfCols;  c < maxNumOfCols;  ++c)
    {
      if  ((r >= right.NumOfRows ())  ||  (c >= right.NumOfCols ()))
        resultDataRow[c] = NaN;

      else if  (rightData[r][c] == 0.0)
        resultDataRow[c] = NaN;

      else
        resultDataRow[c] = 0.0;
    }
  }

  return  result;
}  /* DotDiv */
예제 #4
0
Matrix  SegmentorOTSU::Power (const Matrix&  left,
                              double         right
                             )
{
  kkuint32 numOfRows = left.NumOfRows ();
  kkuint32 numOfCols = left.NumOfCols ();

  Matrix  result (numOfRows, numOfCols);
  double const * const *  leftData = left.Data ();
  double**  resultData = result.DataNotConst ();

  kkuint32  r, c;
  for  (r = 0;  r < numOfRows;  ++r)
  {
    double const *  leftDataRow = leftData[r];
    double*  resultDataRow = resultData[r];
    for  (c = 0;  c < numOfCols;  ++c)
      resultDataRow[c] = pow (leftDataRow[c], right);
  }
  return  result;
}  /* Power */