Exemple #1
0
from net.imglib2.img.display.imagej import ImageJFunctions as IL
from net.imglib2.img.array import ArrayImg
from net.imglib2.img.basictypeaccess import ByteAccess
from net.imglib2.type.numeric.integer import UnsignedByteType
from math import sin, cos, pi

# Example 1: a virtual blank image. No pixel array backing.
t = UnsignedByteType()
img = ArrayImg(
    type('ConstantValue', (ByteAccess, ), {
        'getValue': lambda self, index: 255
    })(), [512, 512], t.getEntitiesPerPixel())
img.setLinkedType(t.getNativeTypeFactory().createLinkedType(img))

#IL.wrap(img, "white").show()


# Example 1b: a virtual blank image, with the ByteAccess unpacked into a class
class ConstantValue(ByteAccess):
    def __init__(self, value):
        self.value = value

    def getValue(self, index):
        return self.value

    def setValue(self, index, value):
        pass


t = UnsignedByteType()
data = ConstantValue(255)
        # Obtain 2D coordinates and map into the span range, normalized into the [0, 1] range
        # (which will be used as the linearized 2*pi length of the circumference)
        x = (index % self.diameter) / self.diameter
        y = (index / self.diameter) / self.diameter
        # Start at 2, with each sin or cos adding from -1 to +1 each, then normalize and expand into 8-bit range
        # (subtract -0.25 to center the white peak)
        return int((2 + sin((x - 0.25) * 2 * pi) + sin(
            (y - 0.25) * 2 * pi)) / 4.0 * 255)

    def setValue(self, index, value):
        pass


# Define the dimensions of the repeat
dimensions = [64, 64]
data = Sinusoid(dimensions[0])

# Construct an 8-bit image
t = UnsignedByteType()
img = ArrayImg(data, dimensions, t.getEntitiesPerPixel())
img.setLinkedType(t.getNativeTypeFactory().createLinkedType(img))

# Define the number of repeats
n_copies = 12
imgMirrored = Views.extendMirrorSingle(img)
imgMosaic = Views.interval(
    imgMirrored, [0, 0],
    [d * n_copies - n_copies
     for d in dimensions])  # subtracts n_copies to correct for mirror single

IL.wrap(imgMosaic, "sinusoid").show()