private void parseROIs(MetadataStore store) throws IOException { if (roiFile == null) return; String roiData = DataTools.readFile(roiFile); String[] lines = roiData.split("\r\n"); int firstRow = 0; while (firstRow < lines.length && !lines[firstRow].startsWith("ROI")) { firstRow++; } firstRow += 2; if (firstRow >= lines.length) return; for (int i = firstRow; i < lines.length; i++) { String[] cols = lines[i].split("\t"); if (cols.length < 6) break; if (cols[2].trim().length() > 0) { String rectangleID = MetadataTools.createLSID("Shape", i - firstRow, 0); store.setRectangleID(rectangleID, i - firstRow, 0); store.setRectangleX(new Double(cols[2]), i - firstRow, 0); store.setRectangleY(new Double(cols[3]), i - firstRow, 0); store.setRectangleWidth(new Double(cols[4]), i - firstRow, 0); store.setRectangleHeight(new Double(cols[5]), i - firstRow, 0); String roiID = MetadataTools.createLSID("ROI", i - firstRow); store.setROIID(roiID, i - firstRow); for (int s = 0; s < getSeriesCount(); s++) { store.setImageROIRef(roiID, s, i - firstRow); } } } }
private void parseROIs(MetadataStore store) throws FormatException, IOException { if (MetadataTools.isOMEXMLMetadata(store) || MetadataTools.isOMEXMLRoot(store.getRoot())) { return; } String roiID = MetadataTools.createLSID("ROI", 0, 0); String maskID = MetadataTools.createLSID("Shape", 0, 0); store.setROIID(roiID, 0); store.setMaskID(maskID, 0, 0); String positionData = DataTools.readFile(roiDrawFile); String[] coordinates = positionData.split("[ ,]"); double x1 = Double.parseDouble(coordinates[1]); double y1 = Double.parseDouble(coordinates[2]); double x2 = Double.parseDouble(coordinates[3]); double y2 = Double.parseDouble(coordinates[5]); store.setMaskX(x1, 0, 0); store.setMaskY(y1, 0, 0); store.setMaskWidth(x2 - x1, 0, 0); store.setMaskHeight(y2 - y1, 0, 0); store.setImageROIRef(roiID, 0, 0); ImageReader roiReader = new ImageReader(); roiReader.setId(roiFile); byte[] roiPixels = roiReader.openBytes(0); roiReader.close(); BitWriter bits = new BitWriter(roiPixels.length / 8); for (int i = 0; i < roiPixels.length; i++) { bits.write(roiPixels[i] == 0 ? 0 : 1, 1); } store.setMaskBinData(bits.toByteArray(), 0, 0); }