Browse Source

Avoid needless duplication of ImageProcessor.

When the ChannelMasker calls the apply method, it passes an
ImageProcessor source which has already been duplicated, so there's
no need to duplicate that object again prior to applying the mask.
master
Damien Goutte-Gattat 2 years ago
parent
commit
076f1021a6
  1. 3
      src/main/java/org/incenp/imagej/ChannelMasker.java
  2. 7
      src/main/java/org/incenp/imagej/Masking.java

3
src/main/java/org/incenp/imagej/ChannelMasker.java

@ -166,7 +166,8 @@ public class ChannelMasker {
case APPLY:
src = image.getProcessor().duplicate();
image.setC(getChannel(op.argument[0], order));
ip = Masking.applyMask(src, image.getProcessor(), operators[op.argument[1]], maskingOptions);
ip = Masking.applyMask(src, image.getProcessor(), operators[op.argument[1]],
maskingOptions | Masking.NO_DUPLICATE);
break;
}

7
src/main/java/org/incenp/imagej/Masking.java

@ -45,6 +45,11 @@ public class Masking {
*/
public static final int CLOSE_OPEN_MASK = 0x02;
/**
* Avoid duplicating the source image when possible.
*/
public static final int NO_DUPLICATE = 0x04;
private static final AutoThresholder globalThresholder = new AutoThresholder();
private static final Auto_Local_Threshold localThresholder = new Auto_Local_Threshold();
@ -152,7 +157,7 @@ public class Masking {
*/
public static ImageProcessor applyMask(ImageProcessor source, ImageProcessor mask, BinaryOperator operator,
int options) {
ImageProcessor result = source.duplicate();
ImageProcessor result = (options & NO_DUPLICATE) > 0 ? source : source.duplicate();
if ( (options & WHITE_MASK) > 0 ) {
mask = mask.duplicate();

Loading…
Cancel
Save