Skip to content

Instantly share code, notes, and snippets.

@romainGuiet
Last active July 5, 2023 09:15
Show Gist options
  • Save romainGuiet/81b17e46ba788de84b8340be9e610f58 to your computer and use it in GitHub Desktop.
Save romainGuiet/81b17e46ba788de84b8340be9e610f58 to your computer and use it in GitHub Desktop.
make detection of a define size
/* = CODE DESCRIPTION =
* This QuPath script fills thae image Annotations objects with circular detections objects of a user defined diameter.
* In combination with "Measure > Show measurements maps" it can be helpfull to quickly create meaningful heatmaps.
*
* == INPUTS ==
* Annotation(s) and RegionOfInterest diamater (in microns)
*
* == OUTPUTS ==
* circular detections objects of a user defined diameter
*
* = DEPENDENCIES =
* QuPath
*
* = INSTALLATION =
* Darg and drop the script on QuPath, open an image with annotation(s), press RUN
*
* = AUTHOR INFORMATION =
* Code written by romain guiet, EPFL - SV - PTECH - BIOP
* for XXX XXX, Lab XXX
* 2023.01.18
*
* = COPYRIGHT =
* (c) All rights reserved. ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE, Switzerland, BioImaging And Optics Platform (BIOP), 2023
*
* Licensed under the BSD-3-Clause License:
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
roi_microns = 20
px_width = getCurrentServer().getPixelCalibration().getAveragedPixelSizeMicrons()
roi_width = Math.round (roi_microns/px_width ) // in microns
roi_height = roi_width
roi_spacing = roi_width + Math.round (roi_width/10 ) as int
clearDetections()
annots = getAnnotationObjects()
annots.each{ annot ->
println (annot)
roi = annot.getROI()
xO = roi.getBoundsX()
yO = roi.getBoundsY()
w = roi.getBoundsWidth()
h = roi.getBoundsHeight()
circles = []
(0..h).step(roi_spacing).each{ y ->
(0..w).step(roi_spacing).each{ x ->
if ( roi.contains( xO+x, yO+y) ){
def circle = ROIs.createEllipseROI(xO+x, yO+y, roi_width, roi_height, roi.getImagePlane() )
def detection = PathObjects.createDetectionObject( circle)
circles.add(detection)
}
}
}
addObjects(circles)
}
fireHierarchyUpdate()
selectDetections();
runPlugin('qupath.lib.algorithms.IntensityFeaturesPlugin', '{"pixelSizeMicrons": '+roi_microns+', "region": "ROI", "tileSizeMicrons": 25.0, "channel1": true, "channel2": true, "channel3": true, "channel4": true, "channel5": true, "channel6": false, "doMean": true, "doStdDev": true, "doMinMax": true, "doMedian": true, "doHaralick": false, "haralickMin": NaN, "haralickMax": NaN, "haralickDistance": 1, "haralickBins": 32}');
println "done!"
import qupath.lib.roi.*
import qupath.lib.roi.EllipseROI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment