Skip to content

Commit

Permalink
FeatureCalculation: Restore axis information in created bitmasks Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gab1one committed Aug 14, 2018
1 parent 1198fb3 commit 6ba5651
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.Map;

import net.imagej.ImgPlus;
import net.imagej.axis.CalibratedAxis;
import net.imagej.ops.OpEnvironment;
import net.imagej.ops.special.computer.AbstractUnaryComputerOp;
import net.imglib2.img.Img;
Expand Down Expand Up @@ -84,7 +85,7 @@
/**
* FIXME: Design of FeatureGroups is really weak. However, we can redesign it
* whenever we have more time, without destroying backwards compatibility.
*
*
* @author Christian Dietz, University of Konstanz
*
* @param <L>
Expand Down Expand Up @@ -210,13 +211,14 @@ protected <I> List<DataCell> computeOnFeatureSets(final List<FeatureSet<I, O>> s

protected <L> void appendRegionOptions(final LabelRegion<L> region, final List<DataCell> cells,
final ImgPlusCellFactory imgPlusCellFactory, final Map<L, List<L>> dependencies,
final boolean appendOverlappingLabels, final OpEnvironment ops) {
final boolean appendOverlappingLabels, final OpEnvironment ops, final CalibratedAxis[] axes) {
if (imgPlusCellFactory != null) {
@SuppressWarnings("unchecked")
Img<BitType> bitmask = (Img<BitType>) ops.run(LabelRegionToBitmaskConverter.class, region);
final Img<BitType> bitmask = (Img<BitType>) ops.run(LabelRegionToBitmaskConverter.class, region);
try {
cells.add(imgPlusCellFactory.createCell(new ImgPlus<BitType>(bitmask)));
} catch (IOException exc) {
final ImgPlus<BitType> imgPlus = new ImgPlus<>(bitmask, "bitmask", axes);
cells.add(imgPlusCellFactory.createCell(imgPlus));
} catch (final IOException exc) {
KNIPGateway.log()
.warn("Could not create bitmask for label " + region.toString() + ". Inserted missing cell.");
cells.add(DataType.getMissingCell());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import net.imagej.axis.CalibratedAxis;
import net.imagej.ops.slice.SlicesII;
import net.imagej.ops.special.computer.UnaryComputerOp;
import net.imglib2.Cursor;
Expand All @@ -78,6 +79,7 @@
import org.knime.knip.base.data.labeling.LabelingValue;
import org.knime.knip.base.node.nodesettings.SettingsModelDimSelection;
import org.knime.knip.core.KNIPGateway;
import org.knime.knip.core.data.img.LabelingMetadata;
import org.knime.knip.core.ops.misc.LabelingDependency;
import org.knime.knip.core.ui.imgviewer.events.RulebasedLabelFilter;
import org.knime.knip.features.DataRowUtil;
Expand All @@ -88,6 +90,7 @@
/**
* FIXME: Design of FeatureGroups is really weak. However, we can redesign it
* whenever we have more time, without destroying backwards compatibility.
*
* @author Christian Dietz, University of Konstanz
*
* @param <L>
Expand Down Expand Up @@ -183,8 +186,9 @@ public void compute(final DataRow row, final DataContainer container) {
final RandomAccessibleInterval<LabelingType<L>> labeling = labValue.getLabeling();
// here we have to loop!!!

final LabelingMetadata labelingMetadata = labValue.getLabelingMetadata();
final SlicesII<LabelingType<L>> slicer = new SlicesII<>(labeling,
dimSelection.getSelectedDimIndices(labValue.getLabelingMetadata()), true);
dimSelection.getSelectedDimIndices(labelingMetadata), true);

final Cursor<RandomAccessibleInterval<LabelingType<L>>> slicingCursor = slicer.cursor();

Expand Down Expand Up @@ -222,6 +226,11 @@ public void compute(final DataRow row, final DataContainer container) {
intervalDef = " Pos[" + Arrays.toString(pos) + "]";

}
final CalibratedAxis[] labelAxes = new CalibratedAxis[dimSelection.getNumSelectedDimLabels()];
final int[] selectedIdx = dimSelection.getSelectedDimIndices(labelingMetadata);
for (int i = 0; i < selectedIdx.length; i++) {
labelAxes[i] = labelingMetadata.axis(selectedIdx[i]);
}

final ArrayList<Future<Pair<String, List<DataCell>>>> futures = new ArrayList<>();
for (final LabelRegion<L> region : regions) {
Expand All @@ -231,8 +240,8 @@ public void compute(final DataRow row, final DataContainer container) {
futures.add(KNIPGateway.threads().run(() -> {
final List<DataCell> cells = new ArrayList<>();

appendRegionOptions(region, cells, imgPlusCellFactory, dependencies,
appendOverlappingSegments, ops());
appendRegionOptions(region, cells, imgPlusCellFactory, dependencies,
appendOverlappingSegments, ops(), labelAxes);

cells.addAll(computeOnFeatureSets(featureSets, region));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.concurrent.Future;

import net.imagej.ImgPlus;
import net.imagej.axis.CalibratedAxis;
import net.imagej.ops.slice.SlicesII;
import net.imagej.ops.special.computer.UnaryComputerOp;
import net.imglib2.Cursor;
Expand Down Expand Up @@ -84,6 +85,7 @@
import org.knime.knip.base.data.labeling.LabelingValue;
import org.knime.knip.base.node.nodesettings.SettingsModelDimSelection;
import org.knime.knip.core.KNIPGateway;
import org.knime.knip.core.data.img.LabelingMetadata;
import org.knime.knip.core.ops.misc.LabelingDependency;
import org.knime.knip.core.ui.imgviewer.events.RulebasedLabelFilter;
import org.knime.knip.core.util.MiscViews;
Expand All @@ -95,7 +97,7 @@
/**
* FIXME: Design of FeatureGroups is really weak. However, we can redesign it
* whenever we have more time, without destroying backwards compatibility.
*
*
* @author Christian Dietz, University of Konstanz
*
* @param <L>
Expand Down Expand Up @@ -213,16 +215,17 @@ public void compute(final DataRow row, final DataContainer container) {
final ImgPlus<T> imgPlus = ((ImgPlusValue<T>) imgPlusCell).getImgPlus();
RandomAccessibleInterval<LabelingType<L>> labeling = val.getLabeling();

LabelingMetadata labelingMetadata = val.getLabelingMetadata();
if (!Intervals.equalDimensions(imgPlus, labeling)) {
KNIPGateway.log().warn("The dimensions of Labeling and Image in Row " + row.getKey()
+ " are not compatible. Dimensions of labeling are virtually adjusted to match size.");

labeling = MiscViews.synchronizeDimensionality(labeling, val.getLabelingMetadata(), imgPlus,
labeling = MiscViews.synchronizeDimensionality(labeling, labelingMetadata, imgPlus,
imgPlus);
}

final SlicesII<LabelingType<L>> slicerLab = new SlicesII<>(labeling,
dimSelection.getSelectedDimIndices(val.getLabelingMetadata()), true);
dimSelection.getSelectedDimIndices(labelingMetadata), true);

final SlicesII<T> slicerImg = new SlicesII<>(imgPlus, dimSelection.getSelectedDimIndices(imgPlus),
true);
Expand Down Expand Up @@ -268,6 +271,11 @@ public void compute(final DataRow row, final DataContainer container) {

}

final CalibratedAxis[] labelAxes = new CalibratedAxis[dimSelection.getNumSelectedDimLabels()];
final int[] selectedIdx = dimSelection.getSelectedDimIndices(labelingMetadata);
for (int i = 0; i < selectedIdx.length; i++) {
labelAxes[i] = labelingMetadata.axis(selectedIdx[i]);
}
final ArrayList<Future<Pair<String, List<DataCell>>>> futures = new ArrayList<>();
for (final LabelRegion<L> region : regions) {
if (!labelFilter.getRules().isEmpty() && !labelFilter.isValid(region.getLabel())) {
Expand All @@ -277,11 +285,9 @@ public void compute(final DataRow row, final DataContainer container) {
futures.add(KNIPGateway.threads().run(() -> {
final List<DataCell> cells = new ArrayList<>();

appendRegionOptions(region, cells, imgPlusCellFactory, dependencies,
appendOverlappingSegments, ops());
appendRegionOptions(region, cells, imgPlusCellFactory, dependencies,
appendOverlappingSegments, ops(), labelAxes);

cells.addAll(computeOnFeatureSets(regionSets, region));
cells.addAll(computeOnFeatureSets(iterableSets, Regions.sample(region, sliceImgPlus)));
cells.addAll(computeOnFeatureSets(regionSets, region));
cells.addAll(computeOnFeatureSets(iterableSets, Regions.sample(region, sliceImgPlus)));

Expand Down

0 comments on commit 6ba5651

Please sign in to comment.