コード例 #1
0
  /*
   * Load two input files and use adapters to obtain corresponding ImageObject objects.
   * These objects are the basis of the metric calculations.
   *
   * Thus, we could say that these metrics operate upon "pixel features".
   *
   * There does not yet seem to be a "pixel adapter" (which would amount to a kind of
   * "pixel 'pass-through'). To conform to the adapter/descriptor/measure pattern, we
   * will implement such a minimal adapter and also relocate relevant parts of this code into
   * those respective components.
   */
  public Vector load(File f1, File f2) {
    Vector<ImageObject> v = new Vector();
    ImageObjectAdapter a1 = new ImageObjectAdapter();
    ImageObjectAdapter a2 = new ImageObjectAdapter();

    try {
      a1.load(f1);
      a2.load(f2);
    } catch (IOException e) {
      e.printStackTrace();
      return null;
    }

    v.addElement(a1.getImageObject());
    v.addElement(a2.getImageObject());

    return v;
  }
コード例 #2
0
  public static SimilarityNumber unlabeled(String fileName1, String fileName2) throws Exception {
    // unlabeled case: whole image (no labels)
    ImageObjectAdapter a1 = new ImageObjectAdapter();
    if (a1 == null)
      throw new SWIndependenceException("failed to create ImageObjectAdapter adapter for file1");

    ImageObjectAdapter a2 = new ImageObjectAdapter();
    if (a2 == null)
      throw new SWIndependenceException("failed to create ImageObjectAdapter adapter for file2");

    SimilarityNumber result = null;

    try {

      File f1 = new File(fileName1);
      if (f1 == null)
        throw new ImageCompatibilityException("failed to create file object for file1");

      File f2 = new File(fileName2);
      if (f2 == null)
        throw new ImageCompatibilityException("failed to create file object for file2");

      a1.load(f1);
      if (a1 == null) throw new SWIndependenceException("failed to load file1 into adapter1");
      a2.load(f2);
      if (a2 == null) throw new SWIndependenceException("failed to load file2 into adapter2");

      ArrayFeatureExtractor x1 = new ArrayFeatureExtractor();
      if (x1 == null)
        throw new SWIndependenceException(
            "failed to create ArrayFeatureExtractor object for extractor1");

      ArrayFeatureExtractor x2 = new ArrayFeatureExtractor();
      if (x2 == null)
        throw new SWIndependenceException(
            "failed to create ArrayFeatureExtractor object for extractor2");

      ThreeDimensionalDoubleArrayFeature desc1 =
          (ThreeDimensionalDoubleArrayFeature) x1.extract(a1);
      if (desc1 == null)
        throw new SWIndependenceException(
            "failed to extract ThreeDimensionalDoubleArrayFeature feature1 via extractor1");

      ThreeDimensionalDoubleArrayFeature desc2 =
          (ThreeDimensionalDoubleArrayFeature) x2.extract(a2);
      if (desc2 == null)
        throw new SWIndependenceException(
            "failed to extract ThreeDimensionalDoubleArrayFeature feature2 via extractor2");

      AdjustedRandIndexMeasure m = new AdjustedRandIndexMeasure();
      if (m == null)
        throw new SWIndependenceException(
            "failed to create AdjustedRandIndexMeasure object for measure");

      result = m.compare(desc1, desc2);
      if (result == null)
        throw new SingularityTreatmentException("received null comparison result");

      String SEP = ",";
      String rString =
          fileName1
              + SEP
              + fileName2
              + SEP
              + "ImageObjectAdapter"
              + SEP
              + "ThreeDimensionalDoubleArrayFeature"
              + SEP
              + "AdjustedRandIndexMeasure"
              + SEP
              + result.getValue();
      System.out.println(rString);

    } catch (IOException e) {
      throw new SWIndependenceException("failed to load file via adapter into memory");
    }

    return result;
  }