Skip to content

Commit

Permalink
Pixel classification refactoring
Browse files Browse the repository at this point in the history
Major refactoring of pixel classification, including:
- Pixel layer added as an ImageData property, displayed by default with the pixel layer overlay & supporting dynamic measurements on request
- Added 'getOutputType()' for ImageServers in general, to support more server implementations that return classifications/features
- Added (rough) implementation of simple threshold command
  • Loading branch information
petebankhead committed Apr 14, 2019
1 parent b748cbd commit ad8595e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected BufferedImage readTile(TileRequest tileRequest) throws IOException {
public int getClassification(int x, int y, int z, int t) throws IOException {

var type = classifier.getMetadata().getOutputType();
if (type != ImageServerMetadata.OutputType.CLASSIFICATION && type != ImageServerMetadata.OutputType.PROBABILITIES)
if (type != ImageServerMetadata.OutputType.CLASSIFICATION && type != ImageServerMetadata.OutputType.PROBABILITY)
return -1;

var tile = getTile(0, x, y, z, t);
Expand Down Expand Up @@ -186,7 +186,7 @@ public int getClassification(int x, int y, int z, int t) throws IOException {
logger.error("Error requesting classification", e);
return -1;
}
} else if (type == ImageServerMetadata.OutputType.PROBABILITIES) {
} else if (type == ImageServerMetadata.OutputType.PROBABILITY) {
int maxInd = -1;
double maxVal = Double.NEGATIVE_INFINITY;
var raster = img.getRaster();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static class Builder {
private PixelType inputDataType = PixelType.UInt8;
private int outputWidth = -1;
private int outputHeight = -1;
private ImageServerMetadata.OutputType outputType = ImageServerMetadata.OutputType.PROBABILITIES;
private ImageServerMetadata.OutputType outputType = ImageServerMetadata.OutputType.PROBABILITY;
private List<ImageChannel> channels = new ArrayList<>();

public PixelClassifierMetadata build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public interface ImageServer<T> extends AutoCloseable {
* @return
*/
public default ImageServerMetadata.OutputType getOutputType() {
return ImageServerMetadata.OutputType.CHANNELS;
return ImageServerMetadata.OutputType.CHANNEL;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@
*/
public class ImageServerMetadata {

public static enum OutputType { CHANNELS, FEATURES, PROBABILITIES, CLASSIFICATION;
public static enum OutputType { CHANNEL, FEATURE, PROBABILITY, MULTICLASS_PROBABILITY, CLASSIFICATION;

@Override
public String toString() {
switch (this) {
case CHANNELS:
return "Channels";
case FEATURES:
return "Features";
case PROBABILITIES:
return "Probabilities";
case CHANNEL:
return "Channel";
case FEATURE:
return "Feature";
case PROBABILITY:
return "Probability";
case MULTICLASS_PROBABILITY:
return "Multiclass probability";
case CLASSIFICATION:
return "Classification";
default:
Expand All @@ -78,7 +80,7 @@ public String toString() {
private int sizeZ = 1;
private int sizeT = 1;

public ImageServerMetadata.OutputType outputType = ImageServerMetadata.OutputType.CHANNELS;
public ImageServerMetadata.OutputType outputType = ImageServerMetadata.OutputType.CHANNEL;

private boolean isRGB = false;
private int bitDepth = 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void initialize(final QuPathViewer viewer) {
// Output
var labelOutput = new Label("Output");
var comboOutput = new ComboBox<ImageServerMetadata.OutputType>();
comboOutput.getItems().addAll(ImageServerMetadata.OutputType.CLASSIFICATION, ImageServerMetadata.OutputType.PROBABILITIES);
comboOutput.getItems().addAll(ImageServerMetadata.OutputType.CLASSIFICATION, ImageServerMetadata.OutputType.PROBABILITY);
selectedOutputType = comboOutput.getSelectionModel().selectedItemProperty();
selectedOutputType.addListener((v, o, n) -> {
updateClassifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public BufferedImage applyClassification(final ImageData<BufferedImage> imageDat

ColorModel colorModelLocal = null;

if (type == ImageServerMetadata.OutputType.PROBABILITIES) {
if (type == ImageServerMetadata.OutputType.PROBABILITY) {
var matProbabilities = matOutput;
double maxValue = 1.0;
if (do8Bit()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public synchronized void updateMeasurementList() {
var pixelClassifier = imageData.getProperty("PIXEL_LAYER");
if (pixelClassifier instanceof ImageServer<?>) {
ImageServer<BufferedImage> server = (ImageServer<BufferedImage>)pixelClassifier;
if (server.getOutputType() == ImageServerMetadata.OutputType.CLASSIFICATION || server.getOutputType() == ImageServerMetadata.OutputType.PROBABILITIES) {
if (server.getOutputType() == ImageServerMetadata.OutputType.CLASSIFICATION || server.getOutputType() == ImageServerMetadata.OutputType.PROBABILITY) {
var pixelManager = new PixelClassificationMeasurementManager(server);
for (String name : pixelManager.getMeasurementNames()) {
builderMap.put(name, new PixelClassifierMeasurementBuilder(pixelManager, name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ synchronized MeasurementList calculateMeasurements(final ROI roi, final boolean

// Check we have a suitable output type
ImageServerMetadata.OutputType type = classifierServer.getOutputType();
if (type == ImageServerMetadata.OutputType.FEATURES)
if (type == ImageServerMetadata.OutputType.FEATURE)
return null;


Expand Down Expand Up @@ -204,7 +204,7 @@ synchronized MeasurementList calculateMeasurements(final ROI roi, final boolean
logger.error("Error calculating classification areas", e);
}
break;
case PROBABILITIES:
case PROBABILITY:
// Take classification from the channel with the highest value
raster = tile.getRaster();
rasterMask = imgMask.getRaster();
Expand Down

0 comments on commit ad8595e

Please sign in to comment.