Guest User

Untitled

a guest
Mar 18th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. /**
  2. * Create a region annotation with a fixed size in QuPath, based on the current viewer location.
  3. *
  4. * @author Pete Bankhead
  5. */
  6.  
  7. import qupath.lib.objects.PathAnnotationObject
  8. import qupath.lib.objects.classes.PathClassFactory
  9. import qupath.lib.roi.RectangleROI
  10. import qupath.lib.scripting.QPEx
  11.  
  12. // Define the size of the region to create
  13. double sizeMicrons = 200.0
  14.  
  15. // Get main data structures
  16. def imageData = QPEx.getCurrentImageData()
  17. def server = imageData.getServer()
  18.  
  19. // Convert size in microns to pixels - QuPath ROIs are defined in pixel units of the full-resolution image
  20. int sizePixels = Math.round(sizeMicrons / server.getAveragedPixelSizeMicrons())
  21.  
  22. // Get the current viewer & the location of the pixel currently in the center
  23. def viewer = QPEx.getCurrentViewer()
  24. double cx = viewer.getCenterPixelX()
  25. double cy = viewer.getCenterPixelY()
  26.  
  27. // Create a new Rectangle ROI
  28. def roi = new RectangleROI(cx-sizePixels/2, cy-sizePixels/2, sizePixels, sizePixels)
  29.  
  30. // Create & new annotation & add it to the object hierarchy
  31. def annotation = new PathAnnotationObject(roi, PathClassFactory.getPathClass("Region"))
  32. imageData.getHierarchy().addPathObject(annotation, false)
Add Comment
Please, Sign In to add comment