Skip to content

Commit

Permalink
Calibrate detailed skeleton branch output. (#257)
Browse files Browse the repository at this point in the history
* Calibrate detailed skeleton branch output.

Fixes #256

* Remove check that has no effect
  • Loading branch information
mdoube committed Apr 5, 2024
1 parent 327c223 commit 763c3d3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import ij.ImagePlus;
import ij.ImageStack;
import ij.gui.Roi;
import ij.measure.Calibration;

import io.scif.FormatException;
import io.scif.services.FormatService;
Expand Down Expand Up @@ -302,13 +303,14 @@ private void showAdditionalResults(final SkeletonResult results) {
final DefaultGenericTable table = new DefaultGenericTable();
final List<PrimitiveColumn<?, ?>> columns = Arrays.asList(new IntColumn(
"# Skeleton"), new IntColumn("# Branch"), new DoubleColumn(
"Branch length"), new IntColumn("V1 x"), new IntColumn("V1 y"),
new IntColumn("V1 z"), new IntColumn("V2 x"), new IntColumn("V2 y"),
new IntColumn("V2 z"), new DoubleColumn("Euclidean distance"),
"Branch length"), new DoubleColumn("V1 x"), new DoubleColumn("V1 y"),
new DoubleColumn("V1 z"), new DoubleColumn("V2 x"), new DoubleColumn("V2 y"),
new DoubleColumn("V2 z"), new DoubleColumn("Euclidean distance"),
new DoubleColumn("running average length"), new DoubleColumn(
"average intensity (inner 3rd)"), new DoubleColumn(
"average intensity"));
final Graph[] graphs = results.getGraph();
final Calibration cal = inputImage.getCalibration();
for (int i = 0; i < graphs.length; i++) {
final ArrayList<Edge> edges = graphs[i].getEdges();
// Sort into descending order by length
Expand All @@ -319,25 +321,26 @@ private void showAdditionalResults(final SkeletonResult results) {
((IntColumn) columns.get(1)).add((j + 1));
((DoubleColumn) columns.get(2)).add((edge.getLength()));
final Point point = edge.getV1().getPoints().get(0);
((IntColumn) columns.get(3)).add((point.x));
((IntColumn) columns.get(4)).add((point.y));
((IntColumn) columns.get(5)).add((point.z));
((DoubleColumn) columns.get(3)).add((point.x) * cal.pixelWidth);
((DoubleColumn) columns.get(4)).add((point.y) * cal.pixelHeight);
((DoubleColumn) columns.get(5)).add((point.z) * cal.pixelDepth);
final Point point2 = edge.getV2().getPoints().get(0);
((IntColumn) columns.get(6)).add((point2.x));
((IntColumn) columns.get(7)).add((point2.y));
((IntColumn) columns.get(8)).add((point2.z));
final double distance = MathArrays.distance(new double[] { point.x,
point.y, point.z }, new double[] { point2.x, point2.y, point2.z });
((DoubleColumn) columns.get(6)).add((point2.x) * cal.pixelWidth);
((DoubleColumn) columns.get(7)).add((point2.y) * cal.pixelHeight);
((DoubleColumn) columns.get(8)).add((point2.z) * cal.pixelDepth);
final double distance = MathArrays.distance(
new double[] { point.x * cal.pixelWidth,
point.y * cal.pixelHeight, point.z * cal.pixelDepth },
new double[] { point2.x * cal.pixelWidth,
point2.y * cal.pixelHeight, point2.z * cal.pixelDepth });
((DoubleColumn) columns.get(9)).add((distance));
((DoubleColumn) columns.get(10)).add((edge.getLength_ra()));
((DoubleColumn) columns.get(11)).add((edge.getColor3rd()));
((DoubleColumn) columns.get(12)).add((edge.getColor()));
}
}
table.addAll(columns);
if (!table.isEmpty()) {
verboseTable = table;
}
verboseTable = table;
}

private void showResults(final SkeletonResult results) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import ij.IJ;
import ij.ImagePlus;
import ij.gui.NewImage;
import ij.measure.Calibration;

import java.io.File;
import java.util.Collection;
Expand Down Expand Up @@ -70,13 +71,18 @@ public void testAdditionalResultsTable() throws Exception {
FILL_BLACK);
line.getStack().getProcessor(1).set(1, 1, (byte) 0xFF);
line.getStack().getProcessor(1).set(2, 2, (byte) 0xFF);
final String length = String.valueOf(Math.sqrt(2.0));
final String length = String.valueOf(Math.sqrt(2.0) / 2);
Calibration cal = line.getCalibration();
cal.pixelWidth = 0.5;
cal.pixelHeight = 0.5;
cal.pixelDepth = 0.5;
line.setCalibration(cal);
final String[] expectedHeaders = { "# Skeleton", "# Branch",
"Branch length", "V1 x", "V1 y", "V1 z", "V2 x", "V2 y", "V2 z",
"Euclidean distance", "running average length",
"average intensity (inner 3rd)", "average intensity" };
final String[] expectedValues = { "1", "1", length, "1", "1", "0", "2", "2",
"0", length, length, "255.0", "255.0" };
final String[] expectedValues = { "1", "1", length, "0.5", "0.5", "0.0", "1.0", "1.0",
"0.0", length, length, "255.0", "255.0" };

// EXECUTE
final CommandModule module = command().run(
Expand All @@ -94,7 +100,7 @@ public void testAdditionalResultsTable() throws Exception {
assertEquals("Column has incorrect header", expectedHeaders[i], column
.getHeader());
assertEquals("Column has wrong number of rows", 1, column.size());
assertEquals("Column has an incorrect value", expectedValues[i], String
assertEquals("Column "+i+" has an incorrect value", expectedValues[i], String
.valueOf(column.get(0)));
}
}
Expand Down

0 comments on commit 763c3d3

Please sign in to comment.