Skip to content

Commit

Permalink
ImgCropper: Respect minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
dietzc committed Apr 8, 2017
1 parent f420016 commit 2616bc8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ protected final SettingsModelSubsetSelection2 createClone() {
* @throws KNIPException
*/
@SuppressWarnings("unchecked")
public final Interval[] createSelectedIntervals(final long[] dimensions, final CalibratedAxis[] axes)
public final Interval[] createSelectedIntervals(final long[] min, final long[] dimensions,
final CalibratedAxis[] axes)
throws KNIPException {

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

if (selectionInformation[d]) {
minPosList[d].add(0l);
maxPosList[d].add(dimensions[d] - 1);
minPosList[d].add(min[d]);
maxPosList[d].add(min[d] + dimensions[d] - 1);
numIntervalsPerDim[d] = 1;
} else {
final int[] selection = SubsetSelectionUtils.parseString(m_selection.get(axes[d].type().getLabel()));
Expand Down Expand Up @@ -246,12 +247,12 @@ public final Interval[] createSelectedIntervals(final long[] dimensions, final C
* @return the intervals
* @throws KNIPException
*/
public final Interval[] createSelectedIntervals(final long[] dimensions,
public final Interval[] createSelectedIntervals(final long[] minimum, final long[] dimensions,
final CalibratedSpace<CalibratedAxis> labeledAxes)
throws KNIPException {
throws KNIPException {
final CalibratedAxis[] axes = new CalibratedAxis[dimensions.length];
labeledAxes.axes(axes);
return createSelectedIntervals(dimensions, axes);
return createSelectedIntervals(minimum, dimensions, axes);
}

/**
Expand All @@ -260,10 +261,11 @@ public final Interval[] createSelectedIntervals(final long[] dimensions,
* @return the intervals
* @throws KNIPException
*/
public Interval[] createSelectedIntervalsPlaneWise(final long[] dimensions, final CalibratedAxis[] axes)
public Interval[] createSelectedIntervalsPlaneWise(final long[] minimum, final long[] dimensions,
final CalibratedAxis[] axes)
throws KNIPException {

final Interval[] selected = createSelectedIntervals(dimensions, axes);
final Interval[] selected = createSelectedIntervals(minimum, dimensions, axes);

if (selected.length == 1) {
boolean same = true;
Expand Down Expand Up @@ -645,7 +647,8 @@ protected final void validateSettingsForModel(final NodeSettingsRO settings) thr
*/
@SuppressWarnings("unchecked")
public Pair<TypedAxis, long[]>[] createSelectionConstraints(final long[] dimensions,
final CalibratedAxis[] calibAxes) throws KNIPException {
final CalibratedAxis[] calibAxes)
throws KNIPException {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import net.imglib2.Interval;
import net.imglib2.ops.operation.Operations;
import net.imglib2.type.numeric.RealType;
import net.imglib2.util.Intervals;

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

final long[] dims = new long[zeroMinFromCell.numDimensions()];
zeroMinFromCell.dimensions(dims);
Interval ivs[] = m_subsetSelect.createSelectedIntervals(dims, zeroMinFromCell);
Interval ivs[] = m_subsetSelect.createSelectedIntervals(Intervals.minAsLongArray(zeroMinFromCell), dims,
zeroMinFromCell);
if ((ivs == null) || (ivs.length == 0)) {
ivs = new Interval[1];
final long mins[] = new long[zeroMinFromCell.numDimensions()];
Expand All @@ -258,16 +260,13 @@ protected ImgPlusCell<T> compute(final ImgPlusValue<T> cellValueA, final ImgPlus
ivs[0] = new FinalInterval(mins, maxs);
}

return m_imgCellFactory
.createCell(MinimaUtils
.getTranslatedImgPlus(fromCell, new ImgPlus<>(
Operations.compute(
new Aligner<T, V>(selectedDims1, selectedDim2, ivs[0],
sizemode, alignmode, m_stepSize.getIntValue(),
m_minPixOverlap.getIntValue()),
zeroMinFromCell,
MinimaUtils.getZeroMinImgPlus(cellValueB.getImgPlus())),
cellValueA.getMetadata())));
return m_imgCellFactory.createCell(MinimaUtils
.getTranslatedImgPlus(fromCell, new ImgPlus<>(
Operations.compute(new Aligner<T, V>(selectedDims1, selectedDim2, ivs[0], sizemode,
alignmode, m_stepSize.getIntValue(), m_minPixOverlap.getIntValue()),
zeroMinFromCell,
MinimaUtils.getZeroMinImgPlus(cellValueB.getImgPlus())),
cellValueA.getMetadata())));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ protected ImgPlusCell<T> compute(final ImgPlusValue<T> cellValue) throws Excepti
final ImgPlus<T> img = cellValue.getImgPlus();

final Interval[] intervals =
m_smSubsetSel.createSelectedIntervals(Intervals.dimensionsAsLongArray(img), img);
m_smSubsetSel.createSelectedIntervals(cellValue.getMinimum(), Intervals.dimensionsAsLongArray(img), img);

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

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

if ((iis.length == 1) && m_smAdjustDimensionality.getBooleanValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import net.imglib2.roi.labeling.ImgLabeling;
import net.imglib2.roi.labeling.LabelingType;
import net.imglib2.type.numeric.IntegerType;
import net.imglib2.util.Intervals;
import net.imglib2.util.Util;
import net.imglib2.view.Views;

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

final Interval[] intervals =
m_subsetSel.createSelectedIntervals(dimensions, cellValue.getLabelingMetadata());
m_subsetSel.createSelectedIntervals(Intervals.minAsLongArray(lab), dimensions,
cellValue.getLabelingMetadata());

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

}

return m_labCellFactory
.createCell(res,
new DefaultLabelingMetadata(
new DefaultCalibratedSpace(
validAxes.toArray(new CalibratedAxis[validAxes.size()])),
new DefaultNamed(cellValue.getLabelingMetadata().getName()),
new DefaultSourced(cellValue.getLabelingMetadata().getSource()),
cellValue.getLabelingMetadata().getLabelingColorTable()));
return m_labCellFactory.createCell(res, new DefaultLabelingMetadata(
new DefaultCalibratedSpace(validAxes.toArray(new CalibratedAxis[validAxes.size()])),
new DefaultNamed(cellValue.getLabelingMetadata().getName()),
new DefaultSourced(cellValue.getLabelingMetadata().getSource()),
cellValue.getLabelingMetadata().getLabelingColorTable()));
}
}

Expand Down

0 comments on commit 2616bc8

Please sign in to comment.