Exemplo n.º 1
0
def wrap(img, title="", n_channels=1):
    """ Like ImageJFunctions.wrap but, when n_channels=1 (the default),
      then a new dimension of size 1 is inserted at position 2 to prevent the Z axis
      from showing as the channels axis.
      To enable ImageJFunctions.wrap default behavior, set n_channels to a value other than 1. """
    if 1 == n_channels:
        # Append a dimension of size 1 at the end
        # and permute it iteratively so that it becomes the channels dimension (d=2)
        img = Views.addDimension(img, 1, 1)
        d = img.numDimensions(
        ) - 1  # starts with the last: the new one of size 1
        while d > 2:
            img = Views.permute(img, d, d - 1)
            d -= 1
    #
    return IL.wrap(img, title)
Exemplo n.º 2
0
from net.imglib2.view import Views
from net.imglib2.interpolation.randomaccess import NLinearInterpolatorFactory
from net.imglib2.util import Intervals
from math import radians, floor, ceil
from jarray import zeros

# Load an image (of any dimensions)
imp = IJ.getImage()

# Access its pixel data as an ImgLib2 RandomAccessibleInterval
img = IL.wrap(imp)

# Adjust number of dimensions: we want at least 3 so we can use an AffineTransform3D
# (Could also use an AffineTransform2D but we are being lazy here or general over 2D and 3D)
if img.numDimensions() < 3:
    img = Views.addDimension(img, 0, 0)

# View as an infinite image, with value zero beyond the image edges
imgE = Views.extendZero(img)

# View the pixel data as a RealRandomAccessible
# (that is, accessible with sub-pixel precision)
# by using an interpolator
imgR = Views.interpolate(imgE, NLinearInterpolatorFactory())

# Define a rotation by +30 degrees relative to the image center in the XY axes
angle = radians(32 + 90)
toCenter = AffineTransform3D()
cx = img.dimension(0) / 2.0  # X axis
cy = img.dimension(1) / 2.0  # Y axis
toCenter.setTranslation(-cx, -cy, 0.0)  # no translation in the Z axis