Skip to content

Instantly share code, notes, and snippets.

@hanslovsky
Last active March 15, 2021 02:46
Show Gist options
  • Save hanslovsky/0a7513ceaed117e7bb05b4a789082de2 to your computer and use it in GitHub Desktop.
Save hanslovsky/0a7513ceaed117e7bb05b4a789082de2 to your computer and use it in GitHub Desktop.
import net.imglib2.imklib.*
import net.imglib2.type.volatiles.*
import net.imglib2.type.numeric.integer.*
// pick any data here
val rawData = imklib.io.n5.openUntypedHDF5("/home/zottel/Downloads/sample_A_20160501.hdf", "volumes/raw").asUnsignedBytes()
val rawDataExtended = rawData.extendBorder().asInts()
val gradientMagnitudeData = (0..2)
.map { d -> LongArray(3) { if (it == d) 1 else 0 } }
.map { rawDataExtended[rawData + it].zeroMin - rawDataExtended[rawData - it].zeroMin }
.map { it * it }
.reduce { d1, d2 -> d1 + d2 }
.cache()
val res = doubleArrayOf(4.0, 4.0, 40.0)
val off = DoubleArray(3) { 0.0 }
val raw = paintera.baseView.addSingleScaleRawSource<UnsignedByteType, VolatileUnsignedByteType>(
rawData, res, off, 0.0, 255.0, "raw"
)
val gradientMagnitude = paintera.baseView.addSingleScaleRawSource<IntType, VolatileIntType>(
gradientMagnitudeData, res, off, 0.0, 2047.0, "gradient magnitude squared"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment