Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements Prediction Mask for Pixel Classification #65

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public PixelClassification(File executableFilePath, File projectFileName, LogSer
}

public <T extends NativeType<T>> ImgPlus<T> classifyPixels(ImgPlus<? extends RealType<?>> rawInputImg,
ImgPlus<? extends RealType<?>> predictionMask,
PixelPredictionType pixelPredictionType) throws IOException {
return executeIlastik(rawInputImg, null, pixelPredictionType);
return executeIlastik(rawInputImg, predictionMask, pixelPredictionType);
}

@Override
Expand All @@ -36,6 +37,10 @@ else if (pixelPredictionType == PixelPredictionType.Probabilities) {
commandLine.add("--raw_data=" + tempFiles.get(rawInputTempFile));
commandLine.add("--output_filename_format=" + tempFiles.get(outputTempFile));

if(tempFiles.containsKey(secondInputTempFile)){
commandLine.add("--prediction_mask=" + tempFiles.get(secondInputTempFile));
}

return commandLine;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.scijava.ItemIO;
import org.scijava.app.StatusService;
import org.scijava.command.Command;
import org.scijava.command.DynamicCommand;
import org.scijava.log.LogService;
import org.scijava.options.OptionsService;
import org.scijava.plugin.Parameter;
Expand All @@ -19,7 +20,7 @@
import static org.ilastik.ilastik4ij.executors.AbstractIlastikExecutor.PixelPredictionType;

@Plugin(type = Command.class, headless = true, menuPath = "Plugins>ilastik>Run Pixel Classification Prediction")
public class IlastikPixelClassificationCommand implements Command {
public class IlastikPixelClassificationCommand extends DynamicCommand {

@Parameter
public LogService logService;
Expand All @@ -42,6 +43,21 @@ public class IlastikPixelClassificationCommand implements Command {
@Parameter(label = "Output type", choices = {UiConstants.PIXEL_PREDICTION_TYPE_PROBABILITIES, UiConstants.PIXEL_PREDICTION_TYPE_SEGMENTATION}, style = "radioButtonHorizontal")
public String pixelClassificationType;

@Parameter(label = "Use Mask?", persist=false, initializer = "initUseMask")
public boolean useMask=false;

protected void initUseMask(){
useMask = false;
//resolveInput("useMask"); //this makes the input not be rendered -.-
}

@Parameter(
label = "Prediction Mask",
required = false,
description = "An image with same dimensions as Raw Data, where the black pixels will be masked out of the predictions"
)
public Dataset predictionMask;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try:

Suggested change
public Dataset predictionMask;
public Dataset predictionMask = null;

to see whether that solves the issue with a default value?


@Parameter(type = ItemIO.OUTPUT)
private ImgPlus<? extends NativeType<?>> predictions;

Expand Down Expand Up @@ -69,7 +85,11 @@ private void runClassification() throws IOException {
projectFileName, logService, statusService, ilastikOptions.getNumThreads(), ilastikOptions.getMaxRamMb());

PixelPredictionType pixelPredictionType = PixelPredictionType.valueOf(pixelClassificationType);
this.predictions = pixelClassification.classifyPixels(inputImage.getImgPlus(), pixelPredictionType);
this.predictions = pixelClassification.classifyPixels(
inputImage.getImgPlus(),
useMask ? predictionMask.getImgPlus() : null,
pixelPredictionType
);

// DisplayUtils.showOutput(uiService, predictions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static <T extends RealType<T> & NativeType<T>> void main(String[] args) t
1024
);

final ImgPlus<T> classifiedPixels = prediction.classifyPixels(inputDataset.getImgPlus(), PixelPredictionType.Probabilities);
final ImgPlus<T> classifiedPixels = prediction.classifyPixels(inputDataset.getImgPlus(), null, PixelPredictionType.Probabilities);

ImageJFunctions.show(classifiedPixels, "Probability maps");
}
Expand Down