private int countLeaves(Node node) { int count = 0; if (node.children == null) { count = node.result.numClusters(); } else { for (int i=0; i<node.result.numClusters(); i++) { count += countLeaves(node.children[i]); } } return count; }
private void writeNodeASCII(PrintWriter writer, final Node node) throws IOException { //write node type if (node.children == null) writer.write("L\n"); //intermediate else writer.write("I\n"); //leaf //write result data node.result.writeASCII(writer); // node.result.writeASCII(writer, false); writer.flush(); //write children if (node.children != null) { for (int i=0; i<node.result.numClusters(); i++) { writeNodeASCII(writer, node.children[i]); } } }
private Node readNode(HierarchicalByteKMeansResult hBytekm, Scanner reader) throws IOException { String line; while ((line = reader.nextLine()).length()==0) {/*do nothing*/} char type = line.charAt(0); //read result data Node node = new Node(); node.result = new ByteCentroidsResult(); node.result.readASCII(reader); if (type == 'I') { node.children = new Node[node.result.numClusters()]; for (int i=0; i<node.result.numClusters(); i++) { node.children[i] = readNode(hBytekm,reader); } } else { node.children = null; } return node ; }
private void writeNodeB(DataOutput dos, Node node) throws IOException { //write node type char type; if (node.children == null) type='L'; //intermediate else type='I'; //leaf dos.writeByte(type); //write result data node.result.writeBinary(dos); //write children if (node.children != null) { for (int i=0; i<node.result.numClusters(); i++) { writeNodeB(dos, node.children[i]); } } }
private Node readNodeB(HierarchicalByteKMeansResult hBytekm, DataInput dis) throws IOException { Node node = new Node(); char type = (char) dis.readByte(); //read result data node.result = new ByteCentroidsResult(); node.result.readBinary(dis); if (type == 'I') { node.children = new Node[node.result.numClusters()]; for (int i=0; i<node.result.numClusters(); i++) { node.children[i] = readNodeB(hBytekm, dis); } } else { node.children = null; } return node ; }
@Override public DoubleFV createFeature(final MBFImage image) { if (this.rabc == null) { try { final ByteCentroidsResult clusterer = IOUtils.read(Mode.class .getResourceAsStream("/org/openimaj/demos/codebooks/random-100-highfield-codebook.voc"), ByteCentroidsResult.class); this.rabc = new ExactByteAssigner(clusterer); this.fv = new DoubleFV(clusterer.numClusters()); this.engine.getOptions().setDoubleInitialImage(false); } catch (final IOException e) { e.printStackTrace(); } } FImage img = Transforms.calculateIntensity(image); img = ResizeProcessor.halfSize(img); final List<Keypoint> keys = this.engine.findFeatures(img); for (final Keypoint keypoint : keys) { image.drawPoint(new Point2dImpl(keypoint.x * 2f, keypoint.y * 2f), RGBColour.RED, 3); } Arrays.fill(this.fv.values, 0); for (final Keypoint k : keys) { this.fv.values[this.rabc.assign(k.ivec)]++; } return this.fv; }
@Override public DoubleFV createFeature(final MBFImage image) { if (this.rabc == null) { try { final ByteCentroidsResult clusterer = IOUtils.read(Mode.class .getResourceAsStream("/org/openimaj/demos/codebooks/random-100-highfield-codebook.voc"), ByteCentroidsResult.class); this.rabc = new ExactByteAssigner(clusterer); this.fv = new DoubleFV(clusterer.numClusters()); this.engine.getOptions().setDoubleInitialImage(false); } catch (final IOException e) { e.printStackTrace(); } } FImage img = Transforms.calculateIntensity(image); img = ResizeProcessor.halfSize(img); final List<Keypoint> keys = this.engine.findFeatures(img); for (final Keypoint keypoint : keys) { image.drawPoint(new Point2dImpl(keypoint.x * 2f, keypoint.y * 2f), RGBColour.RED, 3); } Arrays.fill(this.fv.values, 0); for (final Keypoint k : keys) { this.fv.values[this.rabc.assign(k.ivec)]++; } return this.fv; }