Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added axes serialization to json for export #126

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/org/ilastik/ilastik4ij/hdf5/Hdf5.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import static org.ilastik.ilastik4ij.util.ImgUtils.DEFAULT_AXES;
import static org.ilastik.ilastik4ij.util.ImgUtils.argbToMultiChannel;
import static org.ilastik.ilastik4ij.util.ImgUtils.axesOf;
import static org.ilastik.ilastik4ij.util.ImgUtils.axesToJSON;
import static org.ilastik.ilastik4ij.util.ImgUtils.inputBlockDims;
import static org.ilastik.ilastik4ij.util.ImgUtils.outputDims;
import static org.ilastik.ilastik4ij.util.ImgUtils.reversed;
Expand Down Expand Up @@ -286,6 +287,9 @@ public static <T extends NativeType<T>> void writeDataset(
reversed(chunkDims),
compressionLevel)) {

// Add axes tags
writer.string().setAttr(dataset.getDataSetPath(), "axistags", axesToJSON(axes));

callback.accept(0L);

while (gridCursor.hasNext()) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/ilastik/ilastik4ij/util/ImgUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,41 @@ public static List<AxisType> parseAxes(String json) {
return axes;
}

public static String axesToJSON(List<AxisType> axes)
{
JSONArray jsonAxesArray = new JSONArray();
List<AxisType> axes_for_serialization = new ArrayList<>(axes);
Collections.reverse(axes_for_serialization);
for (AxisType axis : axes_for_serialization)
{
JSONObject jsonAxis = new JSONObject();
String label = axis.getLabel().toLowerCase();
int vigraType;
String vigraKey;
if (axis.isSpatial()){
vigraType = 2;
vigraKey = label;
} else if (label.equals("time")) {
k-dominik marked this conversation as resolved.
Show resolved Hide resolved
vigraType = 8;
vigraKey = "t";
} else if (label.equals("channel")) {
vigraType = 1;
vigraKey = "c";
} else {
throw new IllegalArgumentException(
String.format("Unknown axis type found with label %s.", label));
}
jsonAxis.put("key", vigraKey);
jsonAxis.put("typeFlags", vigraType);
jsonAxesArray.put(jsonAxis);
}

JSONObject root = new JSONObject();
root.put("axes", jsonAxesArray);

return root.toString();
}

/**
* Treat alpha, red, green, and blue values in {@link ARGBType} image
* as a separate, last channel dimension.
Expand Down