Skip to content

Annotation Tools

Annota provides a comprehensive set of tools for creating and editing annotations.

Tools enable users to interact with the image and create annotations. Each tool implements a specific interaction pattern:

ToolPurposeInteraction
PointToolCreate point markersSingle click
RectangleToolDraw rectanglesClick and drag
PolygonToolDraw polygonsClick vertices, double-click to finish
PushToolEdit polygon verticesClick and drag to push/pull vertices
ContourToolExtract contours from masksClick to detect contours
SplitToolCut annotations into piecesClick start point, click end point

Activate a tool using the useTool hook:

import { useTool, PointTool } from "annota";
function MyComponent({ viewer }) {
const pointTool = new PointTool();
useTool({
viewer,
handler: pointTool,
enabled: true,
});
return null;
}

Allow users to switch between tools:

import { useTool, PointTool, RectangleTool, PolygonTool } from "annota";
import { useState } from "react";
function ToolController({ viewer }) {
const [activeTool, setActiveTool] = useState("point");
const tools = {
point: new PointTool(),
rectangle: new RectangleTool(),
polygon: new PolygonTool(),
};
useTool({
viewer,
handler: activeTool === "pan" ? null : tools[activeTool],
enabled: activeTool !== "pan",
});
return (
<div>
<button onClick={() => setActiveTool("pan")}>Pan</button>
<button onClick={() => setActiveTool("point")}>Point</button>
<button onClick={() => setActiveTool("rectangle")}>Rectangle</button>
<button onClick={() => setActiveTool("polygon")}>Polygon</button>
</div>
);
}

Create point annotations with a single click.

Use Cases

  • Cell counting
  • Nuclei detection
  • Marking points of interest
  • Landmarks for registration

Interaction

Single click to place a point marker at that location.

import { PointTool } from "annota";
const pointTool = new PointTool({
style: {
fill: "#FF0000",
fillOpacity: 0.8,
stroke: "#FFFFFF",
strokeWidth: 2,
},
});

Draw rectangular regions by clicking and dragging.

Interaction:

  1. Click to start the rectangle
  2. Drag to define the size
  3. Release to finish
import { RectangleTool } from "annota";
const rectangleTool = new RectangleTool({
style: {
fill: "#00FF00",
fillOpacity: 0.3,
stroke: "#00FF00",
strokeWidth: 2,
},
});

Draw polygons by clicking to add vertices.

Interaction:

  1. Click to add vertices
  2. Move mouse to preview next segment
  3. Double-click or press Enter to finish
  4. Press Escape to cancel
import { PolygonTool } from "annota";
const polygonTool = new PolygonTool({
style: {
fill: "#0000FF",
fillOpacity: 0.3,
stroke: "#0000FF",
strokeWidth: 2,
},
});

Edit polygon vertices by pushing and pulling.

import { PushTool } from "annota";
const pushTool = new PushTool({
radius: 50, // Influence radius in pixels
strength: 1.0, // Strength of the push effect (0-1)
showCursor: true, // Show the cursor indicator
});

Interaction:

  1. Click and drag on or near polygon edges
  2. Vertices within the radius are pushed
  3. Effect falls off with distance from cursor

Cut annotations into multiple pieces with a line.

import { SplitTool } from "annota";
const splitTool = new SplitTool();

Workflow:

  1. Select an annotation (before or during tool activation)
  2. Activate the split tool
  3. Click to set the start point of the split line
  4. Move mouse — an orange line preview follows the cursor
  5. Click to set the end point and execute the split

Combine multiple selected annotations into a single annotation:

import { useAnnotator } from "annota";
function MergeButton() {
const annotator = useAnnotator();
const handleMerge = () => {
const merged = annotator.mergeSelected();
if (merged) {
console.log("Successfully merged annotations");
}
};
return <button onClick={handleMerge}>Merge Selected</button>;
}

Automatically detect contours from underlying image data.

import { ContourTool, loadOpenCV } from "annota";
// Load OpenCV before using ContourTool
await loadOpenCV();
const contourTool = new ContourTool({
threshold: 128, // Threshold for binary mask
minArea: 100, // Minimum contour area
maxContours: 1000, // Maximum number of contours
});

All tools support these common options:

const tool = new PointTool({
style: {
fill: "#FF0000",
fillOpacity: 0.8,
stroke: "#FFFFFF",
strokeWidth: 2,
},
});
const tool = new PointTool({
layer: "tumor", // Annotations will be created on the 'tumor' layer
});
const tool = new PointTool({
properties: {
type: "cell",
confidence: 1.0,
},
});

Reuse Instances

Create tool instances once, not on every render.

const [tools] = useState({
point: new PointTool(),
rectangle: new RectangleTool(),
});

Visual Feedback

Show which tool is active with UI highlighting.

Allow Deactivation

Always provide a way to disable tools (e.g., “Pan” mode).

Keyboard Shortcuts

Add keyboard shortcuts for common tools (P, R, G, V).