Skip to content

Commit

Permalink
Merge branch 'main' into Fix_network_loading
Browse files Browse the repository at this point in the history
  • Loading branch information
SachidanandAlle authored Aug 26, 2023
2 parents 1a32ea2 + 43e9e2a commit a3f1eab
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 22 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ Refer to full [MONAI Label documentations](https://docs.monai.io/projects/label/
Refer to [MONAI Label Tutorial](https://github.com/Project-MONAI/tutorials/tree/main/monailabel) series for application and viewer workflows with different medical image tasks. Notebook-like tutorials are created for detailed instructions.

### Table of Contents
- [Overview](#Overview)
- [Highlights and Features](#Highlights-and-Features)
- [Supported Matrix](#Supported-Matrix)
- [Getting Started with MONAI Label](#Getting-Started-with-MONAI-Label)
- [Step 1. Installation](#Step-1-Installation)
- [Step 2. MONAI Label Sample Applications](#Step-2-MONAI-Label-Sample-Applications)
- [Step 3. MONAI Label Supported Viewers](#Step-3-MONAI-Label-Supported-Viewers)
- [Step 4. Data Preparation](#Step-4-Data-Preparation)
- [Step 5. Start MONAI Label Server and Start Annotating!](#Step-5-Start-MONAI-Label-Server-and-Start-Annotating)
- [MONAI Label Tutorials](#MONAI-Label-Tutorials)
- [Cite MONAI Label](#Cite)
- [Contributing](#Contributing)
- [Community](#Community)
- [Additional Resources](#Additional-Resources)
- [Overview](#overview)
- [Highlights and Features](#highlights-and-features)
- [Supported Matrix](#supported-matrix)
- [Getting Started with MONAI Label](#getting-started-with-monai-label)
- [Step 1. Installation](#step-1-installation)
- [Step 2. MONAI Label Sample Applications](#step-2-monai-label-sample-applications)
- [Step 3. MONAI Label Supported Viewers](#step-3-monai-label-supported-viewers)
- [Step 4. Data Preparation](#step-4-data-preparation)
- [Step 5. Start MONAI Label Server and Start Annotating!](#step-5-start-monai-label-server-and-start-annotating)
- [MONAI Label Tutorials](#monai-label-tutorials)
- [Cite MONAI Label](#cite)
- [Contributing](#contributing)
- [Community](#community)
- [Additional Resources](#additional-resources)

### Overview
MONAI Label reduces the time and effort of annotating new datasets and enables the adaptation of AI to the task at hand by continuously learning from user interactions and data. MONAI Label allows researchers and developers to make continuous improvements to their apps by allowing them to interact with their apps at the user would. End-users (clinicians, technologists, and annotators in general) benefit from AI continuously learning and becoming better at understanding what the end-user is trying to annotate.
Expand Down Expand Up @@ -165,11 +165,11 @@ In addition, you can find a table of the basic supported fields, modalities, vie

# Getting Started with MONAI Label
### MONAI Label requires a few steps to get started:
- Step 1: [Install MONAI Label](#Step-1-Installation)
- Step 2: [Download a MONAI Label sample app or write your own custom app](#Step-2-MONAI-Label-Sample-Applications)
- Step 3: [Install a compatible viewer and supported MONAI Label Plugin](#Step-3-MONAI-Label-Supported-Viewers)
- Step 4: [Prepare your Data](#Step-4-Data-Preparation)
- Step 5: [Launch MONAI Label Server and start Annotating!](#Step-5-Start-MONAI-Label-Server-and-Start-Annotating)
- Step 1: [Install MONAI Label](#step-1-installation)
- Step 2: [Download a MONAI Label sample app or write your own custom app](#step-2-monai-label-sample-applications)
- Step 3: [Install a compatible viewer and supported MONAI Label Plugin](#step-3-monai-label-supported-viewers)
- Step 4: [Prepare your Data](#step-4-data-preparation)
- Step 5: [Launch MONAI Label Server and start Annotating!](#step-5-start-monai-label-server-and-start-annotating)

## Step 1 Installation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@

import javax.xml.parsers.ParserConfigurationException;

import org.controlsfx.dialog.ProgressDialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javafx.concurrent.Task;
import qupath.lib.extension.monailabel.MonaiLabelClient;
import qupath.lib.extension.monailabel.MonaiLabelClient.RequestInfer;
import qupath.lib.extension.monailabel.MonaiLabelClient.ResponseInfo;
Expand Down Expand Up @@ -76,9 +78,15 @@ public void run() {
var selected = imageData.getHierarchy().getSelectionModel().getSelectedObject();
var roi = selected != null ? selected.getROI() : null;

if (roi == null || !(roi instanceof RectangleROI)) {
Dialogs.showPlainMessage("Please create and select ROI", "Please create and select a Rectangle ROI before " +
"running this method.\nThe \"Annotations\" function creates annotations within the selected rectangle.");
return;
}

String imageFile = Utils.getFileName(viewer.getImageData().getServerPath());
String im = imageFile.toLowerCase();
boolean isWSI = (im.endsWith(".png") || im.endsWith(".jpg") || im.endsWith(".jpeg")) ? false : true;
boolean isWSI = !im.endsWith(".png") && !im.endsWith(".jpg") && !im.endsWith(".jpeg");
logger.info("MONAILabel:: isWSI: " + isWSI + "; File: " + imageFile);

// Select first RectangleROI if not selected explicitly
Expand Down Expand Up @@ -112,6 +120,7 @@ public void run() {

ParameterList list = new ParameterList();
list.addChoiceParameter("Model", "Model Name", selectedModel, names);
list.addTitleParameter("Parameters of selected ROI:");
if (isWSI) {
list.addStringParameter("Location", "Location (x,y,w,h)", Arrays.toString(bbox));
list.addIntParameter("TileSize", "TileSize", tileSize);
Expand All @@ -131,8 +140,42 @@ public void run() {
selectedBBox = bbox;
selectedTileSize = tileSize;

runInference(model, info, bbox, tileSize, imageData, imageFile, isWSI);
// runInference(model, info, bbox, tileSize, imageData, imageFile, isWSI);
final int[] finalBbox = bbox;
final int finalTileSize = tileSize;

Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
runInference(model, info, finalBbox, finalTileSize, imageData, imageFile, isWSI);
return null;
}
};

ProgressDialog progressDialog = new ProgressDialog(task);
progressDialog.setTitle("MONAILabel");
progressDialog.setHeaderText("Server-side processing is in progress, please wait...");
progressDialog.setContentText("Annotations will be drawn immediately after the method ends.");
progressDialog.initOwner(qupath.getStage());

// Start the inference
new Thread(task).start();

task.setOnSucceeded(event -> {
progressDialog.close();
});
task.setOnFailed(event -> {
progressDialog.close();
Throwable ex = task.getException();
if (ex != null) {
ex.printStackTrace();
Dialogs.showErrorMessage("MONAILabel", ex);
}
});
}

imageData.getHierarchy().removeObject(imageData.getHierarchy().getSelectionModel().getSelectedObject(), true);
imageData.getHierarchy().getSelectionModel().clearSelection();
} catch (Exception ex) {
ex.printStackTrace();
Dialogs.showErrorMessage("MONAILabel", ex);
Expand Down Expand Up @@ -296,7 +339,7 @@ public static int updateAnnotations(Set<String> labels, NodeList annotation_list
int color = Color.RED.getRGB();
Node colorNode = annotation.getAttributes().getNamedItem("Color");
if (colorNode != null) {
color = Integer.parseInt(colorNode.getTextContent().replaceFirst("#", ""), 16) ;
color = Integer.parseInt(colorNode.getTextContent().replaceFirst("#", ""), 16);
// logger.info("Annotation Class: " + annotationClass + " Annotation Color: " + colorNode.getTextContent());
}

Expand Down

0 comments on commit a3f1eab

Please sign in to comment.