Example #1
0
ZSwcTree* ZSwcGenerator::createSwc(
    const ZObject3dScan &blockObj, int z, const ZDvidInfo &dvidInfo)
{
#ifdef _FLYEM_
  ZObject3dScan slice = blockObj.getSlice(z);
  size_t stripeNumber = slice.getStripeNumber();

  ZSwcTree *tree = new ZSwcTree;
  for (size_t s = 0; s < stripeNumber; ++s) {
    const ZObject3dStripe &stripe = slice.getStripe(s);
    int nseg = stripe.getSegmentNumber();
    int y = stripe.getY();
    int z = stripe.getZ();
    for (int i = 0; i < nseg; ++i) {
      int x0 = stripe.getSegmentStart(i);
      int x1 = stripe.getSegmentEnd(i);
      for (int x = x0; x <= x1; ++x) {
        ZIntCuboid cuboid = dvidInfo.getBlockBox(x, y, z);
        tree->merge(createBoxSwc(cuboid));
      }
    }
  }

  return tree;
#else
  UNUSED_PARAMETER(&blockObj);
  UNUSED_PARAMETER(z);
  UNUSED_PARAMETER(&dvidInfo);
  return NULL;
#endif
}
Example #2
0
Stack *ZFlyEmNeuronImageFactory::createSurfaceImage(const ZObject3dScan &obj) const
{
  Stack *stack = NULL;
  if (!obj.isEmpty()) {
    ZObject3dScan tmpObj = obj;
    tmpObj.downsampleMax(m_downsampleInterval[0], m_downsampleInterval[1],
        m_downsampleInterval[2]);

    int offset[3] = { 0, 0, 0 };
    tmpObj.switchYZ();
    Stack *objStack = tmpObj.toStack(offset);
    offset[1] -= 1500 / (m_downsampleInterval[2] + 1); //hard-coded calibration, need modification later

    stack = misc::computeNormal(objStack, NeuTube::Z_AXIS);
    C_Stack::kill(objStack);

    int height= C_Stack::height(stack);
    if (m_sizePolicy[2] == SIZE_SOURCE) {
      height = m_sourceDimension[2];

      if (m_downsampleInterval[2] > 0) {
        height /= m_downsampleInterval[2] + 1;
        height += 1;
      }
    }
    if (height > C_Stack::height(stack)) {
      Stack *out = C_Stack::crop(stack, 0, -offset[1], 0, C_Stack::width(stack),
          height, 1, NULL);
      C_Stack::kill(stack);
      stack = out;
    }
  }

  return stack;
}
Example #3
0
Stack* ZFlyEmNeuronImageFactory::createImage(const ZObject3dScan &obj) const
{
  Stack *stack = NULL;
  if (!obj.isEmpty()) {
    ZObject3dScan objProj = obj.makeYProjection();
    objProj.downsampleMax(m_downsampleInterval[0], m_downsampleInterval[2], 0);
    Cuboid_I boundBox;
    objProj.getBoundBox(&boundBox);

    int width = 0;
    int height = 0;
    //int depth = 0;
    if (m_sizePolicy[0] == SIZE_SOURCE) {
      width = m_sourceDimension[0] / (m_downsampleInterval[0] + 1) + 1;
    }
    if (m_sizePolicy[2] == SIZE_SOURCE) {
      height = m_sourceDimension[2];

      if (m_downsampleInterval[2] > 0) {
        height /= m_downsampleInterval[2] + 1;
        height += 1;
      }
    }
    /*
    if (m_sizePolicy[2] == SIZE_SOURCE) {
      depth = m_sourceDimension[2];
    }
    */

    int offset[3] = { 0, 0, 0 };
    if (width == 0) {
      width = Cuboid_I_Width(&boundBox);
      offset[0] = -boundBox.cb[0];
    }
    if (height == 0) {
      height = Cuboid_I_Height(&boundBox);
      offset[1] = -boundBox.cb[1];
    }
    /*
    if (depth == 0) {
      depth = Cuboid_I_Depth(&boundBox);
      offset[2] = -boundBox.cb[2];
    }
    */

    if (width > 0 && height > 0/* && depth > 0*/) {
      stack = C_Stack::make(GREY, width, height, 1);
      C_Stack::setZero(stack);
      objProj.drawStack(stack, 255, offset);
    }
  }

  return stack;
}
Example #4
0
ZObject3dScan ZDvidInfo::getBlockIndex(const ZIntCuboidArray &boxArray) const
{
  ZObject3dScan obj;
  for (ZIntCuboidArray::const_iterator iter = boxArray.begin();
       iter != boxArray.end(); ++iter) {
    const ZIntCuboid &box = *iter;
    obj.unify(getBlockIndex(box));
  }

  return obj;
}
Example #5
0
ZObject3dScan ZDvidInfo::getBlockIndex(const ZObject3dScan &obj) const
{
  ZIntPoint gridSize = m_endBlockIndex - m_startBlockIndex + 1;
  size_t area = ((size_t) gridSize.getX()) * gridSize.getY();
  size_t blockNumber = area * gridSize.getZ();
  std::vector<bool> isAdded(blockNumber, false);

  //std::set<ZIntPoint> blockSet;
  //ZIntPointArray blockArray;
  ZObject3dScan blockObj;

  for (size_t i = 0; i < obj.getStripeNumber(); ++i) {
#ifdef _DEBUG_2
    if (i % 10000 == 0) {
      std::cout << i << "/" << obj.getStripeNumber() << std::endl;
    }
#endif
    const ZObject3dStripe &stripe = obj.getStripe(i);
    int y = stripe.getY();
    int z = stripe.getZ();
    if (y > 0 && z > 0 && y < m_startCoordinates[1] + m_stackSize[1] &&
        z < m_startCoordinates[2] + m_stackSize[2]) {
      for (int j = 0; j < stripe.getSegmentNumber(); ++j) {
        int x0 = stripe.getSegmentStart(j);
        int x1 = stripe.getSegmentEnd(j);
        if (x0 < 0) {
          x0 = 0;
        } else if (x0 >= m_startCoordinates[0] + m_stackSize[0]) {
          x0 = m_startCoordinates[0] + m_stackSize[0] - 1;
        }

        if (x1 < 0) {
          x1 = 0;
        } else if (x1 >= m_startCoordinates[0] + m_stackSize[0]) {
          x1 = m_startCoordinates[0] + m_stackSize[0] - 1;
        }

        ZIntPoint block1 = getBlockIndex(x0, y, z);
        size_t blockIndex1 = area * block1.getZ() +
            gridSize.getY() * block1.getY() + block1.getX();
        ZIntPoint block2 = getBlockIndex(x1, y, z);
        size_t blockIndex2 = area * block2.getZ() +
            gridSize.getY() * block2.getY() + block2.getX();

        if (!isAdded[blockIndex1] || !isAdded[blockIndex2]) {
          blockObj.addSegment(
                block1.getZ(), block1.getY(), block1.getX(), block2.getX(), false);
          isAdded[blockIndex1] = true;
          isAdded[blockIndex2] = true;
        }
      }
    }
  }

  //blockArray.append(blockSet.begin(), blockSet.end());
  blockObj.canonize();

  return blockObj;
}
Example #6
0
void ZSparseObject::append(const ZObject3dScan &obj)
{
  for (size_t i = 0; i < obj.getStripeNumber(); ++i) {
    m_stripeArray.push_back(obj.getStripe(i));
  }
}
Example #7
0
QList<ZObject3dScan*> ZFlyEmBodyMergeDoc::extractAllObject()
{
  QList<ZObject3dScan*> objList;

  if (m_originalLabel == NULL) {
    return objList;
  }

  if (m_originalLabel->isEmpty()) {
    return objList;
  }

  ZFlyEmBodyMerger::TLabelMap finalMap = m_bodyMerger.getFinalMap();

  std::map<uint64_t, ZObject3dScan*> bodySet;
  uint64_t *array = m_originalLabel->getDataPointer<uint64_t>();
  int width = m_originalLabel->getDim(0);
  int height = m_originalLabel->getDim(1);
  int depth = m_originalLabel->getDim(2);
  int x0 = m_originalLabel->getStartCoordinate(0);
  int y0 = m_originalLabel->getStartCoordinate(1);
  int z0 = m_originalLabel->getStartCoordinate(2);


  ZObject3dScan *obj = NULL;
  for (int z = 0; z < depth; ++z) {
    for (int y = 0; y < height; ++y) {
      int x = 0;
      while (x < width) {
        uint64_t v = array[x];
        if (finalMap.contains(v)) {
          v = finalMap[v];
        }
        std::map<uint64_t, ZObject3dScan*>::iterator iter = bodySet.find(v);
        if (iter == bodySet.end()) {
          obj = new ZObject3dScan;
          obj->setLabel(v);
          //(*bodySet)[v] = obj;
          bodySet.insert(std::map<uint64_t, ZObject3dScan*>::value_type(v, obj));
        } else {
          obj = iter->second;
        }
        int length = obj->scanArray(array, x, y + y0, z + z0, width, x0);
        x += length;
      }
      array += width;
    }
  }

  for (std::map<uint64_t, ZObject3dScan*>::iterator iter = bodySet.begin();
       iter != bodySet.end(); ++iter) {
    ZObject3dScan *obj = iter->second;
    obj->setRole(ZStackObjectRole::ROLE_SEGMENTATION);
    QColor color = m_objColorSheme.getColor(abs((int) obj->getLabel()));
    color.setAlpha(64);
    obj->setColor(color);
    objList.append(obj);
  }

  return objList;
}
Example #8
0
int main(int argc, char *argv[])
{
  if (Show_Version(argc, argv, "0.1") == 1) {
    return 0;
  }

  static char const *Spec[] = {
    "<input:string> [-o <string>]",
    "[--landmark <string>]", "[--intv <int> <int> <int>]",
    "[--minloop <int(100)>]", "[--bound_adjust]",
    NULL};

  ZArgumentProcessor::processArguments(argc, argv, Spec);

  const char *input =
          ZArgumentProcessor::getStringArg(const_cast<char*>("input"));

  cout << "Loading object ..." << endl;

  ZObject3dScan obj;

  if (ZFileType::fileType(input) == ZFileType::OBJECT_SCAN_FILE) {
    obj.load(input);
  } else if (ZFileType::fileType(input) == ZFileType::TIFF_FILE) {
    ZStack stack;
    stack.load(input);
    if (stack.channelNumber() > 1) {
      cout << "  More than one channel found. Only the first channel will be loaded" << endl;
    }
    Stack_Binarize(stack.c_stack(0));
    obj.loadStack(stack.c_stack(0));
  } else {
    cout << "Invalid input. Abort." << endl;
    return 1;
  }

  if (!obj.isEmpty()) {
    if (ZArgumentProcessor::isArgMatched("--landmark")) {
      ZPointArray pts;
      const char *landmark = ZArgumentProcessor::getStringArg("--landmark");
      ZFlyEmBodyAnalyzer bodyAnalyzer;
      int intv[3] = {0, 0, 0};
      bool usingDefaultIntv = true;
      if (ZArgumentProcessor::isArgMatched("--intv")) {
        for (int i = 0; i < 3; ++i) {
          intv[i] = ZArgumentProcessor::getIntArg("--intv", i + 1);
        }
        usingDefaultIntv = false;
      }

      if (eqstr(landmark, "hole")) {
        if (usingDefaultIntv) {
          intv[0] = 1;
          intv[1] = 1;
          intv[2] = 0;
        }

        bodyAnalyzer.setDownsampleInterval(intv[0], intv[1], intv[2]);

        cout << "Examining holes ..." << endl;
        pts = bodyAnalyzer.computeHoleCenter(obj);
      } else if (eqstr(landmark, "terminal")) {
        if (usingDefaultIntv) {
          intv[0] = 1;
          intv[1] = 1;
          intv[2] = 1;
        }

        bodyAnalyzer.setDownsampleInterval(intv[0], intv[1], intv[2]);

        cout << "Examining termini ..." << endl;
        pts = bodyAnalyzer.computeTerminalPoint(obj);
      } else if (eqstr(landmark, "loop")) {
        if (usingDefaultIntv) {
          intv[0] = 1;
          intv[1] = 1;
          intv[2] = 1;
        }

        bodyAnalyzer.setDownsampleInterval(intv[0], intv[1], intv[2]);
        bodyAnalyzer.setMinLoopSize(ZArgumentProcessor::getIntArg("--minloop"));
        pts = bodyAnalyzer.computeLoopCenter(obj);
      } else {
        cout << "Invalid landmark, which must be one one of the following:" << endl;
        cout << "  hole, terminal" << endl;
        return 1;
      }

      if (!pts.empty()) {
        cout << "Saving results ...";
        if (ZArgumentProcessor::isArgMatched("--bound_adjust")) {
          ZCuboid box = obj.getBoundBox();
          ZPoint corner = box.firstCorner();
          corner *= -1;
          pts.translate(corner);
        }

        std::string output = ZArgumentProcessor::getStringArg("-o");
        switch (ZFileType::fileType(output)) {
        case ZFileType::SWC_FILE:
            pts.exportSwcFile(output, 3.0);
            break;
        case ZFileType::JSON_FILE:
            pts.exportJsonFile(output);
            break;
        default:
            cout << "Unknown output format. Saved as csv file" << endl;
            pts.exportCsvFile(output);
            break;
        }

        cout << output << " saved." << endl;
      } else {
        cout << "No landmark found." << endl;
        return 0;
      }
    }
  } else {
    cout << "Invalid or empty object. Abort." << endl;
    return 1;
  }

  return 0;
}