https://github.com/qupath/qupath-imglib2
A Java library to link QuPath and ImgLib2
https://github.com/qupath/qupath-imglib2
Last synced: 5 months ago
JSON representation
A Java library to link QuPath and ImgLib2
- Host: GitHub
- URL: https://github.com/qupath/qupath-imglib2
- Owner: qupath
- License: apache-2.0
- Created: 2025-09-24T09:29:46.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2026-01-16T16:44:07.000Z (5 months ago)
- Last Synced: 2026-01-17T05:26:38.333Z (5 months ago)
- Language: Java
- Size: 238 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QuPath-imglib2
A Java library to link QuPath with ImgLib2.
## Sample script
Here is a sample script that shows how to use the library from QuPath:
```groovy
import qupath.ext.imglib2.ImgBuilder
import qupath.ext.imglib2.ImgLib2ImageServer
import net.imglib2.type.numeric.ARGBType
var server = getCurrentServer()
// Create Img from level
var level = 0
var img = ImgBuilder.createBuilder(server).buildForLevel(level)
println img
// Create RandomAccessibleInterval from downsample
var downsample = 1
var randomAccessible = ImgBuilder.createBuilder(server).buildForDownsample(downsample)
println randomAccessible
// In previous examples, the type of the output image is not checked, which creates unchecked cast warnings
// (visible from Java, not Groovy). A better solution in Java to explicitely declare the output image type:
var type = new ARGBType() // only valid if server represents a RGB image. Otherwise:
// net.imglib2.type.numeric.integer.UnsignedByteType for UINT8 images
// net.imglib2.type.numeric.integer.ByteType for INT8 images
// net.imglib2.type.numeric.integer.UnsignedShortType for UINT16 images
// net.imglib2.type.numeric.integer.ShortType for INT16 images
// net.imglib2.type.numeric.integer.UnsignedIntType for UINT32 images
// net.imglib2.type.numeric.integer.IntType for INT32 images
// net.imglib2.type.numeric.real.FloatType for FLOAT32 images
// net.imglib2.type.numeric.real.DoubleType for FLOAT64 images
var safeImg = ImgBuilder.createBuilder(server, type).buildForLevel(level)
println safeImg
// Once you have an image (or random accessible), you can use regular ImgLib2 functions
// For example, to read the pixel located at [x:1, y:2; c:0; z:0; t:0]:
var randomAccess = randomAccessible.randomAccess()
var position = new long[ImgBuilder.NUMBER_OF_AXES]
position[ImgBuilder.AXIS_X] = 1
position[ImgBuilder.AXIS_Y] = 2
var pixel = randomAccess.setPositionAndGet(position)
println pixel
// It is also possible to create an ImageServer from a RandomAccessible or Img
var newServer = ImgLib2ImageServer.builder(List.of(randomAccessible)).build()
println newServer
```