コード例 #1
0
 @Override
 public int compare(FinderPattern center1, FinderPattern center2) {
   if (center2.getCount() == center1.getCount()) {
     float dA = Math.abs(center2.getEstimatedModuleSize() - average);
     float dB = Math.abs(center1.getEstimatedModuleSize() - average);
     return dA < dB ? 1 : dA == dB ? 0 : -1;
   } else {
     return center2.getCount() - center1.getCount();
   }
 }
コード例 #2
0
 public int compare(FinderPattern paramFinderPattern1, FinderPattern paramFinderPattern2)
 {
   float f1 = Math.abs(paramFinderPattern2.getEstimatedModuleSize() - this.average);
   float f2 = Math.abs(paramFinderPattern1.getEstimatedModuleSize() - this.average);
   if (f1 < f2) {
     return -1;
   }
   if (f1 == f2) {
     return 0;
   }
   return 1;
 }
コード例 #3
0
  /**
   * @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are those
   *     that have been detected at least {@link #CENTER_QUORUM} times, and whose module size
   *     differs from the average among those patterns the least
   * @throws NotFoundException if 3 such finder patterns do not exist
   */
  private FinderPattern[] selectBestPatterns() throws NotFoundException {

    int startSize = possibleCenters.size();
    if (startSize < 3) {
      // Couldn't find enough finder patterns
      throw NotFoundException.getNotFoundInstance();
    }

    // Filter outlier possibilities whose module size is too different
    if (startSize > 3) {
      // But we can only afford to do so if we have at least 4 possibilities to choose from
      float totalModuleSize = 0.0f;
      float square = 0.0f;
      for (FinderPattern center : possibleCenters) {
        float size = center.getEstimatedModuleSize();
        totalModuleSize += size;
        square += size * size;
      }
      float average = totalModuleSize / (float) startSize;
      float stdDev = (float) Math.sqrt(square / startSize - average * average);

      Collections.sort(possibleCenters, new FurthestFromAverageComparator(average));

      float limit = Math.max(0.2f * average, stdDev);

      for (int i = 0; i < possibleCenters.size() && possibleCenters.size() > 3; i++) {
        FinderPattern pattern = possibleCenters.get(i);
        if (Math.abs(pattern.getEstimatedModuleSize() - average) > limit) {
          possibleCenters.remove(i);
          i--;
        }
      }
    }

    if (possibleCenters.size() > 3) {
      // Throw away all but those first size candidate points we found.

      float totalModuleSize = 0.0f;
      for (FinderPattern possibleCenter : possibleCenters) {
        totalModuleSize += possibleCenter.getEstimatedModuleSize();
      }

      float average = totalModuleSize / (float) possibleCenters.size();

      Collections.sort(possibleCenters, new CenterComparator(average));

      possibleCenters.subList(3, possibleCenters.size()).clear();
    }

    return new FinderPattern[] {
      possibleCenters.get(0), possibleCenters.get(1), possibleCenters.get(2)
    };
  }
コード例 #4
0
 private boolean haveMultiplyConfirmedCenters()
 {
   int i = 0;
   float f1 = 0.0F;
   int j = this.possibleCenters.size();
   Iterator localIterator1 = this.possibleCenters.iterator();
   while (localIterator1.hasNext())
   {
     FinderPattern localFinderPattern = (FinderPattern)localIterator1.next();
     if (localFinderPattern.getCount() >= 2)
     {
       i++;
       f1 += localFinderPattern.getEstimatedModuleSize();
     }
   }
   if (i < 3) {}
   float f3;
   do
   {
     return false;
     float f2 = f1 / j;
     f3 = 0.0F;
     Iterator localIterator2 = this.possibleCenters.iterator();
     while (localIterator2.hasNext()) {
       f3 += Math.abs(((FinderPattern)localIterator2.next()).getEstimatedModuleSize() - f2);
     }
   } while (f3 > 0.05F * f1);
   return true;
 }
コード例 #5
0
 /**
  * @return true iff we have found at least 3 finder patterns that have been detected at least
  *     {@link #CENTER_QUORUM} times each, and, the estimated module size of the candidates is
  *     "pretty similar"
  */
 private boolean haveMultiplyConfirmedCenters() {
   int confirmedCount = 0;
   float totalModuleSize = 0.0f;
   int max = possibleCenters.size();
   for (FinderPattern pattern : possibleCenters) {
     if (pattern.getCount() >= CENTER_QUORUM) {
       confirmedCount++;
       totalModuleSize += pattern.getEstimatedModuleSize();
     }
   }
   if (confirmedCount < 3) {
     return false;
   }
   // OK, we have at least 3 confirmed centers, but, it's possible that one is a "false positive"
   // and that we need to keep looking. We detect this by asking if the estimated module sizes
   // vary too much. We arbitrarily say that when the total deviation from average exceeds
   // 5% of the total module size estimates, it's too much.
   float average = totalModuleSize / (float) max;
   float totalDeviation = 0.0f;
   for (FinderPattern pattern : possibleCenters) {
     totalDeviation += Math.abs(pattern.getEstimatedModuleSize() - average);
   }
   return totalDeviation <= 0.05f * totalModuleSize;
 }
コード例 #6
0
 @Override
 public int compare(FinderPattern center1, FinderPattern center2) {
   float dA = Math.abs(center2.getEstimatedModuleSize() - average);
   float dB = Math.abs(center1.getEstimatedModuleSize() - average);
   return dA < dB ? -1 : dA == dB ? 0 : 1;
 }