@Override public VolatileFloatArray loadArray( final int timepoint, final int setup, final int level, final int[] dimensions, final long[] min ) throws InterruptedException { final int channel = setup + 1; final int slice = ( int ) min[ 2 ] + 1; final int frame = timepoint + 1; final float[] data = ( float[] ) imp.getStack().getProcessor( imp.getStackIndex( channel, slice, frame ) ).getPixels(); return new VolatileFloatArray( data, true ); }
@Override public VolatileIntArray loadArray( final int timepoint, final int setup, final int level, final int[] dimensions, final long[] min ) throws InterruptedException { final int channel = setup + 1; final int slice = ( int ) min[ 2 ] + 1; final int frame = timepoint + 1; final int[] data = ( int[] ) imp.getStack().getProcessor( imp.getStackIndex( channel, slice, frame ) ).getPixels(); return new VolatileIntArray( data, true ); }
@Override public VolatileByteArray loadArray( final int timepoint, final int setup, final int level, final int[] dimensions, final long[] min ) throws InterruptedException { final int channel = setup + 1; final int slice = ( int ) min[ 2 ] + 1; final int frame = timepoint + 1; final byte[] data = ( byte[] ) imp.getStack().getProcessor( imp.getStackIndex( channel, slice, frame ) ).getPixels(); return new VolatileByteArray( data, true ); }
@Override public VolatileShortArray loadArray( final int timepoint, final int setup, final int level, final int[] dimensions, final long[] min ) throws InterruptedException { final int channel = setup + 1; final int slice = ( int ) min[ 2 ] + 1; final int frame = timepoint + 1; final short[] data = ( short[] ) imp.getStack().getProcessor( imp.getStackIndex( channel, slice, frame ) ).getPixels(); return new VolatileShortArray( data, true ); }
public FloatImagePlus( final ImagePlus imp ) { super( imp.getWidth(), imp.getHeight(), imp.getNSlices(), imp.getNFrames(), imp.getNChannels(), 1 ); this.imp = imp; mirror.clear(); for ( int t = 0; t < frames; ++t ) for ( int z = 0; z < depth; ++z ) for ( int c = 0; c < channels; ++c ) mirror.add( new FloatArray( ( float[] )imp.getStack().getProcessor( imp.getStackIndex( c + 1, z + 1 , t + 1 ) ).getPixels() ) ); }
public ByteImagePlus( final ImagePlus imp ) { super( imp.getWidth(), imp.getHeight(), imp.getNSlices(), imp.getNFrames(), imp.getNChannels(), 1 ); this.imp = imp; mirror.clear(); for ( int t = 0; t < frames; ++t ) for ( int z = 0; z < depth; ++z ) for ( int c = 0; c < channels; ++c ) mirror.add( new ByteArray( ( byte[] )imp.getStack().getProcessor( imp.getStackIndex( c + 1, z + 1 , t + 1 ) ).getPixels() ) ); }
public ShortImagePlus( final ImagePlus imp ) { super( imp.getWidth(), imp.getHeight(), imp.getNSlices(), imp.getNFrames(), imp.getNChannels(), 1 ); this.imp = imp; mirror.clear(); for ( int t = 0; t < frames; ++t ) for ( int z = 0; z < depth; ++z ) for ( int c = 0; c < channels; ++c ) mirror.add( new ShortArray( ( short[] )imp.getStack().getProcessor( imp.getStackIndex( c + 1, z + 1 , t + 1 ) ).getPixels() ) ); }
public IntImagePlus( final ImagePlus imp ) { super( imp.getWidth(), imp.getHeight(), imp.getNSlices(), imp.getNFrames(), imp.getNChannels(), 1 ); this.imp = imp; mirror.clear(); for ( int t = 0; t < frames; ++t ) for ( int z = 0; z < depth; ++z ) for ( int c = 0; c < channels; ++c ) mirror.add( new IntArray( ( int[] )imp.getStack().getProcessor( imp.getStackIndex( c + 1, z + 1 , t + 1 ) ).getPixels() ) ); }
public ShortImagePlus( final long[] dim, final int entitiesPerPixel ) { super( dim, entitiesPerPixel ); if ( entitiesPerPixel == 1 ) { final ImageStack stack = new ImageStack( width, height ); for ( int i = 0; i < numSlices; ++i ) stack.addSlice( "", new ShortProcessor( width, height ) ); imp = new ImagePlus( "image", stack ); imp.setDimensions( channels, depth, frames ); if ( numSlices > 1 ) imp.setOpenAsHyperStack( true ); mirror.clear(); for ( int t = 0; t < frames; ++t ) for ( int z = 0; z < depth; ++z ) for ( int c = 0; c < channels; ++c ) mirror.add( new ShortArray( ( short[] )imp.getStack().getProcessor( imp.getStackIndex( c + 1, z + 1 , t + 1 ) ).getPixels() ) ); } else { imp = null; mirror.clear(); for ( int i = 0; i < numSlices; ++i ) mirror.add( new ShortArray( width * height * entitiesPerPixel ) ); } }
public ByteImagePlus( final long[] dim, final int entitiesPerPixel ) { super( dim, entitiesPerPixel ); if ( entitiesPerPixel == 1 ) { final ImageStack stack = new ImageStack( width, height ); for ( int i = 0; i < numSlices; ++i ) stack.addSlice( "", new ByteProcessor( width, height ) ); imp = new ImagePlus( "image", stack ); imp.setDimensions( channels, depth, frames ); if ( numSlices > 1 ) imp.setOpenAsHyperStack( true ); mirror.clear(); for ( int t = 0; t < frames; ++t ) for ( int z = 0; z < depth; ++z ) for ( int c = 0; c < channels; ++c ) mirror.add( new ByteArray( ( byte[] )imp.getStack().getProcessor( imp.getStackIndex( c + 1, z + 1 , t + 1 ) ).getPixels() ) ); } else { imp = null; mirror.clear(); for ( int i = 0; i < numSlices; ++i ) mirror.add( new ByteArray( width * height * entitiesPerPixel ) ); } }
private static ImageStack getVolume(ImagePlus imp, int c, int t) { ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight()); if (imp.getNSlices()==1) { for (t=1; t<=imp.getNFrames(); t++) { int n = imp.getStackIndex(c, 1, t); stack2.addSlice(stack1.getProcessor(n)); } } else { for (int z=1; z<=imp.getNSlices(); z++) { int n = imp.getStackIndex(c, z, t); stack2.addSlice(stack1.getProcessor(n)); } } return stack2; }
private static ImageStack getVolume(ImagePlus imp, int c, int t) { ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight()); if (imp.getNSlices()==1) { for (t=1; t<=imp.getNFrames(); t++) { int n = imp.getStackIndex(c, 1, t); stack2.addSlice(stack1.getProcessor(n)); } } else { for (int z=1; z<=imp.getNSlices(); z++) { int n = imp.getStackIndex(c, z, t); stack2.addSlice(stack1.getProcessor(n)); } } return stack2; }
public static float[] computeMinMax( final ImagePlus imp, final int channel ) { final int size = imp.getWidth() * imp.getHeight(); float min = Float.MAX_VALUE; float max = -Float.MAX_VALUE; IJ.log( "Computing min/max over " + imp.getNSlices() + " slices and " + imp.getNFrames() + " frames for channel " + channel ); for ( int z = 0; z < imp.getNSlices(); ++z ) for ( int t = 0; t < imp.getNFrames(); ++t ) { final ImageProcessor ip = imp.getStack().getProcessor( imp.getStackIndex( channel, z + 1, t + 1 ) ); for ( int i = 0; i < size; ++i ) { final float f = ip.getf( i ); min = Math.min( min, f ); max = Math.max( max, f ); } } return new float[]{ min, max }; }
/** Returns, as an ImageStack, the specified channel, where 'c' must be greater than zero and less than or equal to the number of channels in the image. */ public static ImageStack getChannel(ImagePlus imp, int c) { if (imp.getBitDepth()==24) { // RGB? if (c<1 || c>3) throw new IllegalArgumentException("Channel must be 1,2 or 3"); ImageStack[] channels = splitRGB(imp.getStack(), true); return channels[c-1]; } if (c<1 || c>imp.getNChannels()) throw new IllegalArgumentException("Channel less than 1 or greater than "+imp.getNChannels()); ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight()); for (int t=1; t<=imp.getNFrames(); t++) { for (int z=1; z<=imp.getNSlices(); z++) { int n = imp.getStackIndex(c, z, t); stack2.addSlice(stack1.getProcessor(n)); } } return stack2; }
/** Returns, as an ImageStack, the specified channel, where 'c' must be greater than zero and less than or equal to the number of channels in the image. */ public static ImageStack getChannel(ImagePlus imp, int c) { if (imp.getBitDepth()==24) { // RGB? if (c<1 || c>3) throw new IllegalArgumentException("Channel must be 1,2 or 3"); ImageStack[] channels = splitRGB(imp.getStack(), true); return channels[c-1]; } if (c<1 || c>imp.getNChannels()) throw new IllegalArgumentException("Channel less than 1 or greater than "+imp.getNChannels()); ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight()); for (int t=1; t<=imp.getNFrames(); t++) { for (int z=1; z<=imp.getNSlices(); z++) { int n = imp.getStackIndex(c, z, t); stack2.addSlice(stack1.getProcessor(n)); } } return stack2; }
public static ImagePlus focus(ImagePlus image, double radius, boolean showProgress) { int nSlices = image.getNSlices(); int nChannels = image.getNChannels(); int nFrames = image.getNFrames(); ImageStack stack = image.getStack(); ImageStack output = new ImageStack(image.getWidth(), image.getHeight()); for (int frame = 1; frame <= nFrames; frame++) for (int channel = 1; channel <= nChannels; channel++) { FloatProcessor[] slices = new FloatProcessor[nSlices]; for (int slice = 1; slice <= nSlices; slice++) { int index = image.getStackIndex(channel, slice, frame); ImageProcessor ip = stack.getProcessor(index); if (ip instanceof FloatProcessor) slices[slice - 1] = (FloatProcessor)ip; else slices[slice - 1] = (FloatProcessor)ip.convertToFloat(); } output.addSlice("", focus(slices, radius)); if (showProgress) IJ.showProgress((frame - 1) * nChannels + channel, nFrames * nChannels); } ImagePlus result = new ImagePlus("Focused " + image.getTitle(), output); result.setDimensions(nChannels, 1, nFrames); return result; }
private ImagePlus extractZSlice(ImagePlus imp, int zslice) { int width = imp.getWidth(); int height = imp.getHeight(); int channels = imp.getNChannels(); int frames = imp.getNFrames(); FileInfo fileInfo = imp.getOriginalFileInfo(); // create empty stack ImageStack stack2 = new ImageStack(width, height); // create new ImagePlus for selected frame ImagePlus imp2 = new ImagePlus(); imp2.setTitle("Z" + zslice + "-" + imp.getTitle()); // copy slices for (int f = 1; f <= frames; f++) for (int c = 1; c <= channels; c++) { int slice = imp.getStackIndex(c, zslice, f); stack2.addSlice("", imp.getStack().getProcessor(slice)); } imp2.setStack(stack2); imp2.setDimensions(channels, 1, frames); if (channels*frames > 1) imp2.setOpenAsHyperStack(true); imp2.setFileInfo(fileInfo); return imp2; }
private ImagePlus extractChannel(ImagePlus imp, int channel) { int width = imp.getWidth(); int height = imp.getHeight(); int zslices = imp.getNSlices(); int frames = imp.getNFrames(); FileInfo fileInfo = imp.getOriginalFileInfo(); // create empty stack ImageStack stack2 = new ImageStack(width, height); // create new ImagePlus for selected channel ImagePlus imp2 = new ImagePlus(); imp2.setTitle("C" + channel + "-" + imp.getTitle()); // copy slices for (int t = 1; t <= frames; t++) for (int z = 1; z <= zslices; z++) { int slice = imp.getStackIndex(channel, z, t); stack2.addSlice("", imp.getStack().getProcessor(slice)); } imp2.setStack(stack2); imp2.setDimensions(1, zslices, frames); if (zslices*frames > 1) imp2.setOpenAsHyperStack(true); imp2.setFileInfo(fileInfo); return imp2; }
@Override public void run() { final int si = imp.getStackIndex( imp.getChannel(), imp.getSlice(), imp.getFrame() ); final ImageStack stack = imp.getStack(); for ( int i = 1; i <= stack.getSize(); ++i ) { final ImageProcessor source = stack.getProcessor( i ).duplicate(); final ImageProcessor target = source.createProcessor( source.getWidth(), source.getHeight() ); source.setInterpolationMethod( ImageProcessor.BILINEAR ); mapping.mapInterpolated( source, target ); if ( i == si ) imp.getProcessor().setPixels( target.getPixels() ); stack.setPixels( target.getPixels(), i ); IJ.showProgress( i, stack.getSize() ); } if ( imp.isComposite() ) ( ( CompositeImage )imp ).setChannelsUpdated(); imp.updateAndDraw(); } } );
@Override public void run() { final int si = imp.getStackIndex( imp.getChannel(), imp.getSlice(), imp.getFrame() ); final ImageStack stack = imp.getStack(); for ( int i = 1; i <= stack.getSize(); ++i ) { final ImageProcessor source = stack.getProcessor( i ).duplicate(); final ImageProcessor target = source.createProcessor( source.getWidth(), source.getHeight() ); source.setInterpolationMethod( ImageProcessor.BILINEAR ); mapping.mapInterpolated( source, target ); if ( i == si ) imp.getProcessor().setPixels( target.getPixels() ); stack.setPixels( target.getPixels(), i ); IJ.showProgress( i, stack.getSize() ); } if ( imp.isComposite() ) ( ( CompositeImage )imp ).setChannelsUpdated(); imp.updateAndDraw(); } } );