Пример #1
0
from net.imglib2.img.display.imagej import ImageJFunctions as IL
from net.imglib2.view import Views
from ij import IJ, ImagePlus

# Fetch an RGB image stack (or any RGB image with more than 1 dimension)
imp_rgb = IJ.getImage(
)  # IJ.openImage("http://imagej.nih.gov/ij/images/flybrain.zip")

img = IL.wrap(imp_rgb)  # an ARGBType Img
red = Converters.argbChannel(img, 1)  # a view of the ARGB red channel

# Project the last dimension using the max function
last_d = red.numDimensions() - 1
op = maximum(
    [Views.hyperSlice(red, last_d, i) for i in xrange(red.dimension(last_d))])
img_max_red = compute(op).intoArrayImg()

IL.wrap(img_max_red, "max projection of the red channel)").show()

# Now project all 3 color channels and compose an RGB image
last_dim_index = img.numDimensions() - 1
channel_stacks = [[
    Views.hyperSlice(Converters.argbChannel(img, channel_index),
                     last_dim_index, slice_index)
    for slice_index in xrange(img.dimension(last_dim_index))
] for channel_index in [1, 2, 3]]  # 1: red, 2: green, 3: blue

channels = Views.stack([maximum(cs).view() for cs in channel_stacks])
max_rgb = Converters.mergeARGB(channels, ColorChannelOrder.RGB)

IL.wrap(max_rgb, "max RGB").show()
Пример #2
0
from net.imglib2.img.array import ArrayImgs
from net.imglib2.img.display.imagej import ImageJFunctions as IL
from net.imglib2.view import Views

# Fetch an RGB image stack
imp_rgb = IJ.getImage(
)  # IJ.openImage("http://imagej.nih.gov/ij/images/flybrain.zip")

img = IL.wrap(imp_rgb)  # an ARGBType Img
# Color channel views
red, green, blue = (Converters.argbChannel(img, c) for c in [1, 2, 3])

# ImgLib1 scripting gamma function
# return Min(255, Max(0, Multiply(Exp(Multiply(gamma, Log(Divide(channel, 255)))), 255)))

gamma = 0.5


def op(channel):
    return minimum(
        255, maximum(0, mul(exp(mul(gamma, log(div(channel, 255)))), 255)))


img_gamma = Converters.mergeARGB(
    Views.stack(
        op(red).viewDouble(),
        op(green).viewDouble(),
        op(blue).viewDouble()), ColorChannelOrder.RGB)

IL.wrap(img_gamma, "gamma 0.5").show()
Пример #3
0
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),
                           sliceInterval)
            for channel in channels), ColorChannelOrder.RGB)
    slices2.append(imgSlice2)

# Transformed view
viewImg2 = Views.stack(slices2)
# Materialized image
img2 = ArrayImgs.argbs(Intervals.dimensionsAsLongArray(interval2))
ImgUtil.copy(viewImg2, img2)

imp4 = IL.wrap(img2, "imglib2-transformed RGB (pull)")
imp4.show()

# Fourth approach: pull (CORRECT!), and much faster (delegates pixel-wise operations
# to java libraries and delegates RGB color handling altogether)