Skip to content

Commit 2616bc8

Browse files
committed
ImgCropper: Respect minimum
1 parent f420016 commit 2616bc8

4 files changed

Lines changed: 32 additions & 31 deletions

File tree

org.knime.knip.base/src/org/knime/knip/base/node/nodesettings/SettingsModelSubsetSelection2.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ protected final SettingsModelSubsetSelection2 createClone() {
140140
* @throws KNIPException
141141
*/
142142
@SuppressWarnings("unchecked")
143-
public final Interval[] createSelectedIntervals(final long[] dimensions, final CalibratedAxis[] axes)
143+
public final Interval[] createSelectedIntervals(final long[] min, final long[] dimensions,
144+
final CalibratedAxis[] axes)
144145
throws KNIPException {
145146

146147
List<Long>[] minPosList;
@@ -160,8 +161,8 @@ public final Interval[] createSelectedIntervals(final long[] dimensions, final C
160161
maxPosList[d] = new ArrayList<Long>(dimensions.length);
161162

162163
if (selectionInformation[d]) {
163-
minPosList[d].add(0l);
164-
maxPosList[d].add(dimensions[d] - 1);
164+
minPosList[d].add(min[d]);
165+
maxPosList[d].add(min[d] + dimensions[d] - 1);
165166
numIntervalsPerDim[d] = 1;
166167
} else {
167168
final int[] selection = SubsetSelectionUtils.parseString(m_selection.get(axes[d].type().getLabel()));
@@ -246,12 +247,12 @@ public final Interval[] createSelectedIntervals(final long[] dimensions, final C
246247
* @return the intervals
247248
* @throws KNIPException
248249
*/
249-
public final Interval[] createSelectedIntervals(final long[] dimensions,
250+
public final Interval[] createSelectedIntervals(final long[] minimum, final long[] dimensions,
250251
final CalibratedSpace<CalibratedAxis> labeledAxes)
251-
throws KNIPException {
252+
throws KNIPException {
252253
final CalibratedAxis[] axes = new CalibratedAxis[dimensions.length];
253254
labeledAxes.axes(axes);
254-
return createSelectedIntervals(dimensions, axes);
255+
return createSelectedIntervals(minimum, dimensions, axes);
255256
}
256257

257258
/**
@@ -260,10 +261,11 @@ public final Interval[] createSelectedIntervals(final long[] dimensions,
260261
* @return the intervals
261262
* @throws KNIPException
262263
*/
263-
public Interval[] createSelectedIntervalsPlaneWise(final long[] dimensions, final CalibratedAxis[] axes)
264+
public Interval[] createSelectedIntervalsPlaneWise(final long[] minimum, final long[] dimensions,
265+
final CalibratedAxis[] axes)
264266
throws KNIPException {
265267

266-
final Interval[] selected = createSelectedIntervals(dimensions, axes);
268+
final Interval[] selected = createSelectedIntervals(minimum, dimensions, axes);
267269

268270
if (selected.length == 1) {
269271
boolean same = true;
@@ -645,7 +647,8 @@ protected final void validateSettingsForModel(final NodeSettingsRO settings) thr
645647
*/
646648
@SuppressWarnings("unchecked")
647649
public Pair<TypedAxis, long[]>[] createSelectionConstraints(final long[] dimensions,
648-
final CalibratedAxis[] calibAxes) throws KNIPException {
650+
final CalibratedAxis[] calibAxes)
651+
throws KNIPException {
649652

650653
ArrayList<Pair<TypedAxis, long[]>> ret = new ArrayList<Pair<TypedAxis, long[]>>();
651654

org.knime.knip.base/src/org/knime/knip/base/nodes/proc/AlignerNodeFactory2.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import net.imglib2.Interval;
7777
import net.imglib2.ops.operation.Operations;
7878
import net.imglib2.type.numeric.RealType;
79+
import net.imglib2.util.Intervals;
7980

8081
/**
8182
* AlignerNodeFactory. Uses {@link DialogComponentSubsetSelection2} instead of {@link DialogComponentSubsetSelection};
@@ -248,7 +249,8 @@ protected ImgPlusCell<T> compute(final ImgPlusValue<T> cellValueA, final ImgPlus
248249

249250
final long[] dims = new long[zeroMinFromCell.numDimensions()];
250251
zeroMinFromCell.dimensions(dims);
251-
Interval ivs[] = m_subsetSelect.createSelectedIntervals(dims, zeroMinFromCell);
252+
Interval ivs[] = m_subsetSelect.createSelectedIntervals(Intervals.minAsLongArray(zeroMinFromCell), dims,
253+
zeroMinFromCell);
252254
if ((ivs == null) || (ivs.length == 0)) {
253255
ivs = new Interval[1];
254256
final long mins[] = new long[zeroMinFromCell.numDimensions()];
@@ -258,16 +260,13 @@ protected ImgPlusCell<T> compute(final ImgPlusValue<T> cellValueA, final ImgPlus
258260
ivs[0] = new FinalInterval(mins, maxs);
259261
}
260262

261-
return m_imgCellFactory
262-
.createCell(MinimaUtils
263-
.getTranslatedImgPlus(fromCell, new ImgPlus<>(
264-
Operations.compute(
265-
new Aligner<T, V>(selectedDims1, selectedDim2, ivs[0],
266-
sizemode, alignmode, m_stepSize.getIntValue(),
267-
m_minPixOverlap.getIntValue()),
268-
zeroMinFromCell,
269-
MinimaUtils.getZeroMinImgPlus(cellValueB.getImgPlus())),
270-
cellValueA.getMetadata())));
263+
return m_imgCellFactory.createCell(MinimaUtils
264+
.getTranslatedImgPlus(fromCell, new ImgPlus<>(
265+
Operations.compute(new Aligner<T, V>(selectedDims1, selectedDim2, ivs[0], sizemode,
266+
alignmode, m_stepSize.getIntValue(), m_minPixOverlap.getIntValue()),
267+
zeroMinFromCell,
268+
MinimaUtils.getZeroMinImgPlus(cellValueB.getImgPlus())),
269+
cellValueA.getMetadata())));
271270
}
272271

273272
/**

org.knime.knip.base/src/org/knime/knip/base/nodes/proc/ImgCropperNodeFactory2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ protected ImgPlusCell<T> compute(final ImgPlusValue<T> cellValue) throws Excepti
156156
final ImgPlus<T> img = cellValue.getImgPlus();
157157

158158
final Interval[] intervals =
159-
m_smSubsetSel.createSelectedIntervals(Intervals.dimensionsAsLongArray(img), img);
159+
m_smSubsetSel.createSelectedIntervals(cellValue.getMinimum(), Intervals.dimensionsAsLongArray(img), img);
160160

161161
@SuppressWarnings("unchecked")
162162
final IntervalView<T>[] iis = new IntervalView[intervals.length];
163163

164164
for (int i = 0; i < intervals.length; i++) {
165-
iis[i] = Views.interval(img, intervals[i]);
165+
iis[i] = Views.interval(img.getImg(), intervals[i]);
166166
}
167167

168168
if ((iis.length == 1) && m_smAdjustDimensionality.getBooleanValue()) {

org.knime.knip.base/src/org/knime/knip/base/nodes/seg/LabelingOrthoCropperNodeFactory2.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import net.imglib2.roi.labeling.ImgLabeling;
7979
import net.imglib2.roi.labeling.LabelingType;
8080
import net.imglib2.type.numeric.IntegerType;
81+
import net.imglib2.util.Intervals;
8182
import net.imglib2.util.Util;
8283
import net.imglib2.view.Views;
8384

@@ -163,7 +164,8 @@ protected LabelingCell<L> compute(final LabelingValue<L> cellValue) throws Excep
163164
lab.dimensions(dimensions);
164165

165166
final Interval[] intervals =
166-
m_subsetSel.createSelectedIntervals(dimensions, cellValue.getLabelingMetadata());
167+
m_subsetSel.createSelectedIntervals(Intervals.minAsLongArray(lab), dimensions,
168+
cellValue.getLabelingMetadata());
167169

168170
@SuppressWarnings("unchecked")
169171
final RandomAccessibleInterval<LabelingType<L>>[] subLab =
@@ -201,14 +203,11 @@ protected LabelingCell<L> compute(final LabelingValue<L> cellValue) throws Excep
201203

202204
}
203205

204-
return m_labCellFactory
205-
.createCell(res,
206-
new DefaultLabelingMetadata(
207-
new DefaultCalibratedSpace(
208-
validAxes.toArray(new CalibratedAxis[validAxes.size()])),
209-
new DefaultNamed(cellValue.getLabelingMetadata().getName()),
210-
new DefaultSourced(cellValue.getLabelingMetadata().getSource()),
211-
cellValue.getLabelingMetadata().getLabelingColorTable()));
206+
return m_labCellFactory.createCell(res, new DefaultLabelingMetadata(
207+
new DefaultCalibratedSpace(validAxes.toArray(new CalibratedAxis[validAxes.size()])),
208+
new DefaultNamed(cellValue.getLabelingMetadata().getName()),
209+
new DefaultSourced(cellValue.getLabelingMetadata().getSource()),
210+
cellValue.getLabelingMetadata().getLabelingColorTable()));
212211
}
213212
}
214213

0 commit comments

Comments
 (0)