ij.io.Opener Java Examples

The following examples show how to use ij.io.Opener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommonFunctions.java    From Stitching with GNU General Public License v2.0 6 votes vote down vote up
public static ImagePlus loadImage(String directory, String file, int seriesNumber, String rgb)
{
	ImagePlus imp = null;
	
	String smallFile = file.toLowerCase();
	
	if (smallFile.endsWith("tif") || smallFile.endsWith("tiff") || smallFile.endsWith("jpg") || smallFile.endsWith("png") || smallFile.endsWith("bmp") || 
		smallFile.endsWith("gif") || smallFile.endsWith("jpeg"))
	{
		imp = new Opener().openImage((new File(directory, file)).getPath());
	}
	else
	{
		imp = openLOCIImagePlus(directory, file, seriesNumber, rgb);
		if (imp == null)
			imp = new Opener().openImage((new File(directory, file)).getPath());
	}

	
	return imp;
}
 
Example #2
Source File: CrossCorrelation2D.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public CrossCorrelation2D(String image1, String image2, boolean showImages)
{
    // load images
    ImagePlus img1 = new Opener().openImage(image1);
    ImagePlus img2 = new Opener().openImage(image2);

    if (showImages)
    {
        img1.show();
        img2.show();
    }

    ImageProcessor ip1 = img1.getProcessor();
    ImageProcessor ip2 = img2.getProcessor();

    this.img1 = ImageToFloatArray2D(ip1);
    this.img2 = ImageToFloatArray2D(ip2);
    this.showImages = showImages;

    //computeCrossCorrelation(ImageToFloatArray2D(ip1), ImageToFloatArray2D(ip2), showImages);
}
 
Example #3
Source File: IJImager.java    From DeconvolutionLab2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public RealSignal open(String filename) {
	Opener opener = new Opener();
	ImagePlus imp = opener.openImage(filename);
	if (imp == null)
		return null;
	return build(imp);
}
 
Example #4
Source File: IcyImager.java    From DeconvolutionLab2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
   public RealSignal open(String filename) {
	Opener opener = new Opener();
	ImagePlus imp = opener.openImage(filename);
	Sequence seq = ImageJUtil.convertToIcySequence(imp, null);
	return build(seq);
}
 
Example #5
Source File: MipmapClient.java    From render with GNU General Public License v2.0 5 votes vote down vote up
static ImageProcessor loadImageProcessor(final String url)
        throws IllegalArgumentException {

    // openers keep state about the file being opened, so we need to create a new opener for each load
    final Opener opener = new Opener();
    opener.setSilentMode(true);

    final ImagePlus imagePlus = opener.openURL(url);
    if (imagePlus == null) {
        throw new IllegalArgumentException("failed to create imagePlus instance for '" + url + "'");
    }

    return imagePlus.getProcessor();
}
 
Example #6
Source File: LegacyStackImgLoaderIJ.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static ImagePlus open( File file )
{
	final ImagePlus imp = new Opener().openImage( file.getAbsolutePath() );

	if ( imp == null )
	{
		IOFunctions.printlnSafe( "Could not open file with ImageJ TIFF reader: '" + file.getAbsolutePath() + "'" );
		return null;
	}

	return imp;
}
 
Example #7
Source File: InteractiveDoG.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static void main( String[] args )
{
	new ImageJ();
	
	ImagePlus imp = new Opener().openImage( "/Users/spreibi/Documents/Microscopy/SPIM/HisYFP-SPIM/spim_TL18_Angle0.tif" );
	//ImagePlus imp = new Opener().openImage( "D:/Documents and Settings/Stephan/My Documents/Downloads/1-315--0.08-isotropic-subvolume/1-315--0.08-isotropic-subvolume.tif" );
	imp.show();
	
	imp.setSlice( 27 );		
	imp.setRoi( imp.getWidth()/4, imp.getHeight()/4, imp.getWidth()/2, imp.getHeight()/2 );		
	
	new InteractiveDoG().run( null ); 	
		
}
 
Example #8
Source File: Distortion_Correction.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
static List< Feature >[] extractSIFTFeaturesThreaded(
		final int numberOfImages, final String directory,
		final String[] names ){
	//extract all SIFT Features

	final List< Feature >[] siftFeatures = new ArrayList[numberOfImages];
	final Thread[] threads = MultiThreading.newThreads();
	final AtomicInteger ai = new AtomicInteger(0); // start at second slice

	IJ.showStatus("Extracting SIFT Features");
	for (int ithread = 0; ithread < threads.length; ++ithread) {
		threads[ithread] = new Thread() {
			@Override
               public void run() {
				for (int i = ai.getAndIncrement(); i < numberOfImages; i = ai.getAndIncrement())
				{
					final ArrayList< Feature > fs = new ArrayList< Feature >();
					final ImagePlus imps = new Opener().openImage(directory + names[i + sp.firstImageIndex]);
					imps.setProcessor(imps.getTitle(), imps.getProcessor().convertToFloat());

					final FloatArray2DSIFT sift = new FloatArray2DSIFT( sp.sift.clone() );
					final SIFT ijSIFT = new SIFT( sift );

					ijSIFT.extractFeatures( imps.getProcessor(), fs );

					Collections.sort( fs );
					IJ.log("Extracting SIFT of image: "+i);

					siftFeatures[i]=fs;

				}
			}
		};
	}
	MultiThreading.startAndJoin(threads);

	return  siftFeatures;
}
 
Example #9
Source File: ImageProcessorCache.java    From render with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The core method used to load image processor instances that is called when cache misses occur.
 *
 * @param  url               url for the image.
 * @param  downSampleLevels  number of levels to further down sample the image.
 * @param  isMask            indicates whether this image is a mask.
 * @param  convertTo16Bit    indicates whether the loaded image processor should be converted to 16-bit.
 *
 * @return a newly loaded image processor to be cached.
 *
 * @throws IllegalArgumentException
 *   if the image cannot be loaded.
 */
protected ImageProcessor loadImageProcessor(final String url,
                                            final int downSampleLevels,
                                            final boolean isMask,
                                            final boolean convertTo16Bit)
        throws IllegalArgumentException {

    if (LOG.isDebugEnabled()) {
        LOG.debug("loadImageProcessor: entry, url={}, downSampleLevels={}, convertTo16Bit={}", url, downSampleLevels,convertTo16Bit);
    }

    ImageProcessor imageProcessor = null;

    // if we need to down sample, see if source image is already cached before trying to load it
    if (downSampleLevels > 0) {
        imageProcessor = cache.getIfPresent(new CacheKey(url, 0, isMask,convertTo16Bit));
    }

    // load the image as needed
    if (imageProcessor == null) {

        // TODO: use Bio Formats to load strange formats

        // openers keep state about the file being opened, so we need to create a new opener for each load
        final Opener opener = new S3Opener();
        opener.setSilentMode(true);

        final ImagePlus imagePlus = opener.openURL(url);
        if (imagePlus == null) {
            throw new IllegalArgumentException("failed to create imagePlus instance for '" + url + "'");
        }

        imageProcessor = imagePlus.getProcessor();

        // Force images to 16-bit, to allow for testing of mixed 8-bit and 16-bit mipmap levels.
        if ((! isMask) && (imageProcessor.getBitDepth() == 8) && convertTo16Bit) {
            imageProcessor = imageProcessor.convertToShort(false);
            imageProcessor.multiply(256.0);
        }

        // if we're going to down sample and we're supposed to cache originals, do so here
        if (cacheOriginalsForDownSampledImages && (downSampleLevels > 0)) {

            if (LOG.isDebugEnabled()) {
                LOG.debug("loadImageProcessor: caching level 0 for {}", url);
            }

            cache.put(new CacheKey(url, 0, isMask,convertTo16Bit), imageProcessor);
        }

    }

    // down sample the image as needed
    if (downSampleLevels > 0) {
        // NOTE: The down sample methods return a safe copy and leave the source imageProcessor unmodified,
        //       so we don't need to duplicate a cached source instance before down sampling.
        imageProcessor = Downsampler.downsampleImageProcessor(imageProcessor,
                                                              downSampleLevels);
    }

    return imageProcessor;
}
 
Example #10
Source File: Utils.java    From render with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Open an ImagePlus from a file.
 */
public static ImagePlus openImagePlus(final String pathString) {
    final Opener opener = new Opener();
    return opener.openImage(pathString);
}
 
Example #11
Source File: Utils.java    From render with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Open an ImagePlus from a URL
 */
public static ImagePlus openImagePlusUrl(final String urlString) {
    final Opener opener = new Opener();
    return opener.openURL(urlString);
}
 
Example #12
Source File: StackListImageJ.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Calibration loadCalibration( final File file ) 
{
	try
	{
		IOFunctions.println( "Loading calibration for: " + file.getAbsolutePath() );
		
		if ( !file.exists() )
		{
			IOFunctions.println( "File '" + file + "' does not exist. Stopping." );
			return null;
		}
		
		final ImagePlus imp = new Opener().openImage( file.getAbsolutePath() );

		if ( imp == null )
		{
			IOFunctions.println( "Could not open file: '" + file.getAbsolutePath() + "'" );
			return null;				
		}
		
		final ij.measure.Calibration c = imp.getCalibration();
		
		final double calX = c.pixelWidth;
		final double calY = c.pixelHeight;
		final double calZ = c.pixelDepth;
		
		String calUnit = c.getUnit();
		
		if ( calUnit.contains( "µ" ) )
			calUnit = calUnit.replace( 'µ', 'u' );
		
		imp.close();
		
		return new Calibration( calX, calY, calZ, calUnit );
	}
	catch ( Exception e )
	{
		IOFunctions.println( "Could not open file: '" + file.getAbsolutePath() + "'" );
		return null;
	}
}
 
Example #13
Source File: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 
 * @param filenames
 * @return
 */
public static < T extends RealType< T > & NativeType< T > > ExtractPSF< T > loadAndTransformPSFs(
		final ArrayList< Pair< Pair< Angle, Illumination >, String > > filenames,
		final ArrayList< ViewDescription > viewDesc,
		final T type,
		final HashMap< ViewId, AffineTransform3D > models )
{
	final ExtractPSF< T > extractPSF = new ExtractPSF< T >();

	for ( final ViewDescription vd : viewDesc )
	{
		final File file = getFileNameForViewId( vd, filenames );

		// extract the PSF for this one
		IOFunctions.println( "Loading PSF file '" + file.getAbsolutePath() );

		final ImagePlus imp = new Opener().openImage( file.getAbsolutePath() );

		if ( imp == null )
			throw new RuntimeException( "Could not load '" + file + "' using ImageJ (should be a TIFF file)." );

		final ImageStack stack = imp.getStack();
		final int width = imp.getWidth();
		final int sizeZ = imp.getNSlices();

		ArrayImg< T, ? > psfImage = new ArrayImgFactory< T >().create( new long[]{ width, imp.getHeight(), sizeZ }, type );

		for ( int z = 0; z < sizeZ; ++z )
		{
			final Cursor< T > cursor = Views.iterable( Views.hyperSlice( psfImage, 2, z ) ).localizingCursor();
			final ImageProcessor ip = stack.getProcessor( z + 1 );

			while ( cursor.hasNext() )
			{
				cursor.fwd();
				cursor.get().setReal( ip.getf( cursor.getIntPosition( 0 ) + cursor.getIntPosition( 1 ) * width ) );
			}
		}

		final ArrayImg< T, ? > psf;

		if ( models != null )
		{
			IOFunctions.println( "Transforming PSF for viewid " + vd.getViewSetupId() + ", file=" + file.getName() );
			psf = ExtractPSF.transformPSF( psfImage, models.get( vd ) );
		}
		else
		{
			IOFunctions.println( "PSF for viewid " + vd.getViewSetupId() + ", file=" + file.getName() + " will not be transformed." );
			psf = psfImage.copy();
		}

		extractPSF.viewIds.add( vd );
		extractPSF.pointSpreadFunctions.put( vd, psf );
		extractPSF.originalPSFs.put( vd, psfImage );
	}
	
	return extractPSF;
}
 
