Exemplo n.º 1
0
class ViewFloatProcessor(FloatProcessor):
    """
  A 2D FloatProcessor whose float[] pixel array is populated from the pixels within
  an interval on a source 3D RandomAccessibleInterval at a specified indexZ (the section index).
  The interval and indexZ are editable via the translate method.
  """
    def __init__(self, img3D, interval2D, indexZ):
        self.img3D = img3D
        self.interval2D = interval2D
        self.indexZ = indexZ
        super(FloatProcessor, self).__init__(interval2D.dimension(0),
                                             interval2D.dimension(1))
        self.updatePixels()

    def translate(self, dx, dy, dz):
        # Z within bounds
        self.indexZ += dz
        self.indexZ = min(self.img3D.dimension(2) - 1, max(0, self.indexZ))
        # X, Y can be beyond bounds
        self.interval2D = FinalInterval(
            [self.interval2D.min(0) + dx,
             self.interval2D.min(1) + dy],
            [self.interval2D.max(0) + dx,
             self.interval2D.max(1) + dy])
        self.updatePixels()
        return self.interval2D.min(0), self.interval2D.min(1), self.indexZ

    def updatePixels(self):
        # Copy interval into pixels
        view = Views.interval(
            Views.extendZero(Views.hyperSlice(self.img3D, 2, self.indexZ)),
            self.interval2D)
        aimg = ArrayImgs.floats(
            self.getPixels(),
            [self.interval2D.dimension(0),
             self.interval2D.dimension(1)])
        ImgUtil.copy(view, aimg)
Exemplo n.º 2
0
from net.imglib2.img.array import ArrayImgs
from net.imglib2.util import Intervals, ImgUtil
from net.imglib2.interpolation.randomaccess import NLinearInterpolatorFactory

img1 = Views.dropSingletonDimensions(IL.wrap(imp))
transform = AffineTransform2D()
transform.set(scale, 0, 0, 0, scale, 0)

# Origins and dimensions (hence, interval) of the target image
interval2 = FinalInterval([
    int(img1.dimension(0) * scale),
    int(img1.dimension(1) * scale),
    img1.dimension(2)
])
# Interval of a single stack slice of the target image
sliceInterval = FinalInterval([interval2.dimension(0), interval2.dimension(1)])

slices2 = []
for index in xrange(img1.dimension(2)):
    # One single 2D RGB slice
    imgSlice1 = Views.hyperSlice(img1, 2, index)
    # Views of the 3 color channels, as extended and interpolatable
    channels = [
        Views.interpolate(
            Views.extendZero(Converters.argbChannel(imgSlice1, i)),
            NLinearInterpolatorFactory()) for i in [1, 2, 3]
    ]
    # ARGBType 2D view of the transformed color channels
    imgSlice2 = Converters.mergeARGB(
        Views.stack(
            Views.interval(RealViews.transform(channel, transform),