Compare commits
No commits in common. "8e3a59929418c70b9b70164072d7d6eca55dae16" and "d6c0c9fd30ecf71563f146ebf369895a94fa627c" have entirely different histories.
8e3a599294
...
d6c0c9fd30
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>jp.riken.neurodata.tools.BioFormatsImageInfo</groupId>
|
<groupId>jp.riken.neurodata.tools.BioFormatsImageInfo</groupId>
|
||||||
<artifactId>bioformats-imageinfo</artifactId>
|
<artifactId>bioformats-imageinfo</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.0.0</version>
|
||||||
|
|
||||||
<name>bioformats-imageinfo</name>
|
<name>bioformats-imageinfo</name>
|
||||||
<url>https://neurodata.riken.jp</url>
|
<url>https://neurodata.riken.jp</url>
|
||||||
|
@ -24,259 +24,257 @@ import loci.formats.tools.ImageInfo;
|
|||||||
|
|
||||||
public class BioFormatsImageInfo {
|
public class BioFormatsImageInfo {
|
||||||
|
|
||||||
protected static Map<String, Object> readImages(final IFormatReader reader) throws FormatException, IOException {
|
protected static Map<String, Object> readImages(final IFormatReader reader) throws FormatException, IOException {
|
||||||
final Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
// read basic metadata
|
// read basic metadata
|
||||||
final int seriesCount = reader.getSeriesCount();
|
final int seriesCount = reader.getSeriesCount();
|
||||||
final MetadataStore ms = reader.getMetadataStore();
|
final MetadataStore ms = reader.getMetadataStore();
|
||||||
final MetadataRetrieve mr = ms instanceof MetadataRetrieve ? (MetadataRetrieve) ms : null;
|
final MetadataRetrieve mr = ms instanceof MetadataRetrieve ? (MetadataRetrieve) ms : null;
|
||||||
for (int j = 0; j < seriesCount; j++) {
|
for (int j = 0; j < seriesCount; j++) {
|
||||||
|
|
||||||
// read basic metadata for series #j
|
// read basic metadata for series #j
|
||||||
reader.setSeries(j);
|
reader.setSeries(j);
|
||||||
final Map<String, Object> seriesMetadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> seriesMetadata = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
final int imageCount = reader.getImageCount();
|
final int imageCount = reader.getImageCount();
|
||||||
final int resolutionCount = reader.getResolutionCount();
|
final int resolutionCount = reader.getResolutionCount();
|
||||||
final String seriesName = mr == null ? null : mr.getImageName(j);
|
final String seriesName = mr == null ? null : mr.getImageName(j);
|
||||||
if (seriesName != null) {
|
if (seriesName != null) {
|
||||||
seriesMetadata.put("name", seriesName);
|
seriesMetadata.put("name", seriesName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolutions
|
// resolutions
|
||||||
if (resolutionCount > 1) {
|
if (resolutionCount > 1) {
|
||||||
final Map<String, Object> resolutionsMetadata = new LinkedHashMap<String, Object>();
|
final Map<String, Object> resolutionsMetadata = new LinkedHashMap<String, Object>();
|
||||||
for (int i = 0; i < resolutionCount; i++) {
|
for (int i = 0; i < resolutionCount; i++) {
|
||||||
reader.setResolution(i);
|
reader.setResolution(i);
|
||||||
resolutionsMetadata.put(String.format("resolution[%d]", i),
|
resolutionsMetadata.put(String.format("resolution[%d]", i),
|
||||||
makeRectangle(reader.getSizeX(), reader.getSizeY()));
|
makeRectangle(reader.getSizeX(), reader.getSizeY()));
|
||||||
}
|
|
||||||
seriesMetadata.put("resolutions", resolutionsMetadata);
|
|
||||||
reader.setResolution(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
seriesMetadata.put("imageCount", imageCount);
|
|
||||||
seriesMetadata.put("RGB", new Object[] { reader.isRGB(), reader.getRGBChannelCount() });
|
|
||||||
seriesMetadata.put("interleaved", reader.isInterleaved());
|
|
||||||
|
|
||||||
// indexed
|
|
||||||
{
|
|
||||||
final List<Object> indexed = new ArrayList<Object>();
|
|
||||||
indexed.add(reader.isIndexed());
|
|
||||||
indexed.add(String.format("%b color", !reader.isFalseColor()));
|
|
||||||
final byte[][] table8 = reader.get8BitLookupTable();
|
|
||||||
if (table8 != null) {
|
|
||||||
indexed.add(
|
|
||||||
String.format("8-bit LUT: %d x %s", table8.length,
|
|
||||||
table8[0] == null ? "null" : "" + table8[0].length));
|
|
||||||
}
|
|
||||||
final short[][] table16 = reader.get16BitLookupTable();
|
|
||||||
if (table16 != null) {
|
|
||||||
indexed.add(String.format("16-bit LUT: %d x %s", table16.length,
|
|
||||||
table16[0] == null ? "null" : "" + table16[0].length));
|
|
||||||
}
|
|
||||||
seriesMetadata.put("indexed", indexed);
|
|
||||||
}
|
|
||||||
|
|
||||||
seriesMetadata.put("sizeX", reader.getSizeX());
|
|
||||||
seriesMetadata.put("sizeY", reader.getSizeY());
|
|
||||||
final int sizeZ = reader.getSizeZ();
|
|
||||||
seriesMetadata.put("sizeZ", makeDimension(sizeZ, sizeZ, reader.getModuloZ()));
|
|
||||||
seriesMetadata.put("sizeC",
|
|
||||||
makeDimension(reader.getSizeC(), reader.getEffectiveSizeC(), reader.getModuloC()));
|
|
||||||
final int sizeT = reader.getSizeT();
|
|
||||||
seriesMetadata.put("sizeT", makeDimension(sizeT, sizeT, reader.getModuloT()));
|
|
||||||
seriesMetadata.put("tileSize", makeRectangle(reader.getOptimalTileWidth(), reader.getOptimalTileHeight()));
|
|
||||||
seriesMetadata.put("thumbnailSize", makeRectangle(reader.getThumbSizeX(), reader.getThumbSizeY()));
|
|
||||||
seriesMetadata.put("endianness", reader.isLittleEndian() ? "little" : "big");
|
|
||||||
seriesMetadata.put("dimensionOrder",
|
|
||||||
new String[] { reader.getDimensionOrder(), reader.isOrderCertain() ? "certain" : "uncertain" });
|
|
||||||
seriesMetadata.put("pixelType", FormatTools.getPixelTypeString(reader.getPixelType()));
|
|
||||||
seriesMetadata.put("validBitsPerPixel", reader.getBitsPerPixel());
|
|
||||||
seriesMetadata.put("metadataComplete", reader.isMetadataComplete());
|
|
||||||
seriesMetadata.put("thumbnailSeries", reader.isThumbnailSeries());
|
|
||||||
|
|
||||||
// plane
|
|
||||||
{
|
|
||||||
final int[] indices;
|
|
||||||
if (imageCount > 6) {
|
|
||||||
int q = imageCount / 2;
|
|
||||||
indices = new int[] { 0, q - 2, q - 1, q, q + 1, q + 2, imageCount - 1 };
|
|
||||||
} else if (imageCount > 2) {
|
|
||||||
indices = new int[] { 0, imageCount / 2, imageCount - 1 };
|
|
||||||
} else if (imageCount > 1) {
|
|
||||||
indices = new int[] { 0, 1 };
|
|
||||||
} else {
|
|
||||||
indices = new int[] { 0 };
|
|
||||||
}
|
|
||||||
final int[][] zct = new int[indices.length][];
|
|
||||||
final int[] indices2 = new int[indices.length];
|
|
||||||
for (int i = 0; i < indices.length; i++) {
|
|
||||||
zct[i] = reader.getZCTCoords(indices[i]);
|
|
||||||
indices2[i] = reader.getIndex(zct[i][0], zct[i][1], zct[i][2]);
|
|
||||||
final Map<String, Object> planeMetadata = new LinkedHashMap<String, Object>();
|
|
||||||
planeMetadata.put("Z", zct[i][0]);
|
|
||||||
planeMetadata.put("C", zct[i][1]);
|
|
||||||
planeMetadata.put("T", zct[i][2]);
|
|
||||||
if (indices[i] != indices2[i]) {
|
|
||||||
planeMetadata.put("[mismatch]", indices2[i]);
|
|
||||||
}
|
|
||||||
seriesMetadata.put(String.format("plane[%d]", indices[i]), planeMetadata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
metadata.put(String.format("series[%d]", j), seriesMetadata);
|
|
||||||
}
|
}
|
||||||
|
seriesMetadata.put("resolutions", resolutionsMetadata);
|
||||||
|
reader.setResolution(0);
|
||||||
|
}
|
||||||
|
|
||||||
return metadata;
|
seriesMetadata.put("imageCount", imageCount);
|
||||||
}
|
seriesMetadata.put("RGB", new Object[] { reader.isRGB(), reader.getRGBChannelCount() });
|
||||||
|
seriesMetadata.put("interleaved", reader.isInterleaved());
|
||||||
|
|
||||||
protected static Map<String, Object> readAnnotations(final IFormatReader reader) {
|
// indexed
|
||||||
final Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
{
|
||||||
// global metadata
|
final List<Object> indexed = new ArrayList<Object>();
|
||||||
final Hashtable<String, Object> globalMetadata = reader.getGlobalMetadata();
|
indexed.add(reader.isIndexed());
|
||||||
for (String key : MetadataTools.keys(globalMetadata)) {
|
indexed.add(String.format("%b color", !reader.isFalseColor()));
|
||||||
metadata.put(key, globalMetadata.get(key));
|
final byte[][] table8 = reader.get8BitLookupTable();
|
||||||
|
if (table8 != null) {
|
||||||
|
indexed.add(
|
||||||
|
String.format("8-bit LUT: %d x %s", table8.length, table8[0] == null ? "null" : "" + table8[0].length));
|
||||||
}
|
}
|
||||||
// original metadata
|
final short[][] table16 = reader.get16BitLookupTable();
|
||||||
final int seriesCount = reader.getSeriesCount();
|
if (table16 != null) {
|
||||||
for (int j = 0; j < seriesCount; j++) {
|
indexed.add(String.format("16-bit LUT: %d x %s", table16.length,
|
||||||
reader.setSeries(j);
|
table16[0] == null ? "null" : "" + table16[0].length));
|
||||||
final Hashtable<String, Object> seriesMagedata = reader.getSeriesMetadata();
|
|
||||||
if (!seriesMagedata.isEmpty()) {
|
|
||||||
final Map<String, Object> seriesMetadata = new LinkedHashMap<String, Object>();
|
|
||||||
final String[] keys = MetadataTools.keys(seriesMagedata);
|
|
||||||
for (int i = 0; i < keys.length; i++) {
|
|
||||||
seriesMetadata.put(keys[i], seriesMagedata.get(keys[i]));
|
|
||||||
}
|
|
||||||
metadata.put(String.format("series[%d]", j), seriesMetadata);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
seriesMetadata.put("indexed", indexed);
|
||||||
|
}
|
||||||
|
|
||||||
return metadata;
|
seriesMetadata.put("sizeX", reader.getSizeX());
|
||||||
}
|
seriesMetadata.put("sizeY", reader.getSizeY());
|
||||||
|
final int sizeZ = reader.getSizeZ();
|
||||||
|
seriesMetadata.put("sizeZ", makeDimension(sizeZ, sizeZ, reader.getModuloZ()));
|
||||||
|
seriesMetadata.put("sizeC", makeDimension(reader.getSizeC(), reader.getEffectiveSizeC(), reader.getModuloC()));
|
||||||
|
final int sizeT = reader.getSizeT();
|
||||||
|
seriesMetadata.put("sizeT", makeDimension(sizeT, sizeT, reader.getModuloT()));
|
||||||
|
seriesMetadata.put("tileSize", makeRectangle(reader.getOptimalTileWidth(), reader.getOptimalTileHeight()));
|
||||||
|
seriesMetadata.put("thumbnailSize", makeRectangle(reader.getThumbSizeX(), reader.getThumbSizeY()));
|
||||||
|
seriesMetadata.put("endianness", reader.isLittleEndian() ? "little" : "big");
|
||||||
|
seriesMetadata.put("dimensionOrder",
|
||||||
|
new String[] { reader.getDimensionOrder(), reader.isOrderCertain() ? "certain" : "uncertain" });
|
||||||
|
seriesMetadata.put("pixelType", FormatTools.getPixelTypeString(reader.getPixelType()));
|
||||||
|
seriesMetadata.put("validBitsPerPixel", reader.getBitsPerPixel());
|
||||||
|
seriesMetadata.put("metadataComplete", reader.isMetadataComplete());
|
||||||
|
seriesMetadata.put("thumbnailSeries", reader.isThumbnailSeries());
|
||||||
|
|
||||||
protected static Object makeDimension(final int size, final int effSize, final Modulo modulo) {
|
// plane
|
||||||
final int mLength = modulo.length();
|
{
|
||||||
if (size == effSize && mLength == 1) {
|
final int[] indices;
|
||||||
return size;
|
if (imageCount > 6) {
|
||||||
}
|
int q = imageCount / 2;
|
||||||
final List<Object> ret = new ArrayList<Object>();
|
indices = new int[] { 0, q - 2, q - 1, q, q + 1, q + 2, imageCount - 1 };
|
||||||
ret.add(size);
|
} else if (imageCount > 2) {
|
||||||
if (size != effSize) {
|
indices = new int[] { 0, imageCount / 2, imageCount - 1 };
|
||||||
ret.add(String.format("(effectively %d)", effSize));
|
} else if (imageCount > 1) {
|
||||||
}
|
indices = new int[] { 0, 1 };
|
||||||
if (mLength != 1) {
|
|
||||||
ret.add(String.format("(%d %s x %d %s)", size / mLength, modulo.parentType, mLength, modulo.type));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static Map<String, Object> makeRectangle(final int width, final int height) {
|
|
||||||
final Map<String, Object> ret = new LinkedHashMap<String, Object>();
|
|
||||||
ret.put("width", width);
|
|
||||||
ret.put("height", height);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static String getJsonString(final Map<String, Object> map) {
|
|
||||||
final ObjectMapper mapper = new ObjectMapper();
|
|
||||||
String json = null;
|
|
||||||
try {
|
|
||||||
// json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
|
|
||||||
json = mapper.writeValueAsString(map);
|
|
||||||
} catch (final Throwable e) {
|
|
||||||
// return "null" if conversion error occured
|
|
||||||
json = "null";
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readMetadata(final String path, final Map<String, Object> metadata)
|
|
||||||
throws BioFormatsImageException {
|
|
||||||
if (FilenameUtils.getExtension(path).toLowerCase().equals("zip")) {
|
|
||||||
// ignore if file is zip archive
|
|
||||||
throw new BioFormatsImageException("Zip is not supported");
|
|
||||||
}
|
|
||||||
String format = "";
|
|
||||||
final ImageInfo info = new ImageInfo();
|
|
||||||
final IFormatReader reader = new ImageReader();
|
|
||||||
try {
|
|
||||||
// info.parseArgs(new String[] { path, "-nopix", "-noflat", "-omexml" });
|
|
||||||
info.parseArgs(new String[] { path, "-nopix", "-noflat" });
|
|
||||||
info.setReader(reader);
|
|
||||||
info.mapLocation();
|
|
||||||
info.configureReaderPreInit();
|
|
||||||
|
|
||||||
// initialize reader
|
|
||||||
reader.setId(path);
|
|
||||||
format = reader.getFormat();
|
|
||||||
info.configureReaderPostInit();
|
|
||||||
info.checkWarnings();
|
|
||||||
// info.printOMEXML();
|
|
||||||
// info.readCoreMetadata();
|
|
||||||
metadata.put("images", readImages(reader));
|
|
||||||
info.initPreMinMaxValues();
|
|
||||||
reader.setSeries(0);
|
|
||||||
reader.setResolution(0);
|
|
||||||
// info.printGlobalMetadata();
|
|
||||||
// info.printOriginalMetadata();
|
|
||||||
final Map<String, Object> annotations = readAnnotations(reader);
|
|
||||||
if (!annotations.isEmpty()) {
|
|
||||||
metadata.put("annotations", annotations);
|
|
||||||
}
|
|
||||||
} catch (final Throwable e) {
|
|
||||||
throw new BioFormatsImageException(e);
|
|
||||||
} finally {
|
|
||||||
if (reader != null) {
|
|
||||||
try {
|
|
||||||
reader.close();
|
|
||||||
} catch (final IOException e) {
|
|
||||||
throw new BioFormatsImageException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -- Main method --
|
|
||||||
public static void main(final String[] args) {
|
|
||||||
boolean status = true;
|
|
||||||
String message = "";
|
|
||||||
String format = "";
|
|
||||||
final Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
|
||||||
final Map<String, Object> thumbnail = new LinkedHashMap<String, Object>();
|
|
||||||
if (args.length != 1) {
|
|
||||||
status = false;
|
|
||||||
message = "filename argument required";
|
|
||||||
} else {
|
} else {
|
||||||
final String path = args[0];
|
indices = new int[] { 0 };
|
||||||
try {
|
|
||||||
DebugTools.enableLogging("ERROR");
|
|
||||||
format = readMetadata(path, metadata);
|
|
||||||
BioFormatsImageThumbnail.readThumbnail(path, thumbnail);
|
|
||||||
} catch (BioFormatsImageException e) {
|
|
||||||
status = false;
|
|
||||||
message = e.getMessage();
|
|
||||||
metadata.clear();
|
|
||||||
thumbnail.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
final int[][] zct = new int[indices.length][];
|
||||||
final Map<String, Object> results = new LinkedHashMap<String, Object>();
|
final int[] indices2 = new int[indices.length];
|
||||||
results.put("status", status);
|
for (int i = 0; i < indices.length; i++) {
|
||||||
results.put("message", message);
|
zct[i] = reader.getZCTCoords(indices[i]);
|
||||||
results.put("format", format);
|
indices2[i] = reader.getIndex(zct[i][0], zct[i][1], zct[i][2]);
|
||||||
results.put("thumbnail", thumbnail.isEmpty() ? null : thumbnail);
|
final Map<String, Object> planeMetadata = new LinkedHashMap<String, Object>();
|
||||||
results.put("metadata", metadata.isEmpty() ? null : metadata);
|
planeMetadata.put("Z", zct[i][0]);
|
||||||
System.out.println(getJsonString(results));
|
planeMetadata.put("C", zct[i][1]);
|
||||||
|
planeMetadata.put("T", zct[i][2]);
|
||||||
if (!status) {
|
if (indices[i] != indices2[i]) {
|
||||||
System.exit(1);
|
planeMetadata.put("[mismatch]", indices2[i]);
|
||||||
|
}
|
||||||
|
seriesMetadata.put(String.format("plane[%d]", indices[i]), planeMetadata);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
metadata.put(String.format("series[%d]", j), seriesMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Map<String, Object> readAnnotations(final IFormatReader reader) {
|
||||||
|
final Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
||||||
|
// global metadata
|
||||||
|
final Hashtable<String, Object> globalMetadata = reader.getGlobalMetadata();
|
||||||
|
for (String key : MetadataTools.keys(globalMetadata)) {
|
||||||
|
metadata.put(key, globalMetadata.get(key));
|
||||||
|
}
|
||||||
|
// original metadata
|
||||||
|
final int seriesCount = reader.getSeriesCount();
|
||||||
|
for (int j = 0; j < seriesCount; j++) {
|
||||||
|
reader.setSeries(j);
|
||||||
|
final Hashtable<String, Object> seriesMagedata = reader.getSeriesMetadata();
|
||||||
|
if (!seriesMagedata.isEmpty()) {
|
||||||
|
final Map<String, Object> seriesMetadata = new LinkedHashMap<String, Object>();
|
||||||
|
final String[] keys = MetadataTools.keys(seriesMagedata);
|
||||||
|
for (int i = 0; i < keys.length; i++) {
|
||||||
|
seriesMetadata.put(keys[i], seriesMagedata.get(keys[i]));
|
||||||
|
}
|
||||||
|
metadata.put(String.format("series[%d]", j), seriesMetadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Object makeDimension(final int size, final int effSize, final Modulo modulo) {
|
||||||
|
final int mLength = modulo.length();
|
||||||
|
if (size == effSize && mLength == 1) {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
final List<Object> ret = new ArrayList<Object>();
|
||||||
|
ret.add(size);
|
||||||
|
if (size != effSize) {
|
||||||
|
ret.add(String.format("(effectively %d)", effSize));
|
||||||
|
}
|
||||||
|
if (mLength != 1) {
|
||||||
|
ret.add(String.format("(%d %s x %d %s)", size / mLength, modulo.parentType, mLength, modulo.type));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Map<String, Object> makeRectangle(final int width, final int height) {
|
||||||
|
final Map<String, Object> ret = new LinkedHashMap<String, Object>();
|
||||||
|
ret.put("width", width);
|
||||||
|
ret.put("height", height);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static String getJsonString(final Map<String, Object> map) {
|
||||||
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String json = null;
|
||||||
|
try {
|
||||||
|
// json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
|
||||||
|
json = mapper.writeValueAsString(map);
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
// return "null" if conversion error occured
|
||||||
|
json = "null";
|
||||||
|
}
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String readMetadata(final String path, final Map<String, Object> metadata)
|
||||||
|
throws BioFormatsImageException {
|
||||||
|
if (FilenameUtils.getExtension(path).toLowerCase().equals("zip")) {
|
||||||
|
// ignore if file is zip archive
|
||||||
|
throw new BioFormatsImageException("Zip is not supported");
|
||||||
|
}
|
||||||
|
String format = "";
|
||||||
|
final ImageInfo info = new ImageInfo();
|
||||||
|
final IFormatReader reader = new ImageReader();
|
||||||
|
try {
|
||||||
|
// info.parseArgs(new String[] { path, "-nopix", "-noflat", "-omexml" });
|
||||||
|
info.parseArgs(new String[] { path, "-nopix", "-noflat" });
|
||||||
|
info.setReader(reader);
|
||||||
|
info.mapLocation();
|
||||||
|
info.configureReaderPreInit();
|
||||||
|
|
||||||
|
// initialize reader
|
||||||
|
reader.setId(path);
|
||||||
|
format = reader.getFormat();
|
||||||
|
info.configureReaderPostInit();
|
||||||
|
info.checkWarnings();
|
||||||
|
// info.printOMEXML();
|
||||||
|
// info.readCoreMetadata();
|
||||||
|
metadata.put("images", readImages(reader));
|
||||||
|
info.initPreMinMaxValues();
|
||||||
|
reader.setSeries(0);
|
||||||
|
reader.setResolution(0);
|
||||||
|
// info.printGlobalMetadata();
|
||||||
|
// info.printOriginalMetadata();
|
||||||
|
final Map<String, Object> annotations = readAnnotations(reader);
|
||||||
|
if (!annotations.isEmpty()) {
|
||||||
|
metadata.put("annotations", annotations);
|
||||||
|
}
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
throw new BioFormatsImageException(e);
|
||||||
|
} finally {
|
||||||
|
if (reader != null) {
|
||||||
|
try {
|
||||||
|
reader.close();
|
||||||
|
} catch (final IOException e) {
|
||||||
|
throw new BioFormatsImageException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Main method --
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
boolean status = true;
|
||||||
|
String message = "";
|
||||||
|
String format = "";
|
||||||
|
final Map<String, Object> metadata = new LinkedHashMap<String, Object>();
|
||||||
|
final Map<String, Object> thumbnail = new LinkedHashMap<String, Object>();
|
||||||
|
if (args.length != 1) {
|
||||||
|
status = false;
|
||||||
|
message = "filename argument required";
|
||||||
|
} else {
|
||||||
|
final String path = args[0];
|
||||||
|
try {
|
||||||
|
DebugTools.enableLogging("ERROR");
|
||||||
|
format = readMetadata(path, metadata);
|
||||||
|
BioFormatsImageThumbnail.readThumbnail(path, thumbnail);
|
||||||
|
} catch (BioFormatsImageException e) {
|
||||||
|
status = false;
|
||||||
|
message = e.getMessage();
|
||||||
|
metadata.clear();
|
||||||
|
thumbnail.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Map<String, Object> results = new LinkedHashMap<String, Object>();
|
||||||
|
results.put("status", status);
|
||||||
|
results.put("message", message);
|
||||||
|
results.put("format", format);
|
||||||
|
results.put("thumbnail", thumbnail.isEmpty() ? null : thumbnail);
|
||||||
|
results.put("metadata", metadata.isEmpty() ? null : metadata);
|
||||||
|
System.out.println(getJsonString(results));
|
||||||
|
|
||||||
|
if (!status) {
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user