本文整理汇总了Java中net.imglib2.img.Img.size方法的典型用法代码示例。如果您正苦于以下问题:Java Img.size方法的具体用法?Java Img.size怎么用?Java Img.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.img.Img
的用法示例。
在下文中一共展示了Img.size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeSmallestType
import net.imglib2.img.Img; //导入方法依赖的package包/类
/**
* Determine the smallest type that will correctly store the sums.
* For {@link Img} whose type has integer precision, the largest type is {@link LongType}.
* For {@link Img} whose type has floating-point precision, the largest type is {@link DoubleType}.
*
* @param img The input {@link Img}.
* @return
*/
static public final <R extends RealType<R>, T extends NativeType<T> & NumericType<T>> T computeSmallestType(final Img<R> img) {
final R type = img.firstElement();
final long maxSum = (long) (img.size() * (Math.pow(2, type.getBitsPerPixel()) -1));
T smallest = chooseSmallestType(type, maxSum);
if (null != smallest) return smallest;
// Else, slow way: sum all values and determine the smallest type
final RealSum sum = new RealSum();
for (final R r : img) sum.add(r.getRealDouble());
smallest = chooseSmallestType(type, sum.getSum());
if (null != smallest) return smallest;
throw new UnsupportedOperationException("Target image is too large!");
}
示例2: create
import net.imglib2.img.Img; //导入方法依赖的package包/类
static public <T extends RealType<T>, R extends IntegerType<R> & NativeType<R>> Img<R> create(
final Img<T> img,
final Histogram<T> histogram,
final R type)
{
// Sanity check
if (Math.pow(2, type.getBitsPerPixel() / type.getEntitiesPerPixel().getRatio()) < img.size()) {
throw new RuntimeException("Cannot write histogram with type " + type.getClass());
}
// Dimensions of integral image: one more than the input img, and +1 element in the image dimensions
final long[] dims = new long[img.numDimensions() + 1];
for (int i=0; i<img.numDimensions(); ++i) {
dims[i] = img.dimension(i) + 1;
}
dims[dims.length -1] = histogram.nBins();
// Create an image to hold the integral histogram
final Img<R> integralHistogram = type.createSuitableNativeImg(new ArrayImgFactory<R>(), dims);
switch ( img.numDimensions() ) {
case 1:
populate1( integralHistogram, img, histogram );
break;
case 2:
populate2( integralHistogram, img, histogram );
break;
default:
populateND(integralHistogram, img, histogram);
break;
}
return integralHistogram;
}
示例3: process
import net.imglib2.img.Img; //导入方法依赖的package包/类
@SuppressWarnings("boxing")
static private final <R extends RealType<R>> double process(final TreeMap<Double,Long> map, final Img<R> img, final int nBins, final double min, final double max) throws Exception {
final double range = max - min;
final double increment = range / nBins;
final long[] bins = new long[nBins];
//
if (0.0 == range) {
bins[0] = img.size();
} else {
final Cursor<R> c = img.cursor();
// zero-based:
final int N = nBins -1;
// Analyze the image
while (c.hasNext()) {
c.fwd();
int v = (int)(((c.get().getRealDouble() - min) / range) * N);
if (v < 0) v = 0;
else if (v > N) v = N;
bins[v] += 1;
}
}
// Put the contents of the bins into the map
for (int i=0; i<bins.length; i++) {
map.put( min + i * increment, bins[i] );
}
return increment;
}
示例4: 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;
}
示例5: 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;
}
}
示例6: RegionMean
import net.imglib2.img.Img; //导入方法依赖的package包/类
public RegionMean(Img<T> img, RandomAccess<T> ra, long span) {
super(img, ra, span);
this.size = img.size();
}