Exemplo n.º 1
0
  public void integrateStackStart(IntegrateExp integrator) {
    curBgInside.clear();
    curBgOutside.clear();

    //		curBgInt = 0;
    //		curBgVol = 0;
    // Zero out arrays
    sliceExp = new double[numSubDiv];
    sliceVol = new int[numSubDiv];
  }
  /**
   * Fills all keys contained in the receiver into the specified list. Fills the list, starting at
   * index 0. After this call returns the specified list has a new size that equals
   * <tt>this.size()</tt>. Iteration order is guaranteed to be <i>identical</i> to the order used by
   * method {@link #forEachKey(IntProcedure)}.
   *
   * <p>This method can be used to iterate over the keys of the receiver.
   *
   * @param list the list to be filled, can have any size.
   */
  public void keys(IntArrayList list) {
    list.setSize(distinct);
    int[] elements = list.elements();

    int[] tab = table;
    byte[] stat = state;

    int j = 0;
    for (int i = tab.length; i-- > 0; ) {
      if (stat[i] == FULL) elements[j++] = tab[i];
    }
  }
  /**
   * Fills all pairs satisfying a given condition into the specified lists. Fills into the lists,
   * starting at index 0. After this call returns the specified lists both have a new size, the
   * number of pairs satisfying the condition. Iteration order is guaranteed to be <i>identical</i>
   * to the order used by method {@link #forEachKey(IntProcedure)}.
   *
   * <p><b>Example:</b> <br>
   *
   * <pre>
   * IntDoubleProcedure condition = new IntDoubleProcedure() { // match even keys only
   *   public boolean apply(int key, double value) { return key%2==0; }
   * }
   * keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt>
   * </pre>
   *
   * @param condition the condition to be matched. Takes the current key as first and the current
   *     value as second argument.
   * @param keyList the list to be filled with keys, can have any size.
   * @param valueList the list to be filled with values, can have any size.
   */
  public void pairsMatching(
      final IntDoubleProcedure condition,
      final IntArrayList keyList,
      final DoubleArrayList valueList) {
    keyList.clear();
    valueList.clear();

    for (int i = table.length; i-- > 0; ) {
      if (state[i] == FULL && condition.apply(table[i], values[i])) {
        keyList.add(table[i]);
        valueList.add(values[i]);
      }
    }
  }
Exemplo n.º 4
0
  /** Stable median calculation. */
  public double calcStableMedian(double lowerFrac, double upperFrac, IntArrayList list) {
    // This works for any size!
    list.trimToSize();
    Arrays.sort(list.elements());

    int sum = 0;
    int cnt = 0;
    for (int i = (int) (lowerFrac * list.size()); i < (int) (list.size() * upperFrac); i++) {
      sum += list.get(i);
      cnt++;
    }
    return (double) sum / cnt;

    // below is the original. it Relies on bucket-sorting. It should be perfectly possible to write
    // a linear-time stable median
    // based on the normal linear-time median algorithm. This is needed to handle non-8bit images.
    // Value might be off a bit but not much (need to think of indexing), and it doesn't matter for
    // this application
    /*
    int numbins=66000;
    int[] elem=list.elements();
    int numElem=list.size();

    //Calculate histogram
    int[] histogram=new int[numbins];
    //int[] elem=curBgOutside.elements();
    //int numElem=curBgOutside.size();
    for(int i=0;i<numElem;i++)
    	histogram[elem[i]]++;

    int jumpElem=0;
    int lowerIndex=(int)(numElem*lowerFrac);
    int upperIndex=(int)(numElem*upperFrac);
    int sum=0;
    int cnt=0;
    for(int i=0;i<numbins;i++)
    	{
    	int thisNum=histogram[i];
    	int take=Math.min(upperIndex,jumpElem+thisNum)-Math.max(lowerIndex, jumpElem);
    	if(take>0)
    		{
    		sum+=take*i;
    		cnt+=take;
    		}
    	jumpElem+=thisNum;
    	}
    return (double)sum/cnt;
    */
  }
Exemplo n.º 5
0
  public void integrateImage(IntegrateExp integrator) {
    integrator.ensureImageLoaded();

    // Calculate distance mask lazily. Assumes shell does not move over time.
    double[] lenMapArr;
    if (distanceMap.containsKey(integrator.curZint)) {
      EvPixels lenMap = distanceMap.get(integrator.curZint);
      lenMapArr = lenMap.getArrayDouble();
    } else {
      EvPixels lenMap =
          new EvPixels(
              EvPixelsType.DOUBLE, integrator.pixels.getWidth(), integrator.pixels.getHeight());
      lenMapArr = lenMap.getArrayDouble();

      ImVector3d dirvec = getDirVec();
      ImVector3d midpos3 = getMidPos();
      ImVector2d shellPos2 = new ImVector2d(shell.midx, shell.midy);
      double invShellMajor2 = 1.0 / (shell.major * shell.major);
      double invShellMinor2 = 1.0 / (shell.minor * shell.minor);
      // double curZ=integrator.curZ.doubleValue();

      // Calculate distances
      for (int ay = 0; ay < integrator.pixels.getHeight(); ay++) {
        int lineIndex = lenMap.getRowIndex(ay);
        for (int ax = 0; ax < integrator.pixels.getWidth(); ax++) {
          // double worldAX=integrator.stack.transformImageWorldX(ax);
          // double worldAY=integrator.stack.transformImageWorldY(ay);

          Vector3d pos2prim =
              integrator.stack.transformImageWorld(new Vector3d(ax, ay, integrator.curZint));
          final ImVector2d pos2 =
              new ImVector2d(pos2prim.x, pos2prim.y); // new ImVector2(worldAX,worldAY);

          // final ImVector2 pos2 = new ImVector2(worldAX,worldAY);
          final ImVector3d pos3 = new ImVector3d(pos2prim.x, pos2prim.y, pos2prim.z);
          //					final ImVector3d pos3 = new ImVector3d(pos2.x,pos2.y,curZ);

          // Check if this is within ellipse boundary
          final ImVector2d elip = pos2.sub(shellPos2).rotate(shell.angle); // TODO angle? what?
          double len;
          if (1 >= elip.y * elip.y * invShellMinor2 + elip.x * elip.x * invShellMajor2) {
            // xy . dirvecx = cos(alpha) ||xy|| ||dirvecx||
            len = pos3.sub(midpos3).dot(dirvec) + 0.5;
            // goes from -0.5 to 0.5 before addition if using proper ellipse. projection makes it
            // wrong!!!
          } else len = -1;
          lenMapArr[lineIndex + ax] = len;
        }
      }
    }

    // Integrate area, separate into slices and background
    // TODO: have we really really checked that this is done properly?
    for (int y = 0; y < integrator.pixels.getHeight(); y++) {
      int lineIndex = integrator.pixels.getRowIndex(y);
      for (int x = 0; x < integrator.pixels.getWidth(); x++) {
        int i = lineIndex + x;
        double len = lenMapArr[i];
        int sliceNum = (int) (len * numSubDiv); // may need to bound in addition
        int thisPixelValue = integrator.pixelsLine[i];
        if (sliceNum >= 0 && sliceNum < sliceExp.length) {
          sliceExp[sliceNum] += thisPixelValue;
          sliceVol[sliceNum]++;

          curBgInside.add(thisPixelValue);
        } else if (len
            == -1) // so things close the embryo will not be considered - likely too bright
        {
          // Measure background. It's all the pixels outside the embryo
          curBgOutside.add(thisPixelValue);
          //					curBgInt += thisPixelValue;
          //					curBgVol++;
        }
      }
    }
  }