Skip to content

Commit b32f09b

Browse files
committed
Moved OME unit extractors to relevant classes
1 parent 48422f2 commit b32f09b

File tree

7 files changed

+190
-134
lines changed

7 files changed

+190
-134
lines changed

mia-algorithms/src/main/java/io/github/mianalysis/mia/process/imagej/ImageTiler.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ public interface TileAxes {
1919

2020
public static ImagePlus tile(ImagePlus inputIpl, int xNumTiles, int yNumTiles, int xOverlapPx, int yOverlapPx,
2121
String tileAxis) {
22+
inputIpl = inputIpl.duplicate();
2223
String title = "Tiled_" + inputIpl.getTitle();
2324

24-
int coreTileWidth = (int) Math.round(Math.ceil((double) (inputIpl.getWidth()-xOverlapPx) / (double) xNumTiles));
25+
int coreTileWidth = (int) Math
26+
.round(Math.round((double) (inputIpl.getWidth() - xOverlapPx) / (double) xNumTiles));
2527
int tileWidth = coreTileWidth + xOverlapPx;
26-
int coreTileHeight = (int) Math.round(Math.ceil((double) (inputIpl.getHeight()-yOverlapPx) / (double) yNumTiles));
28+
int coreTileHeight = (int) Math
29+
.round(Math.round((double) (inputIpl.getHeight() - yOverlapPx) / (double) yNumTiles));
2730
int tileHeight = coreTileHeight + yOverlapPx;
2831

2932
int nChannels = inputIpl.getNChannels();
@@ -89,7 +92,8 @@ public static ImagePlus tile(ImagePlus inputIpl, int xNumTiles, int yNumTiles, i
8992

9093
public static ImagePlus stitch(ImagePlus inputIpl, int xNumTiles, int yNumTiles, int xOverlapPx, int yOverlapPx,
9194
int outputWidth, int outputHeight,
92-
String tileAxis) {
95+
String tileAxis) {
96+
inputIpl = inputIpl.duplicate();
9397
String title = "Stitched_" + inputIpl.getTitle();
9498

9599
int tileWidth = inputIpl.getWidth();
@@ -123,8 +127,8 @@ public static ImagePlus stitch(ImagePlus inputIpl, int xNumTiles, int yNumTiles,
123127
ImagePlus outputIpl = IJ.createHyperStack(title, outputWidth, outputHeight, nChannels, nSlices, nFrames,
124128
32);
125129

126-
// Converting to 32 bit for this operation to get better results
127-
IJ.run(inputIpl,"32-bit",null);
130+
// Converting to 32 bit for this operation to get better results
131+
IJ.run(inputIpl, "32-bit", null);
128132

129133
ImageStack inputIst = inputIpl.getStack();
130134
ImageStack outputIst = outputIpl.getStack();
@@ -157,22 +161,22 @@ public static ImagePlus stitch(ImagePlus inputIpl, int xNumTiles, int yNumTiles,
157161
float multiplier = 1;
158162

159163
if (xx < xOverlapPx && x != 0)
160-
multiplier *= (1 - (xOverlapPx - xx) / (float) xOverlapPx);
161-
164+
multiplier *= (1 - (xOverlapPx - xx) / (float) xOverlapPx);
165+
162166
if (xx >= coreTileWidth && x != xNumTiles - 1)
163-
multiplier *= (tileWidth - xx) / (float) xOverlapPx;
167+
multiplier *= (tileWidth - xx) / (float) xOverlapPx;
164168

165169
if (yy < yOverlapPx && y != 0)
166170
multiplier *= (1 - (yOverlapPx - yy) / (float) yOverlapPx);
167-
168171

169172
if (yy >= coreTileHeight && y != yNumTiles - 1)
170173
multiplier *= (tileHeight - yy) / (float) yOverlapPx;
171-
172-
outputIpr.setf(xx + x0, yy + y0, outputIpr.getf(xx+x0,yy+y0) + inputIpr.getf(xx, yy) * multiplier);
173-
174+
175+
outputIpr.setf(xx + x0, yy + y0,
176+
outputIpr.getf(xx + x0, yy + y0) + inputIpr.getf(xx, yy) * multiplier);
177+
174178
}
175-
}
179+
}
176180
}
177181
}
178182
}
@@ -182,13 +186,14 @@ public static ImagePlus stitch(ImagePlus inputIpl, int xNumTiles, int yNumTiles,
182186

183187
switch (bitDepth) {
184188
case 8:
185-
inputIpl.setDisplayRange(0,255);
189+
outputIpl.setDisplayRange(0, 255);
190+
IJ.run(outputIpl, "8-bit", null);
186191
break;
187192
case 16:
188-
inputIpl.setDisplayRange(0,65535);
193+
outputIpl.setDisplayRange(0, 65535);
194+
IJ.run(outputIpl, "16-bit", null);
189195
break;
190196
}
191-
IJ.run(inputIpl,"8-bit",null);
192197

193198
return outputIpl;
194199

mia-core/src/main/java/io/github/mianalysis/mia/object/units/SpatialUnit.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,55 @@ public static Unit<Length> getOMEUnit() {
2727
return selectedUnit;
2828
}
2929

30+
public static Unit<Length> getOMEUnit(String unit) {
31+
switch (unit) {
32+
default:
33+
return null;
34+
35+
case "um":
36+
case "μm":
37+
case "micron":
38+
case "microns":
39+
return UNITS.MICROMETER;
40+
41+
case "mm":
42+
case "millimeter":
43+
case "millimeters":
44+
case "millimetre":
45+
case "millimetres":
46+
return UNITS.MILLIMETER;
47+
48+
case "cm":
49+
case "centimeter":
50+
case "centimeters":
51+
case "centimetre":
52+
case "centimetres":
53+
return UNITS.CENTIMETER;
54+
55+
case "nm":
56+
case "nanometer":
57+
case "nanometers":
58+
case "nanometre":
59+
case "nanometres":
60+
return UNITS.NANOMETER;
61+
62+
case "A":
63+
case "Å":
64+
case "ang":
65+
case "angstrom":
66+
case "angstroms":
67+
return UNITS.ANGSTROM;
68+
69+
case "m":
70+
case "meter":
71+
case "meters":
72+
case "metre":
73+
case "metres":
74+
return UNITS.METER;
75+
76+
}
77+
}
78+
3079
public static void setUnit(String units) {
3180
switch (units) {
3281
case AvailableUnits.METRE:

mia-core/src/main/java/io/github/mianalysis/mia/object/units/TemporalUnit.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,48 @@ public static Unit<Time> getOMEUnit() {
2727
return selectedUnit;
2828
}
2929

30+
public static Unit<Time> getOMEUnit(String unit) {
31+
switch (unit) {
32+
default:
33+
return null;
34+
35+
case "ns":
36+
case "nanosecond":
37+
case "nanoseconds":
38+
return UNITS.NANOSECOND;
39+
40+
case "ms":
41+
case "millisecond":
42+
case "milliseconds":
43+
return UNITS.MILLISECOND;
44+
45+
case "m":
46+
case "min":
47+
case "mins":
48+
case "minute":
49+
case "minutes":
50+
return UNITS.MINUTE;
51+
52+
case "h":
53+
case "hour":
54+
case "hours":
55+
return UNITS.HOUR;
56+
57+
case "d":
58+
case "day":
59+
case "days":
60+
return UNITS.DAY;
61+
62+
case "s":
63+
case "sec":
64+
case "secs":
65+
case "second":
66+
case "seconds":
67+
return UNITS.SECOND;
68+
69+
}
70+
}
71+
3072
public static void setUnit(String units) {
3173
switch (units) {
3274
case AvailableUnits.NANOSECOND:

mia-modules/src/main/java/io/github/mianalysis/mia/module/inputoutput/ImageLoader.java

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -864,30 +864,9 @@ void parseImageJSpatialCalibration(ImagePlus ipl, String path) {
864864

865865
// Checking if spatial units match those selected in InputControl
866866
String currUnit = cal.getUnit().toLowerCase();
867-
Unit<Length> currUnitOME = null;
867+
Unit<Length> currUnitOME = SpatialUnit.getOMEUnit(currUnit);
868868
Unit<Length> targetUnitOME = SpatialUnit.getOMEUnit();
869869

870-
if (currUnit.matches("um") || currUnit.matches("μm") || currUnit.contains("micron")
871-
|| currUnit.contains("micrometer") || currUnit.contains("micrometre")) {
872-
currUnitOME = UNITS.MICROMETER;
873-
874-
} else if (currUnit.matches("mm") || currUnit.contains("millimeter") || currUnit.contains("millimetre")) {
875-
currUnitOME = UNITS.MILLIMETER;
876-
877-
} else if (currUnit.matches("cm") || currUnit.contains("centimeter") || currUnit.contains("centimetre")) {
878-
currUnitOME = UNITS.CENTIMETER;
879-
880-
} else if (currUnit.matches("nm") || currUnit.contains("nanometer") || currUnit.contains("nanometre")) {
881-
currUnitOME = UNITS.NANOMETER;
882-
883-
} else if (currUnit.matches("A") || currUnit.matches("Å") || currUnit.contains("angstrom")) {
884-
currUnitOME = UNITS.ANGSTROM;
885-
886-
} else if (currUnit.matches("m") || currUnit.contains("meter") || currUnit.contains("metre")) {
887-
// THIS ONE HAS TO BE THE LAST ONE AS IT WILL PROBABLY MATCH
888-
currUnitOME = UNITS.METER;
889-
}
890-
891870
if (currUnitOME == null) {
892871
if (path == null) {
893872
MIA.log.writeWarning(
@@ -911,29 +890,9 @@ void parseImageJTemporalCalibration(ImagePlus ipl, String path) {
911890

912891
// Checking if spatial units match those selected in InputControl
913892
String currUnit = cal.getTimeUnit().toLowerCase();
914-
Unit<Time> currUnitOME = null;
893+
Unit<Time> currUnitOME = TemporalUnit.getOMEUnit(currUnit);
915894
Unit<Time> targetUnitOME = TemporalUnit.getOMEUnit();
916895

917-
if (currUnit.matches("ns") || currUnit.contains("nanosecond")) {
918-
currUnitOME = UNITS.NANOSECOND;
919-
920-
} else if (currUnit.matches("ms") || currUnit.contains("millisecond")) {
921-
currUnitOME = UNITS.MILLISECOND;
922-
923-
} else if (currUnit.matches("m") || currUnit.contains("min") || currUnit.contains("minute")) {
924-
currUnitOME = UNITS.MINUTE;
925-
926-
} else if (currUnit.matches("h") || currUnit.contains("hour")) {
927-
currUnitOME = UNITS.HOUR;
928-
929-
} else if (currUnit.matches("d") || currUnit.matches("day")) {
930-
currUnitOME = UNITS.DAY;
931-
932-
} else if (currUnit.matches("s") || currUnit.contains("sec") || currUnit.contains("second")) {
933-
// THIS ONE HAS TO BE THE LAST ONE AS IT WILL PROBABLY MATCH
934-
currUnitOME = UNITS.SECOND;
935-
}
936-
937896
if (currUnitOME == null && ipl.getNFrames() != 1) {
938897
if (path == null) {
939898
MIA.log.writeWarning(

mia-modules/src/main/java/io/github/mianalysis/mia/module/objects/measure/intensity/MeasureObjectIntensity.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
package io.github.mianalysis.mia.module.objects.measure.intensity;
44

5-
import java.util.ArrayList;
6-
75
import org.apache.commons.math3.stat.descriptive.rank.Median;
86
import org.scijava.Priority;
97
import org.scijava.plugin.Plugin;

0 commit comments

Comments
 (0)