Skip to content

Commit

Permalink
Bugfix for modules that expand objects from a tight image
Browse files Browse the repository at this point in the history
Prior to fix, output objects near image edge would become shifted.
  • Loading branch information
sjcross committed Sep 2, 2024
1 parent ef6b6dc commit e7e70f9
Show file tree
Hide file tree
Showing 49 changed files with 80 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public Status process(Workspace workspace) {
if (showOutput) {
inputObjects.showMeasurements(this, modules);
if (!objectOutputMode.equals(OutputModes.DO_NOT_STORE)) {
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ public Image convertToImageIDColours() {

ImagePlus dispIpl = dispImage.getImagePlus();
dispIpl.setLut(LUTs.Random(true, false));
dispIpl.setDisplayRange(0, 255);
dispIpl.setPosition(1, 1, 1);
dispIpl.updateChannelAndDraw();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,19 +765,16 @@ public Image getAsTightImage(String imageName, @Nullable int[][] borderWidths) {
return getAsImage(imageName, 0, 1);

double[][] extents = getExtents(true, false);
int xOffs = Math.max(0, (int) Math.round(extents[0][0]) - borderWidths[0][0]);
int yOffs = Math.max(0, (int) Math.round(extents[1][0]) - borderWidths[1][0]);
int zOffs = Math.max(0, (int) Math.round(extents[2][0]) - borderWidths[2][0]);

int width = Math.min(spatCal.getWidth(),
(int) Math.round(extents[0][1]) - (int) Math.round(extents[0][0]) + borderWidths[0][0]
+ borderWidths[0][1] + 1);
int height = Math.min(spatCal.getHeight(),
(int) Math.round(extents[1][1]) - (int) Math.round(extents[1][0]) + borderWidths[1][0]
+ borderWidths[1][1] + 1);
int nSlices = Math.min(spatCal.getNSlices(),
(int) Math.round(extents[2][1]) - (int) Math.round(extents[2][0]) + borderWidths[2][0]
+ borderWidths[2][1] + 1);
int xOffs = (int) Math.round(extents[0][0]) - borderWidths[0][0];
int yOffs = (int) Math.round(extents[1][0]) - borderWidths[1][0];
int zOffs = (int) Math.round(extents[2][0]) - borderWidths[2][0];

int width = (int) Math.round(extents[0][1]) - (int) Math.round(extents[0][0]) + borderWidths[0][0]
+ borderWidths[0][1] + 1;
int height = (int) Math.round(extents[1][1]) - (int) Math.round(extents[1][0]) + borderWidths[1][0]
+ borderWidths[1][1] + 1;
int nSlices = (int) Math.round(extents[2][1]) - (int) Math.round(extents[2][0]) + borderWidths[2][0]
+ borderWidths[2][1] + 1;

ImagePlus ipl = IJ.createImage(imageName, width, height, nSlices, 8);
spatCal.setImageCalibration(ipl);
Expand All @@ -787,7 +784,7 @@ public Image getAsTightImage(String imageName, @Nullable int[][] borderWidths) {
ipl.setPosition(point.z - zOffs + 1);
ipl.getProcessor().putPixel(point.x - xOffs, point.y - yOffs, 255);
}

return ImageFactory.createImage("Tight", ipl);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public Status process(Workspace workspace) {
if (assignTracks)
TrackObjects.showObjects(outputObjects, trackObjectsName);
else
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ public Status process(Workspace workspace) {
loadObjects(outputObjects, inputFile, workspace, parentObjects);

if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Status process(Workspace workspace) {
if (createParents)
TrackObjects.showObjects(objects, parentObjectsName);
else
objects.convertToImageIDColours().show();
objects.convertToImageIDColours().show(false);

workspace.addObjects(objects);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public Status process(Workspace workspace) {
workspace.addObjects(outputObjects);

if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Status process(Workspace workspace) {
}
// Showing objects
if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public Status process(Workspace workspace) {

// Showing objects
if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput) {
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);
if (moveObjects && outputObjects != null)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public Status process(Workspace workspace) {
if (showOutput)
inputObjects.showMeasurements(this, modules);
if (showOutput & !objectOutputMode.equals(ObjectOutputModes.DO_NOT_STORE)) {
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);
}

return Status.PASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// TODO: Distance limits

package io.github.mianalysis.mia.module.objects.process;

import org.scijava.Priority;
import org.scijava.plugin.Plugin;

import com.drew.lang.annotations.Nullable;

import io.github.mianalysis.mia.MIA;
import io.github.mianalysis.mia.module.Categories;
import io.github.mianalysis.mia.module.Category;
import io.github.mianalysis.mia.module.Module;
Expand Down Expand Up @@ -368,16 +367,20 @@ public Status process(Workspace workspace) {
maxDist = Double.MAX_VALUE;

// Calculating border widths for image cropping
int[][] borderWidths = null;
int[][] borderWidths = new int[][] { { 0, 0 }, { 0, 0 }, { 0, 0 } };
if (applyMaxDist) {
int maxDistXY = (int) Math.ceil(maxDist);
int maxDistZ = (int) Math.ceil(maxDist * inputObjects.getDppXY() / inputObjects.getDppZ());
borderWidths = new int[][] { { maxDistXY, maxDistXY }, { maxDistXY, maxDistXY },
{ maxDistZ, maxDistZ } };
if (inputObjects.getNSlices() == 1) {

// Only add borders if using bands outside the object
if (!bandMode.equals(BandModes.INSIDE_OBJECTS))
borderWidths = new int[][] { { maxDistXY, maxDistXY }, { maxDistXY, maxDistXY },
{ maxDistZ, maxDistZ } };

if (inputObjects.getNSlices() == 1)
borderWidths[2][0] = 0;
borderWidths[2][1] = 0;
}
borderWidths[2][1] = 0;

}

// Creating output bands objects
Expand Down Expand Up @@ -445,7 +448,7 @@ public Status process(Workspace workspace) {

// Showing objects
if (showOutput)
bandObjects.convertToImageIDColours().show();
bandObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,14 +685,14 @@ protected Status process(Workspace workspace) {
switch (inputMode) {
case InputModes.IMAGE:
edgeObjects.showMeasurements(this, modules);
skeletonObjects.convertToImageIDColours().show();
skeletonObjects.convertToImageIDColours().show(false);
break;

case InputModes.OBJECTS:
inputObjects.showMeasurements(this, modules);
if (addToWorkspace) {
edgeObjects.showMeasurements(this, modules);
skeletonObjects.convertToImageIDColours().show();
skeletonObjects.convertToImageIDColours().show(false);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public Status process(Workspace workspace) {
}

if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ public Status process(Workspace workspace) {

if (showOutput) {
if (updateInputObjects)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);
else
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);
}

// If selected, adding new Objs to the Workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected Status process(Workspace workspace) {
}

if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected Status process(Workspace workspace) {
}

if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public Status process(Workspace workspace) {
if (showOutput) {
inputObjects.showMeasurements(this, modules);
if (!objectOutputMode.equals(OutputModes.DO_NOT_STORE))
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);
}

return Status.PASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public Status process(Workspace workspace) {

// Showing objects
if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected Status process(Workspace workspace) {

// Showing objects
if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ public Status process(Workspace workspace) {

if (outputObjects == null) {
if (showOutput)
inputObjects.convertToImageIDColours().show();
inputObjects.convertToImageIDColours().show(false);
} else {
workspace.addObjects(outputObjects);
if (showOutput)
outputObjects.convertToImageIDColours().show();
outputObjects.convertToImageIDColours().show(false);
}

return Status.PASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected Status process(Workspace workspace) {
workspace.addObjects(outputObjects);

if (showOutput)
outputObjects.convertToImageRandomColours().show();
outputObjects.convertToImageIDColours().show(false);

return Status.PASS;

Expand Down
Loading

0 comments on commit e7e70f9

Please sign in to comment.