Example #14
Source File: FSLoader.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected boolean mapIntensities(final Patch p, final ImagePlus imp) {
	
	final ImagePlus coefficients = new Opener().openImage(
		getUNUIdFolder() +
		"trakem2.its/" +
		createIdPath(Long.toString(p.getId()), "it", ".tif"));

	if (coefficients == null)
		return false;
	
	final ImageProcessor ip = imp.getProcessor();
	
	@SuppressWarnings({"rawtypes"})
	final LinearIntensityMap<FloatType> map =
			new LinearIntensityMap<FloatType>(
					(FloatImagePlus)ImagePlusImgs.from(coefficients));

	@SuppressWarnings("rawtypes")
	Img img;

	final long[] dims = new long[]{imp.getWidth(), imp.getHeight()};
	switch (p.getType()) {
	case ImagePlus.GRAY8:
	case ImagePlus.COLOR_256:		// this only works for continuous color tables
		img = ArrayImgs.unsignedBytes((byte[])ip.getPixels(), dims);
		break;
	case ImagePlus.GRAY16:
		img = ArrayImgs.unsignedShorts((short[])ip.getPixels(), dims);
		break;
	case ImagePlus.COLOR_RGB:
		img = ArrayImgs.argbs((int[])ip.getPixels(), dims);
		break;
	case ImagePlus.GRAY32:
		img = ArrayImgs.floats((float[])ip.getPixels(), dims);
		break;
	default:
		img = null;
	}
	
	if (img == null)
		return false;

	map.run(img);
	
	return true;
}
 
Example #15
Source File: Distortion_Correction.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
protected double[] evaluateCorrectionXcorr( final int index, final String directory )
{
	final ImagePlus im1 = new Opener().openImage( directory + sp.names[ index ] );
	im1.setProcessor( sp.names[ index ], im1.getProcessor().convertToShort( false ) );

	int count = 0;
	final ArrayList< Double > xcorrVals = new ArrayList< Double >();
	final ArrayList< Double > xcorrValsGrad = new ArrayList< Double >();

	for ( int i = 0; i < sp.numberOfImages; i++ )
	{
		if ( i == index )
		{
			continue;
		}
		if ( models[ index * ( sp.numberOfImages - 1 ) + count ] == null )
		{
			count++;
			continue;
		}

		final ImagePlus newImg = new Opener().openImage( directory + sp.names[ i + sp.firstImageIndex ] );
		newImg.setProcessor( newImg.getTitle(), newImg.getProcessor().convertToShort( false ) );

		newImg.setProcessor( sp.names[ i + sp.firstImageIndex ], applyTransformToImageInverse( models[ index * ( sp.numberOfImages - 1 ) + count ], newImg.getProcessor() ) );

		// If you want to see the stitching improvement run this
		// ImageProcessor testIp = im1.getProcessor().duplicate();

		// for ( int x=0; x < testIp.getWidth(); x++){
		// for (int y=0; y < testIp.getHeight(); y++){
		// testIp.set(x, y, Math.abs(im1.getProcessor().get(x,y) -
		// newImg.getProcessor().get(x,y)));
		// }
		// }

		// ImagePlus testImg = new ImagePlus(sp.names[index] + " minus " +
		// sp.names[i], testIp);
		// testImg.show();
		// im1.show();
		// newImg.show();

		xcorrVals.add( getXcorrBlackOut( im1.getProcessor(), newImg.getProcessor() ) );

		xcorrValsGrad.add( getXcorrBlackOutGradient( im1.getProcessor(), newImg.getProcessor() ) );
		count++;
	}

	Collections.sort( xcorrVals );
	Collections.sort( xcorrValsGrad );

	//		double[] medians = { xcorrVals.get( xcorrVals.size() / 2 ), xcorrValsGrad.get( xcorrValsGrad.size() / 2 ) };

	double m1 = 0.0, m2 = 0.0;
	for ( int i = 0; i < xcorrVals.size(); i++ )
	{
		m1 += xcorrVals.get( i );
		m2 += xcorrValsGrad.get( i );
	}

	m1 /= xcorrVals.size();
	m2 /= xcorrVals.size();

	final double[] means = { m1, m2 };

	return means;
	//return medians;
}