Skip to content

Instantly share code, notes, and snippets.

@caner-ercan
caner-ercan / QuPath Memory Monitor.groovy
Last active February 16, 2024 16:52 — forked from petebankhead/QuPath Memory Monitor.groovy
Groovy script to help monitor memory use over time #QuPath
/**
* A basic GUI to help monitor memory usage in QuPath.
*
* This helps both to find & address out-of-memory troubles by
* 1. Showing how much memory is in use over time
* 2. Giving a button to clear the tile cache - which can be
* using up precious memory
* 3. Giving quick access to control the number of threads used
* for parallel processing
*
/**
From https://forum.image.sc/t/qupath-multiple-image-alignment-and-object-transfer/35521/2
0.2.0m9
If you have annotations within annotations, you may get duplicates. Ask on the forum or change the def pathObjects line.
To use, have all objects desired in one image, and alignment files in the Affine folder within your project folder.
If you have not saved those, this script will not work.
It will use ALL of the affine transforms in that folder to transform the objects in the current image to the destination images
that are named after the affine files.
//*
//Caner Ercan
//caner.ercan@usb.ch
//First Dialog Asks for the folder which contains all the images
//Second dialog asks for time zero image
//It generates a file in the same folder named as Results.csv
*//
setBatchMode(true);
input = getDirectory("Choose Image Directory");
@caner-ercan
caner-ercan / StarDistDetection_calculation.groovy
Last active February 16, 2024 16:53
#StarDist Cell Detection #QuPath
//don't forget to change the stardist model location
// this script will detect the cells and calculate shape, intensity features
// iff you have a cell classifier model you can add it too at line 53
// the output measurements will be in a folder named 'cellMeasurements' in the project directory
//caner 15.02.23
import qupath.ext.stardist.StarDist2D
import qupath.lib.images.servers.*
// Specify the model directory (you will need to change this!)
@caner-ercan
caner-ercan / annotation_to_detection
Last active June 20, 2025 01:12
QuPath _ AI-TIL #QuPath
//0.2.0 version of https://forum.image.sc/t/assign-point-objects-to-different-rois-by-overlap/26905/2?u=research_associate
// Convert points into detections, resolve the heirarchy so they are now child objects of any annotations.
import qupath.lib.roi.EllipseROI;
import qupath.lib.objects.PathDetectionObject
points = getAnnotationObjects().findAll{it.getROI().isPoint() }
print points[0].getROI()
describe(points[0].getROI())
import org.apache.commons.io.FilenameUtils
def name = FilenameUtils.getBaseName(getProjectEntry().getImageName())
def server = getCurrentServer()
selectObjectsByClassification("flow")
anns =[]
def anns = getSelectedObjects()
i=0
for (ann in anns) {
def roi = ann.getROI()
@caner-ercan
caner-ercan / featch_annotation_info.sh
Last active January 5, 2025 23:16
QuPath data access via json
#!/bin/bash
# Define the base directory
BASE_DIR="/Users/cercan/Desktop/BE/NU_wholeDataset_qupath/data" # Change this to your target directory
OUTPUT_CSV="/Users/cercan/Desktop/BE/NU_wholeDataset_qupath/annotationData.csv"
# Write the header to the CSV file
echo "Name,Unclassified,Biopsy,Flow" > "$OUTPUT_CSV"
# Find all subdirectories and process the JSON files
resolveHierarchy()
def server = getCurrentServer()
tsv_folder = buildFilePath(PROJECT_BASE_DIR, "tsv")
def checkDir = new File(tsv_folder)
if(!checkDir.exists()) {
checkDir.mkdir()
}
csv_folder = buildFilePath(PROJECT_BASE_DIR, "corrected_point")
checkDir = new File(csv_folder)
@caner-ercan
caner-ercan / delete_by_class.groovy
Created September 10, 2024 23:54
Annotation manipulations
def classes2delete = ["tissue_box", "tissue"]
classes2delete.each { delclass ->
print delclass
toRemove = getAnnotationObjects().findAll {
it.getPathClass()==getPathClass(delclass)
removeObject(it, true)
}
@caner-ercan
caner-ercan / crate_img_list.R
Created October 23, 2024 23:16
#QuPath HPC project run
base_path = "B:/data/BE/cell_detect/acformer/"
collected_data = NULL
for (dataset in c("NU_dataset_rois","MDA1_dataset_rois","MDA2_dataset_rois")){
txt_path = paste(base_path,dataset ,"img_list.txt",sep="/")
print(txt_path)
txt_table = read.table(txt_path)