Skip to content

Instantly share code, notes, and snippets.

View lacan's full-sized avatar
🤝

Olivier Burri lacan

🤝
View GitHub Profile
@lacan
lacan / Export_Images_Folder.ijm
Last active February 24, 2024 12:27
Extract multi-series file and resave as TIFF stacks or slices #Fiji #ImageJ #Macro #BIOP
/*
* Complex Format EXPORT MACRO
* By Olivier Burri @ EPFL - SV - PTECH - BIOP
* Given a folder, extracts all series inside all multi-file files with given extension in new folders
* Last edit: 13.02.2017
*/
////////////////////// SET PARAMETERS //////////////////////
////////////////////////////////////////////////////////////
@lacan
lacan / Replace detections as cells via erosion and add measurements.groovy
Created February 12, 2024 08:36
[Replace detections as cells via erosion and add measurements] Erodes existing detection objects to create cells and adds all compartment measurements #qupath #groovy #detections
/**
* Reduce Detection size to create new cell objects and add measurements
* @author Olivier Burri
* @date 20240212
*/
// By how much should the existing detections be reduced to create the new "nucleus"
def erosionDistancePx = -5
// Should the intensities be measured on a downsampled image?
@lacan
lacan / Parallel_HistrogramEqualize_All_Slices.groovy
Last active November 11, 2023 13:51
[Parallel Histrogram-Based Normalization] This performs Histogram Based Normalization on all slices of an open stack based on the selected reference slice #fiji #imageJ #histogram #BIOP
#@ ImagePlus image
#@ Integer ( label = "Channel to correct (in case of multichannel images)", value = 1 ) ch_correct
#@ Integer ( label = "Reference Slice", value = 1 ) ref_slice
#@ Boolean ( label = "Use Manual Normalization Parameters Below", value = false ) is_normalize
#@ Integer ( Label = "Minimum" ) the_min
#@ Integer ( Label = "Maximum" ) the_max
// This variable will help us at the end to add the normalized channel back
def all_images = []
@lacan
lacan / resave-as-pyramid-with-fixed-bit-depth.groovy
Last active November 1, 2023 09:26
[Resave pyramid with fixed bit depth] Resaves the current image entry as an ome.tiff #qupath #groovy
// Resave image as a pyramidal ome.tiff at the desired downsample and bit depth
// @author Olivier Burri
// 16-bit magic trick inspired from
// https://forum.image.sc/t/software-recommendations-converting-a-32bit-ome-tiff-to-an-8bit-ome-tiff/43043
// But did not use scaling parameter
// ****** PARAMETERS *********
// Output downsample (1 for full-resolution)
def outputDownsample = 1
@lacan
lacan / Example_RNG.groovy
Last active October 30, 2023 12:28
[Relative Neighborhood Graph Algorithm] Simple RNG graph thanks to ChatGPT #groovy #chatgpt #fiji
// DISCLAIMER: The algorithm was taken from a ChatGPT prompt "What is the Groovy implementation of the 2D Relative Neighborhood Graph Algorithm"
// It is merey an alpha version of the code and has not been thorougly tested at all, nor has the code been optimized.
// The original prompt has been slightly modifided to make better use of ImageJ methods to display the graph
// Create a list of points for testing
def rand = new Random()
// Or to make it reproducible
//def rand = new Random( 1000 )
@lacan
lacan / Rename_VSI_files_from_csv.groovy
Last active September 5, 2023 12:29
[Rename VSI files and folders from CSV] This script helps rename VSI images and folders that have incorrect names #svi #slidescanner #groovy #fiji
#@File originalDir (label="Directory with original VSI Files", style="directory")
#@File csvFile (label="CSV File with full VSI file path in columns 1 and new name in column 2")
#@String sep (label="CSV separator", value=";")
/*
* Rename VSI images based on CSV reference file
*/
println sep
def csvImages = csvFile.readLines()*.split(sep)
@lacan
lacan / Fix_unmapped_image_entry_uris.groovy
Created August 24, 2023 07:29
[Fix Unmapped Image Entry URIs] Fix overly long times to reach "Update URIs" when the server address changed #groovy #qupath #project #uri #server
/*
* Update QuPath URIs
* After the migration of our EPFL servers from svfasX to sv-nas1.rcp, some projects fail to open in a timely manner,
* especially under Windows when the full path to the server is used (instead of a networked drive).
* The reason seems to be that QuPath is waiting for a response from the server, and the timeouts are long, so it takes a
* really long time before the "Update URIs" window pops up
*
* This script aims to assist in fixing that by at least changing the host name (svfasX) to a valid host (sv-nas1.rcp)
* that way, QuPath will immediately either find or fail to find the file, restoring normal behavior
*
@lacan
lacan / Create_progress_monitor.groovy
Created August 3, 2023 12:49
[Create Progress Monitor in QuPath] Build a progress monitor that is either command line or graphical #qupath #groovy
// Example creating a dialog to run tasks in a script.
// We need to discern between headless and non-headless manually so far
// @author Olivier Burri
//
import qupath.lib.plugins.CommandLinePluginRunner
import qupath.lib.gui.PluginRunnerFX
// Define the runner, in this case we will not use it but it is quite powerful
def runner
@lacan
lacan / Export Annotations For Stardist.groovy
Last active July 30, 2023 14:32
[QuPath Script To Export Annotations For Stardist] this script will take rectangular annotations in QuPath and export them and their containing objects as images and masks for deep neural netowrk training #qupath #stardist #BIOP
/*
// ABOUT
Exports Annotations for StarDist (Or other Deep Learning frameworks)
// INPUTS
You need rectangular annotations that have classes "Training" and "Validation"
After you have placed these annotations, lock them and start drawing the objects inside
// OUTPUTS
----------
@lacan
lacan / HoughIncompleteCirclesSEM.ijm
Created September 3, 2020 16:52
[Use of Hough Transform to locate incomplete circles in images] This script segments SEM images containing pores and tries to fit circles to the result
// Hough Transform to find circles,
// Author: Olivier Burri, from a request of the Image.sc forum:
// https://forum.image.sc/t/find-circles-with-incomplete-boundaries/42357
// Due to the simple nature of this code, no copyright applies
#@ImagePlus image
#@Double hough_threshold (value=0.55)
// SOme housekeeping