Пример #1
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;
}
Пример #2
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;
}