本文整理汇总了Java中net.imglib2.img.Img.dimensions方法的典型用法代码示例。如果您正苦于以下问题:Java Img.dimensions方法的具体用法?Java Img.dimensions怎么用?Java Img.dimensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.img.Img
的用法示例。
在下文中一共展示了Img.dimensions方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HWatershedLabeling
import net.imglib2.img.Img; //导入方法依赖的package包/类
public HWatershedLabeling(Img<T> input, float threshold, Connectivity connectivity)
{
int nDims = input.numDimensions();
long[] dims = new long[nDims];
input.dimensions(dims);
ImgFactory<IntType> imgFactoryIntType=null;
try {
imgFactoryIntType = input.factory().imgFactory( new IntType() );
} catch (IncompatibleTypeException e) {
e.printStackTrace();
}
if ( imgFactoryIntType != null )
{
this.labelMapMaxTree = imgFactoryIntType.create(dims, new IntType(0));
Cursor<IntType> c_label = labelMapMaxTree.cursor();
Cursor<T> c_input = input.cursor();
while( c_input.hasNext() )
{
c_label.next().setInteger( (int) c_input.next().getRealFloat() );
}
}
this.threshold = threshold;
this.connectivity = connectivity;
}
示例2: main
import net.imglib2.img.Img; //导入方法依赖的package包/类
public static void main( final String[] args ) throws ImgIOException
{
final String fn = "/home/tobias/workspace/data/DrosophilaWing.tif";
final Img< FloatType > img = new ImgOpener().openImg( fn, new ArrayImgFactory< FloatType >(), new FloatType() );
final long[] dims = new long[ img.numDimensions() ];
img.dimensions( dims );
final Img< FloatType > convolved = ArrayImgs.floats( dims );
try
{
Gauss3.gauss( 3, Views.extendMirrorSingle( img ), convolved );
// Gauss3.gauss( 5, img, Views.interval( convolved, Intervals.createMinSize( 200, 100, 200, 150 ) ) );
}
catch ( final IncompatibleTypeException e )
{
e.printStackTrace();
}
ImageJFunctions.show( convolved );
}
示例3: testOutput
import net.imglib2.img.Img; //导入方法依赖的package包/类
/** Test basic properties of the op's output */
@Test
public void testOutput() throws Exception {
// SETUP
final long[] inputDims = { 3, 3, 3 };
final Img<BitType> img = ArrayImgs.bits(inputDims);
// EXECUTE
final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
Boolean.TRUE);
// VERIFY
assertNotNull(result);
final long[] outputDims = new long[result.numDimensions()];
result.dimensions(outputDims);
assertArrayEquals(inputDims, outputDims);
}
示例4: upsample
import net.imglib2.img.Img; //导入方法依赖的package包/类
public static <T extends RealType<T> & NativeType<T>> Img<T> upsample(Img<T> input, float[] upsampling_factor, Interpolator interpType)
{
int nDim = input.numDimensions();
long[] dims = new long[nDim];
input.dimensions(dims);
long[] out_size = new long[nDim];
for(int i=0; i<nDim; i++)
out_size[i] = (long) ( (float)dims[i] * upsampling_factor[i] );
return upsample( input, out_size, interpType);
}
示例5: validateFormat
import net.imglib2.img.Img; //导入方法依赖的package包/类
private void validateFormat(final Img<T> image) throws IOException {
final int ndims = image.numDimensions();
if (ndims != 2) {
final long[] dims = new long[ndims];
image.dimensions(dims);
throw new IOException("Can only process 2D images, not an image with " +
ndims + " dimensions (" + Arrays.toString(dims) + ")");
}
if (!(image.firstElement() instanceof UnsignedShortType)) {
throw new IOException("Can only process uint16 images. " +
"Please convert your image first via Image > Type > 16-bit.");
}
}
示例6: scaleMatrix
import net.imglib2.img.Img; //导入方法依赖的package包/类
private static Img< DoubleType > scaleMatrix( final Img< DoubleType > matrix, final double[] scalingFactors )
{
final long[] dim = new long[ matrix.numDimensions() ];
matrix.dimensions( dim );
final Img< DoubleType > scaledMatrix = matrix.factory().create( dim, matrix.firstElement().createVariable() );
for ( Cursor< DoubleType > m = matrix.cursor(), s = scaledMatrix.cursor(); s.hasNext(); )
{
m.fwd();
s.fwd();
s.get().set( scalingFactors[ m.getIntPosition( 0 ) ] * scalingFactors[ m.getIntPosition( 1 ) ] * m.get().get() );
}
return scaledMatrix;
}
示例7: main
import net.imglib2.img.Img; //导入方法依赖的package包/类
public static void main( String[] args )
{
new ImageJ();
// test blending
ImgFactory< FloatType > f = new ArrayImgFactory< FloatType >();
Img< FloatType > img = f.create( new int[] { 400, 400 }, new FloatType() );
Cursor< FloatType > c = img.localizingCursor();
final int numDimensions = img.numDimensions();
final double[] tmp = new double[ numDimensions ];
// for blending
final long[] dimensions = new long[ numDimensions ];
img.dimensions( dimensions );
final float percentScaling = 0.2f;
final double[] border = new double[ numDimensions ];
while ( c.hasNext() )
{
c.fwd();
for ( int d = 0; d < numDimensions; ++d )
tmp[ d ] = c.getFloatPosition( d );
c.get().set( (float)BlendingPixelFusion.computeWeight( tmp, dimensions, border, percentScaling ) );
}
ImageJFunctions.show( img );
Log.debug( "done" );
}
示例8: thresholdImage
import net.imglib2.img.Img; //导入方法依赖的package包/类
public Img<UnsignedByteType> thresholdImage(Img<T> img, double thresholdValue)
{
// Create an instance of an image factory
ImgFactory< UnsignedByteType > imgFactory = new ArrayImgFactory< UnsignedByteType >();
long[] dim = new long[2];
img.dimensions(dim);
// Create an Img with the same dimension as the input image
final Img< UnsignedByteType > tmpImage = imgFactory.create( dim, new UnsignedByteType() );
// Create a cursor for both images
Cursor<T> c1 = img.cursor();
Cursor<UnsignedByteType> c2 = tmpImage.cursor();
// do for all pixels
while ( c1.hasNext() )
{
// get value of both imgs
RealType t1 = c1.next();
RealType t2 = c2.next();
// overwrite img1 with the result
if(t1.getRealFloat() > thresholdValue)
{
t2.setReal(255);
}
else
{
t2.setReal(0);
}
}
return tmpImage;
}
示例9: regressionTest
import net.imglib2.img.Img; //导入方法依赖的package包/类
@Test
public void regressionTest() throws Exception {
// load in input image and expected output image.
Img<FloatType> inputImg = (Img<FloatType>) ops.run(
net.imagej.ops.image.equation.DefaultEquation.class,
"Math.tan(0.3*p[0]) + Math.tan(0.1*p[1])");
Img<FloatType> expectedOutput = ((Img<FloatType>) openFloatImg(
"Result.tif"));
// create ouput image
long[] dims = new long[inputImg.numDimensions()];
inputImg.dimensions(dims);
Img<FloatType> actualOutput = ArrayImgs.floats(dims);
// scale over which the filter operates (sensitivity)
int scale = 1;
// physical spacing between data points (1,1 since I got it from the
// computer)
double[] spacing = { 1, 1 };
// run the op
ops.run(net.imagej.ops.filter.vesselness.DefaultFrangi.class, actualOutput,
inputImg, spacing, scale);
// compare the output image data to that stored in the file.
Cursor<FloatType> cursor = Views.iterable(actualOutput).localizingCursor();
RandomAccess<FloatType> actualRA = actualOutput.randomAccess();
RandomAccess<FloatType> expectedRA = expectedOutput.randomAccess();
while (cursor.hasNext()) {
cursor.fwd();
actualRA.setPosition(cursor);
expectedRA.setPosition(cursor);
assertEquals(expectedRA.get().get(), actualRA.get().get(), 0);
}
}
示例10: generateRandomImageStack
import net.imglib2.img.Img; //导入方法依赖的package包/类
/**
* To randomize blockwise we enumerate the blocks, shuffle that list and
* write the data to their new position based on the shuffled list.
*/
protected Img<T> generateRandomImageStack(Img<T> img, int[] blockDimensions) {
int numberOfDimensions = Math.min(img.numDimensions(), blockDimensions.length);
int numberOfBlocks = 0;
long[] numberOfBlocksPerDimension = new long[numberOfDimensions];
for (int i = 0 ; i<numberOfDimensions; i++){
if (img.dimension(i) % blockDimensions[i] != 0){
System.out.println("sorry, for now image dims must be divisable by block size");
return null;
}
numberOfBlocksPerDimension[i] = img.dimension(i) / blockDimensions[i];
numberOfBlocks *= numberOfBlocksPerDimension[i];
}
List<Integer> allTheBlocks = new ArrayList<Integer>(numberOfBlocks);
for (int i = 0; i<numberOfBlocks; i++){
allTheBlocks.add(new Integer(i));
}
Collections.shuffle(allTheBlocks, new Random());
Cursor<T> cursor = img.cursor();
// create factories for new image stack
//ContainerFactory containerFactory = new ImagePlusContainerFactory();
ImgFactory<T> imgFactory = new ArrayImgFactory<T>();
//new ImageFactory<T>(cursor.getType(), containerFactory);
// create a new stack for the random images
final long[] dim = new long[ img.numDimensions() ];
img.dimensions(dim);
Img<T> randomStack = imgFactory.create(dim, img.firstElement().createVariable());
// iterate over image data
while (cursor.hasNext()) {
cursor.fwd();
T type = cursor.get();
// type.getRealDouble();
}
return randomStack;
}
示例11: getLabelContour
import net.imglib2.img.Img; //导入方法依赖的package包/类
public static <T extends RealType<T> & NativeType<T>> Img<T> getLabelContour(Img<T> input, Connectivity connectivity)
{
int nDim = input.numDimensions();
long[] dims = new long[nDim];
input.dimensions(dims);
Img<T> output = input.factory().create(dims, input.firstElement().createVariable() );
//cursor on the extended input
//long[] minInt = new long[ nDim ], maxInt = new long[ nDim ];
//for ( int d = 0; d < nDim; ++d ){
// minInt[ d ] = 0 ;
// maxInt[ d ] = dims[d] - 1 ;
//}
//FinalInterval interval = new FinalInterval( minInt, maxInt );
RandomAccess<T> raIn = Views.extendMirrorSingle(input).randomAccess();
// random accessible on the ouput
RandomAccess<T> raOut = output.randomAccess();
// define the connectivity
long[][] neigh = ImageConnectivity.getConnectivityPos(nDim, connectivity.getConn() );
int[] n_offset = ImageConnectivity.getIdxOffsetToCenterPix(neigh, dims);
long[][] dPosList = ImageConnectivity.getSuccessiveMove(neigh);
int nNeigh = n_offset.length;
// browse through the image
for(long idx=0; idx<input.size(); idx++){
final long[] pos = new long[nDim];
getPosFromIdx( idx, pos, dims);
raIn.setPosition(pos);
float pVal = raIn.get().getRealFloat();
if( pVal > 0 ){
// loop on neighbors
for( int i =0; i<nNeigh; i++){
raIn.move(dPosList[i]);
float nVal = raIn.get().getRealFloat();
// if n different from p then update ouput value
if ( nVal != pVal ) {
raOut.setPosition(pos);
raOut.get().setReal(pVal);
break;
}
}
}
}
return output;
}
示例12: IntegralCursor
import net.imglib2.img.Img; //导入方法依赖的package包/类
public IntegralCursor(
final Img<T> integralImg,
final long[] radius)
{
super(integralImg.numDimensions());
this.integralImg = integralImg;
this.radius = radius;
this.sum = integralImg.firstElement().createVariable();
this.tmp = this.sum.createVariable();
this.packet = new ValuePair<T, long[]>(sum, new long[1]);
this.cellMinPositions = new long[integralImg.numDimensions()];
this.cellMaxPositions = new long[integralImg.numDimensions()];
// Establish the dimensions where this Cursor/RandomAccess is defined:
this.dimensions = new long[integralImg.numDimensions()];
integralImg.dimensions(this.dimensions);
// Compute the size of the underlying, original image from which the integralHistogram was computed:
this.lastIndex = integralImg.size() - 1;
// Set starting index at -1
reset();
// Instead, I have to send the coords back to the nearest existing within the domain.
this.ra = this.integralImg.randomAccess();
// N-dimensional corner coordinates, relative to any one pixel location
this.offsets = new Point[(int)Math.pow(2, numDimensions())];
for (int i=0; i<offsets.length; ++i) {
offsets[i] = new Point(numDimensions());
}
int d = 0;
while (d < numDimensions()) {
final int flip = (int)Math.pow(2, d);
int sign = -1;
for (int i=0; i<offsets.length;) {
long delta = radius[d];
// increasing is inclusive, but decreasing is exclusive. This way, a radius of zero also works.
offsets[i].setPosition(sign * delta + (-1 == sign ? -1 : 0), d);
++i; // done before flipping sign, so coords will be (almost) in order
if (0 == i % flip) sign *= -1;
}
++d;
}
// Compute the sign of each corner
this.signs = new int[offsets.length];
for (int o=0; o<offsets.length; ++o) {
// Count the number of negative signs
signs[o] = 0;
for (d=0; d<numDimensions(); ++d) {
signs[o] += offsets[o].getLongPosition(d) < 0 ? 1 : 0;
}
// Set the proper sign
signs[o] = signs[o] % 2 != 0 ? -1 : 1;
}
}