Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

qupath/qupath-imglib2

Repository files navigation

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:

import qupath.ext.imglib2.ImgBuilder
import qupath.ext.imglib2.ImgLib2ImageServer
import net.imglib2.type.numeric.ARGBType
var server = getCurrentServer()
// Create Img<T> from level
var level = 0
var img = ImgBuilder.createBuilder(server).build().createForLevel(level)
println img
// Create RandomAccessibleInterval<T> from downsample
var downsample = 1
var randomAccessible = ImgBuilder.createBuilder(server).build().createForDownsample(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).build().createForLevel(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

About

A Java library to link QuPath and ImgLib2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

Languages

AltStyle によって変換されたページ (->オリジナル) /