/* (non-Javadoc) * @see edu.stanford.cfuller.imageanalysistools.metric.Metric#quantify(edu.stanford.cfuller.imageanalysistools.image.Image, java.util.Vector) */ @Override public Quantification quantify(Image mask, ImageSet images) { int maxRegion = Histogram.findMaxVal(mask); Quantification q = new Quantification(); for (int i = 1; i < maxRegion; i++) { Measurement m = new Measurement(true, i, 0.0, "zero", "zero", images.getMarkerImageName()); q.addMeasurement(m); } return q; }
public static void writeQuantificationMatrix( Collection<? extends Quantification> listOfQuantifications, String outmatrix) throws IOException { Path p = Paths.get(outmatrix); BufferedWriter bf = Files.newBufferedWriter(p, Charset.defaultCharset()); int index = 0; for (Quantification tq : listOfQuantifications) { if (index == 0) { bf.append(tq.printHeader()); bf.append("\n"); } index++; tq.appendTo(bf); bf.append("\n"); } bf.close(); }
/** * SIGH... * * @return */ public BNF toBNF() { // first thing first, make a deep copy of current EBNF // then play / return with the copy EBNF ebnf = clone(); // auto generate new non terminal names StringIterator quanNames = new StringIterator("quan_{000}"); int oldHash = ebnf.hashCode(); int newHash = ebnf.hashCode(); boolean exceptionTriggered; do { oldHash = newHash; exceptionTriggered = false; Iterator<NonTerminal> i = ebnf.nonTerminals.keySet().iterator(); try { // travel through all non terminals while (i.hasNext()) { NonTerminal iii = i.next(); Iterator<? extends EBNFBranch> j = ebnf.nonTerminals.get(iii).iterator(); // travel through all branches for each non terminal while (j.hasNext()) { EBNFBranch jjj = j.next(); List l = jjj.getElementList(); // travel through all elements for each branch for (int n = 0; n < l.size(); n++) { if (l.get(n) instanceof Quantification) { // found a quantification Quantification q = ((Quantification) l.get(n)); // substitude it with a new non terminal NonTerminal newnt = new NonTerminal(quanNames.next()); l.set(n, newnt); // modify the element list for the new nt a little bit List<EBNFBranch> li = (List<EBNFBranch>) q.getBranchList(); if ((q.getMaxOccurrance() == 1) && (q.getMinOccurrance() == 0)) { // [..] boolean containsEpsilon = false; for (int k = 0; k < li.size(); k++) { if (Terminal.epsilon.equals(li.get(k).getElementList().get(0))) { // this branch contains epsilon // (branches that contain epsilon contains only 1 element) containsEpsilon = true; } } // add new epsilon branch if currently don't have one if (!containsEpsilon) { li.add(new EBNFBranch()); } } else if ((q.getMaxOccurrance() == -1) && (q.getMinOccurrance() == 0)) { boolean containsEpsilon = false; // {...} for (int k = 0; k < li.size(); k++) { if (Terminal.epsilon.equals(li.get(k).getElementList().get(0))) { containsEpsilon = true; // keep the only one epsilon branch untouched } else { // add the new non terminal to the end of // each non epsilon branch li.get(k).getElementList().add(newnt); } } if (!containsEpsilon) { li.add(new EBNFBranch()); } } // add the new non terminal to new EBNF ebnf.nonTerminals.put(newnt, li); } } } } } catch (ConcurrentModificationException e) { exceptionTriggered = true; } newHash = ebnf.hashCode(); } while ((newHash != oldHash) || exceptionTriggered); return new BNF(ebnf.startSymbol, ebnf.nonTerminals); }