本文整理汇总了Java中net.imglib2.img.array.ArrayImgs.unsignedBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayImgs.unsignedBytes方法的具体用法?Java ArrayImgs.unsignedBytes怎么用?Java ArrayImgs.unsignedBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.img.array.ArrayImgs
的用法示例。
在下文中一共展示了ArrayImgs.unsignedBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: diskPlot2D
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* Plot the disks in 2D.
*/
public static void diskPlot2D( final String[] args )
{
ImageJ.main( args );
final long[] radiuses = new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
final int[] decomp = new int[] { 0, 4, 6, 8 };
final Img< UnsignedByteType > source = createSquarePointImage( 20, 2 );
for ( final int n : decomp )
{
final Img< UnsignedByteType > target = ArrayImgs.unsignedBytes( new long[] { 42, 42, radiuses.length } );
int rindex = 0;
for ( final long radius : radiuses )
{
final List< Shape > disc = StructuringElements.disk( radius, source.numDimensions(), n );
final Img< UnsignedByteType > out = Dilation.dilate( source, disc, 1 );
copyToSlice( out, target, rindex++ );
}
ImageJFunctions.show( target, "Decomp = " + n );
}
}
示例2: testDefaultASCII
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@Test
public void testDefaultASCII() {
// character set used in DefaultASCII, could be updated if necessary
final String CHARS = "#O*o+-,. ";
final int len = CHARS.length();
final int width = 10;
final int offset = 47;
final byte[] array = new byte[width * len];
for (int i = 0; i < len; i++) {
for (int j = 0; j < width; j++) {
array[i * width + j] = (byte) (offset + i * width + j);
}
}
final Img<UnsignedByteType> img = ArrayImgs.unsignedBytes(array, width,
len);
final String ascii = (String) ops.run(DefaultASCII.class, img);
for (int i = 0; i < len; i++) {
for (int j = 0; j < width; j++) {
assertTrue(ascii.charAt(i * (width + 1) + j) == CHARS.charAt(i));
}
assertTrue(ascii.charAt(i * (width + 1) + width) == '\n');
}
}
示例3: openAndClose
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
public static void openAndClose() {
final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(new long[] { 50, 50 });
final Random ran = new Random();
for (final UnsignedByteType pixel : img) {
if (ran.nextDouble() > 0.95)
pixel.set(255);
}
final Shape strel = new HyperSphereShape(3);
final Img< UnsignedByteType > open = Opening.open( img, strel, 4 );
final Img< UnsignedByteType > closed = Closing.close( img, strel, 4 );
new ImageJ();
ImageJFunctions.show(img);
ImageJFunctions.show(open);
ImageJFunctions.show(closed);
}
示例4: standardErode
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
public static void standardErode() {
final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(new long[] { 10, 9 });
for (final UnsignedByteType pixel : img) {
pixel.set(255);
}
final ArrayRandomAccess<UnsignedByteType> ra = img.randomAccess();
ra.setPosition(new int[] { 1, 4 });
ra.get().set(0);
final Shape strel = new CenteredRectangleShape(new int[] { 3, 2 }, false);
// final Shape strel = new HyperSphereShape(radius)
final Img< UnsignedByteType > full = Erosion.erodeFull( img, strel, 4 );
final Img< UnsignedByteType > std = Erosion.erode( img, strel, 4 );
new ImageJ();
ImageJFunctions.show(img);
ImageJFunctions.show(full);
ImageJFunctions.show(std);
}
示例5: standardDilate
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
public static void standardDilate() {
final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(new long[] { 3, 9 });
final ArrayRandomAccess<UnsignedByteType> ra = img.randomAccess();
ra.setPosition(new int[] { 1, 4 });
ra.get().set(255);
final Shape strel = new CenteredRectangleShape(new int[] { 5, 2 }, true);
// final Shape strel = new HyperSphereShape(radius)
final Img< UnsignedByteType > full = Dilation.dilateFull( img, strel, new UnsignedByteType( 0 ), 4 );
final Img< UnsignedByteType > std = Dilation.dilate( img, strel, new UnsignedByteType( 0 ), 4 );
new ImageJ();
ImageJFunctions.show(img);
ImageJFunctions.show(full);
ImageJFunctions.show(std);
}
示例6: mean
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* Apply mean filter with given size of reactangle shape
*
* @param input
* Input image
* @param i
* Size of rectangle shape
* @return Filered mean image
*/
@SuppressWarnings("unchecked")
private Img<I> mean(final RandomAccessibleInterval<I> input, final int i) {
long[] dims = new long[input.numDimensions()];
input.dimensions(dims);
final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(dims))];
Img<I> meanImg = (Img<I>) ArrayImgs.unsignedBytes(array, dims);
OutOfBoundsMirrorFactory<ByteType, Img<ByteType>> oobFactory = new OutOfBoundsMirrorFactory<>(
Boundary.SINGLE);
ops().run(MeanFilterOp.class, meanImg, input, new RectangleShape(i, true), oobFactory);
return meanImg;
}
示例7: getConstantUnsignedByteImg
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* @param dim a long array with the desired dimensions of the image
* @param constValue constant image value
* @return an {@link Img} of {@link UnsignedByteType} filled with a constant
* value.
*/
public Img<UnsignedByteType> getConstantUnsignedByteImg(final long[] dim,
final int constValue)
{
final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(
dim);
final UnsignedByteType type = img.firstElement();
if (constValue < type.getMinValue() || constValue >= type.getMaxValue()) {
throw new IllegalArgumentException("Can't create image for constant [" +
constValue + "]");
}
final ArrayCursor<UnsignedByteType> cursor = img.cursor();
while (cursor.hasNext()) {
cursor.next().set(constValue);
}
return img;
}
示例8: generateUnsignedByteImg
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
private static Img<UnsignedByteType> generateUnsignedByteImg(
final byte[] values)
{
final byte[] array =
new byte[(int) Intervals.numElements(new FinalInterval(dims))];
if (array.length != values.length) {
throw new RuntimeException("Number of values doesn't match dimmensions");
}
for (int i = 0; i < array.length; i++) {
array[i] = values[i];
}
return ArrayImgs.unsignedBytes(array, dims);
}
示例9: testDecompositionPerformance
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
public static final void testDecompositionPerformance( final String[] args )
{
ImageJ.main( args );
final ArrayImg< UnsignedByteType, ByteArray > img = ArrayImgs.unsignedBytes( 100, 100 );
final ArrayRandomAccess< UnsignedByteType > ra = img.randomAccess();
ra.setPosition( new long[] { 49, 49 } );
ra.get().set( 255 );
System.out.println( "time(ms)" );
System.out.println( "radius\tNo decomp.\t4 PL\t6 PL\t 8PL" );
// Warm up
Dilation.dilate( img, StructuringElements.disk( 1, img.numDimensions(), 0 ), 1 );
Dilation.dilate( img, StructuringElements.disk( 1, img.numDimensions(), 4 ), 1 );
Dilation.dilate( img, StructuringElements.disk( 1, img.numDimensions(), 6 ), 1 );
Dilation.dilate( img, StructuringElements.disk( 1, img.numDimensions(), 8 ), 1 );
final int[] decomp = new int[] { 0, 4, 6, 8 };
for ( int i = 0; i < 40; i++ )
{
final int radius = i * 2 + 1;
System.out.print( "" + radius );
for ( final int dec : decomp )
{
final long start = System.currentTimeMillis();
final List< Shape > strels = StructuringElements.disk( radius, 2, dec );
Dilation.dilate( img, strels, 1 );
final long end = System.currentTimeMillis();
System.out.print( "\t" + ( end - start ) );
}
System.out.print( "\n" );
}
}
示例10: createSquarePointImage
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
private final static Img< UnsignedByteType > createSquarePointImage( final long radius, final int dim )
{
final long size = 2 * radius + 1;
final long[] sizes = new long[ dim ];
Arrays.fill( sizes, size );
final long[] middle = new long[ dim ];
Arrays.fill( middle, radius );
final ArrayImg< UnsignedByteType, ByteArray > img = ArrayImgs.unsignedBytes( sizes );
final ArrayRandomAccess< UnsignedByteType > ra = img.randomAccess();
ra.setPosition( middle );
ra.get().set( 255 );
return img;
}
示例11: main7
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* Tune optimized 3D cases
*
* @param args
*/
public static void main7( final String[] args )
{
ImageJ.main( args );
final ArrayImg< UnsignedByteType, ByteArray > img = ArrayImgs.unsignedBytes( 19, 19, 19 );
final ArrayRandomAccess< UnsignedByteType > ra = img.randomAccess();
ra.setPosition( new long[] { 9, 9, 9 } );
ra.get().set( 255 );
final long start = System.currentTimeMillis();
final List< Shape > strels = StructuringElements.diamond( 6, img.numDimensions(), true );
Img< UnsignedByteType > dilated = img;
for ( final Shape strel : strels )
{
final String str = MorphologyUtils.printNeighborhood( strel, img.numDimensions() );
System.out.println( str );
dilated = Dilation.dilate( dilated, strel, 1 );
ImageJFunctions.show( dilated, "Decomposed strel: " + strel );
}
final long end = System.currentTimeMillis();
System.out.println( "Optimized processing time: " + ( end - start ) + " ms." );
}
示例12: createImg
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
@BeforeClass
public static void createImg() {
Img<UnsignedByteType> tmp =
ArrayImgs.unsignedBytes(new long[] { 100, 100 });
Random rand = new Random(1234567890L);
final Cursor<UnsignedByteType> cursor = tmp.cursor();
while (cursor.hasNext()) {
cursor.next().set(rand.nextInt((int) tmp.firstElement().getMaxValue()));
}
img = tmp;
}
示例13: getRandomUnsignedByteImg
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* @param dim a long array with the desired dimensions of the image
* @return an {@link Img} of {@link UnsignedByteType} filled with random
* values.
*/
public Img<UnsignedByteType> getRandomUnsignedByteImg(final long[] dim) {
final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(
dim);
final UnsignedByteType type = img.firstElement();
final ArrayCursor<UnsignedByteType> cursor = img.cursor();
while (cursor.hasNext()) {
cursor.next().set(rand.nextInt((int) type.getMaxValue()));
}
return img;
}
示例14: getEllipsedBitImage
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
/**
* @param dim dimensions of the image
* @param radii of the ellipse
* @param offset of the ellipse
* @return an {@link Img} of {@link BitType} filled with a ellipse
*/
@SuppressWarnings({ "deprecation" })
public Img<UnsignedByteType> getEllipsedBitImage(final long[] dim,
final double[] radii, final double[] offset)
{
// create empty bittype image with desired dimensions
final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(
dim);
// create ellipse
final EllipseRegionOfInterest ellipse = new EllipseRegionOfInterest();
ellipse.setRadii(radii);
// set origin in the center of image
final double[] origin = new double[dim.length];
for (int i = 0; i < dim.length; i++)
origin[i] = dim[i] / 2;
ellipse.setOrigin(origin);
// get iterable intervall and cursor of ellipse
final IterableInterval<UnsignedByteType> ii = ellipse
.getIterableIntervalOverROI(img);
final Cursor<UnsignedByteType> cursor = ii.cursor();
// fill image with ellipse
while (cursor.hasNext()) {
cursor.next();
cursor.get().set(255);
}
return img;
}
示例15: generateUnsignedByteArrayTestImg
import net.imglib2.img.array.ArrayImgs; //导入方法依赖的package包/类
public ArrayImg<UnsignedByteType, ByteArray> generateUnsignedByteArrayTestImg(
final boolean fill, final long... dims)
{
final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(
dims))];
if (fill) {
seed = 17;
for (int i = 0; i < array.length; i++) {
array[i] = (byte) pseudoRandom();
}
}
return ArrayImgs.unsignedBytes(array, dims);
}