/** * This has to be overwritten, otherwise two different instances exist (one in the imageplus, one in the mirror) */ @Override public void setPlane( final int no, final FloatArray plane ) { System.arraycopy( plane.getCurrentStorageArray(), 0, mirror.get( no ).getCurrentStorageArray(), 0, plane.getCurrentStorageArray().length ); }
@Override protected DataBufferFloat createDataBuffer( final FloatArray data ) { final float[] sourceArray = data.getCurrentStorageArray(); return new DataBufferFloat( sourceArray, sourceArray.length ); }
@Override public void mutate(final ArrayImg<FloatType, FloatArray> arg) { final float[] data = arg.update(null).getCurrentStorageArray(); for (int i = 0; i < data.length; i++) { data[i] -= value; } }
@Override public void mutate(final ArrayImg<FloatType, FloatArray> arg) { final float[] data = arg.update(null).getCurrentStorageArray(); for (int i = 0; i < data.length; i++) { data[i] += value; } }
@Override public void mutate(final ArrayImg<FloatType, FloatArray> arg) { final float[] data = arg.update(null).getCurrentStorageArray(); for (int i = 0; i < data.length; i++) { data[i] *= value; } }
@Override public void mutate(final ArrayImg<FloatType, FloatArray> arg) { final float[] data = arg.update(null).getCurrentStorageArray(); for (int i = 0; i < data.length; i++) { data[i] /= value; } }
@Override protected DataBufferFloat createDataBuffer( final FloatArray data ) { final float[] sourceArray = data.getCurrentStorageArray(); return new DataBufferFloat( sourceArray, sourceArray.length ); }
@Override public void mutate(final PlanarImg<FloatType, FloatArray> arg) { long planeCount = 1; for (int d = 2; d < arg.numDimensions(); d++) { planeCount *= arg.dimension(d); } for (int p = 0; p < planeCount; p++) { final float[] plane = arg.getPlane(p).getCurrentStorageArray(); for (int i = 0; i < plane.length; i++) { plane[i] += value; } } }
@Override public void mutate(final PlanarImg<FloatType, FloatArray> arg) { long planeCount = 1; for (int d = 2; d < arg.numDimensions(); d++) { planeCount *= arg.dimension(d); } for (int p = 0; p < planeCount; p++) { final float[] plane = arg.getPlane(p).getCurrentStorageArray(); for (int i = 0; i < plane.length; i++) { plane[i] -= value; } } }
@Override public void mutate(final PlanarImg<FloatType, FloatArray> arg) { long planeCount = 1; for (int d = 2; d < arg.numDimensions(); d++) { planeCount *= arg.dimension(d); } for (int p = 0; p < planeCount; p++) { final float[] plane = arg.getPlane(p).getCurrentStorageArray(); for (int i = 0; i < plane.length; i++) { plane[i] /= value; } } }
@Override public void mutate(final PlanarImg<FloatType, FloatArray> arg) { long planeCount = 1; for (int d = 2; d < arg.numDimensions(); d++) { planeCount *= arg.dimension(d); } for (int p = 0; p < planeCount; p++) { final float[] plane = arg.getPlane(p).getCurrentStorageArray(); for (int i = 0; i < plane.length; i++) { plane[i] *= value; } } }
@Override public void mutate(final ArrayImg<FloatType, FloatArray> arg) { final float[] data = arg.update(null).getCurrentStorageArray(); ops().run(ChunkerOp.class, new Chunk() { @Override public void execute(final long startIndex, final long stepSize, final long numSteps) { final int startIndexSafe32 = (startIndex==0) ? 0 : ArrayUtils.safeMultiply32(startIndex); final int stepSizeSafe32 = (stepSize==0) ? 0 : ArrayUtils.safeMultiply32(stepSize); if (stepSizeSafe32 != 1) { for (int i = startIndexSafe32, j = 0; j < numSteps; i = i + stepSizeSafe32, j++) { data[i] -= value; } } else { for (int i = startIndexSafe32; i < startIndex + numSteps; i++) { data[i] -= value; } } } }, data.length); }
@Override public void mutate(final ArrayImg<FloatType, FloatArray> arg) { final float[] data = arg.update(null).getCurrentStorageArray(); ops().run(ChunkerOp.class, new Chunk() { @Override public void execute(final long startIndex, final long stepSize, final long numSteps) { final int startIndexSafe32 = (startIndex==0) ? 0 : ArrayUtils.safeMultiply32(startIndex); final int stepSizeSafe32 = (stepSize==0) ? 0 : ArrayUtils.safeMultiply32(stepSize); if (stepSizeSafe32 != 1) { for (int i = startIndexSafe32, j = 0; j < numSteps; i = i + stepSizeSafe32, j++) { data[i] *= value; } } else { for (int i = startIndexSafe32; i < startIndex + numSteps; i++) { data[i] *= value; } } } }, data.length); }
@Override public void mutate(final ArrayImg<FloatType, FloatArray> arg) { final float[] data = arg.update(null).getCurrentStorageArray(); ops().run(ChunkerOp.class, new Chunk() { @Override public void execute(final long startIndex, final long stepSize, final long numSteps) { final int startIndexSafe32 = (startIndex==0) ? 0 : ArrayUtils.safeMultiply32(startIndex); final int stepSizeSafe32 = (stepSize==0) ? 0 : ArrayUtils.safeMultiply32(stepSize); if (stepSizeSafe32 != 1) { for (int i = startIndexSafe32, j = 0; j < numSteps; i = i + stepSizeSafe32, j++) { data[i] += value; } } else { for (int i = startIndexSafe32; i < startIndex + numSteps; i++) { data[i] += value; } } } }, data.length); }
@Override public void mutate(final ArrayImg<FloatType, FloatArray> arg) { final float[] data = arg.update(null).getCurrentStorageArray(); ops().run(ChunkerOp.class, new Chunk() { @Override public void execute(final long startIndex, final long stepSize, final long numSteps) { final int startIndexSafe32 = (startIndex==0) ? 0 : ArrayUtils.safeMultiply32(startIndex); final int stepSizeSafe32 = (stepSize==0) ? 0 : ArrayUtils.safeMultiply32(stepSize); if (stepSizeSafe32 != 1) { for (int i = startIndexSafe32, j = 0; j < numSteps; i = i + stepSizeSafe32, j++) { data[i] /= value; } } else { for (int i = startIndexSafe32; i < startIndex + numSteps; i++) { data[i] /= value; } } } }, data.length); }
public void convolve1( final RandomAccessibleInterval< FloatType > psi, final ArrayImg< FloatType, ? > kernel1, final ArrayImg< FloatType, ? > tmp1 ) { // copy psi onto tmp1 FusionTools.copyImg( psi, tmp1, service, false ); final float[] blockF = ((FloatArray)(tmp1).update( null ) ).getCurrentStorageArray(); final float[] kernel1F = ((FloatArray)(kernel1).update( null ) ).getCurrentStorageArray(); // in-place CUDA convolution of tmp1 with kernel1 using CUDA long time = System.currentTimeMillis(); cuda.convolution3DfftCUDAInPlace( blockF, CUDATools.getCUDACoordinates( CUDAOutput.getImgSizeInt( tmp1 ) ), kernel1F, CUDATools.getCUDACoordinates( CUDAOutput.getImgSizeInt( kernel1 ) ), cudaDevice.getDeviceId() ); System.out.println( " block " + getId() + "(CUDA " + cudaDevice.getDeviceId() + "): compute " + (System.currentTimeMillis() - time) ); }
public void convolve2( final ArrayImg< FloatType, ? > tmp1, final ArrayImg< FloatType, ? > kernel2, final ArrayImg< FloatType, ? > tmp2 ) { // copy tmp1 onto tmp2 FusionTools.copyImg( tmp1, tmp2, service, false ); final float[] blockF = ((FloatArray)(tmp2).update( null ) ).getCurrentStorageArray(); final float[] kernel2F = ((FloatArray)(kernel2).update( null ) ).getCurrentStorageArray(); // in-place CUDA convolution of tmp2 with kernel2 using CUDA cuda.convolution3DfftCUDAInPlace( blockF, CUDATools.getCUDACoordinates( CUDAOutput.getImgSizeInt( tmp2 ) ), kernel2F, CUDATools.getCUDACoordinates( CUDAOutput.getImgSizeInt( kernel2 ) ), cudaDevice.getDeviceId() ); } }
@Override public void convertBytes(final FloatArray data, final byte[] bytes, final int planesRead) { final ImageMetadata iMeta = reader().getMetadata().get(0); if (isCompatible()) { final int bpp = getBitsPerElement() / 8; final int offset = planesRead * (bytes.length / bpp); final ByteBuffer bb = ByteBuffer.wrap(bytes); bb.order(iMeta.isLittleEndian() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); bb.asFloatBuffer().get(data.getCurrentStorageArray(), offset, bytes.length / bpp); } else { final int pixelType = iMeta.getPixelType(); final int bpp = FormatTools.getBytesPerPixel(pixelType); final int offset = planesRead * (bytes.length / bpp); for (int index = 0; index < bytes.length / bpp; index++) { final float value = (float) utils().decodeWord(bytes, index * bpp, pixelType, iMeta.isLittleEndian()); data.setValue(offset + index, value); } } }
@Override public void convertBytes(final FloatArray data, final byte[] bytes, final int planesRead) { final ImageMetadata iMeta = reader().getMetadata().get(0); if (isCompatible()) { final int bpp = getBitsPerElement() / 8; final int offset = planesRead * (bytes.length / bpp); final ByteBuffer bb = ByteBuffer.wrap(bytes); bb.order(iMeta.isLittleEndian() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN); bb.asFloatBuffer().get(data.getCurrentStorageArray(), offset, bytes.length / bpp); } else { final int pixelType = iMeta.getPixelType(); final int bpp = FormatTools.getBytesPerPixel(pixelType); final int offset = planesRead * (bytes.length / bpp); for (int index = 0; index < bytes.length / bpp; index++) { final float value = (float) utils().decodeWord(bytes, index * bpp, pixelType, iMeta.isLittleEndian()); data.setValue(offset + index, value); } } }
@Override @Before public void setUp() { super.setUp(); // make a random float array image img = generateFloatArrayTestImg(true, 100, 100); // get direct access to the float array array = img.update(null).getCurrentStorageArray(); arraySize = 1; for (int d = 0; d < img.numDimensions(); d++) arraySize *= img.dimension(d); randomlyFilledImg = generateRandomlyFilledUnsignedByteTestImgWithSeed( new long[] { 100, 100 }, 1234567890L); }