Skip to content
Snippets Groups Projects
Commit a93ac471 authored by felmer's avatar felmer
Browse files

LMS-2248 Modify library and utilities classes to handle DeltaVision, Leica,...

LMS-2248 Modify library and utilities classes to handle DeltaVision, Leica, Nikon and Zeiss image containers. Stand-alone classes for getting meta-data viewing and extracting images.

SVN: 21353
parent 2664eb84
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ import java.util.UUID; ...@@ -33,6 +33,7 @@ import java.util.UUID;
import loci.common.IRandomAccess; import loci.common.IRandomAccess;
import loci.common.Location; import loci.common.Location;
import loci.formats.FormatException; import loci.formats.FormatException;
import loci.formats.IFormatHandler;
import loci.formats.IFormatReader; import loci.formats.IFormatReader;
import loci.formats.ImageReader; import loci.formats.ImageReader;
import loci.formats.gui.BufferedImageReader; import loci.formats.gui.BufferedImageReader;
...@@ -126,7 +127,7 @@ final class BioFormatsImageUtils ...@@ -126,7 +127,7 @@ final class BioFormatsImageUtils
static BufferedImage readImage(IFormatReader reader, static BufferedImage readImage(IFormatReader reader,
IRandomAccess handle, int page) throws IOExceptionUnchecked, IllegalArgumentException IRandomAccess handle, int page) throws IOExceptionUnchecked, IllegalArgumentException
{ {
String handleId = generateHandleId(); String handleId = generateHandleId(reader);
// Add to static map. // Add to static map.
Location.mapFile(handleId, handle); Location.mapFile(handleId, handle);
try try
...@@ -159,7 +160,7 @@ final class BioFormatsImageUtils ...@@ -159,7 +160,7 @@ final class BioFormatsImageUtils
public static Map<String, Object> readMetadata(IFormatReader reader, IRandomAccess handle) public static Map<String, Object> readMetadata(IFormatReader reader, IRandomAccess handle)
{ {
// Add to static map. // Add to static map.
String handleId = generateHandleId(); String handleId = generateHandleId(reader);
Location.mapFile(handleId, handle); Location.mapFile(handleId, handle);
try try
...@@ -200,7 +201,7 @@ final class BioFormatsImageUtils ...@@ -200,7 +201,7 @@ final class BioFormatsImageUtils
IllegalArgumentException IllegalArgumentException
{ {
// Add to static map. // Add to static map.
String handleId = generateHandleId(); String handleId = generateHandleId(reader);
Location.mapFile(handleId, handle); Location.mapFile(handleId, handle);
try try
{ {
...@@ -229,9 +230,9 @@ final class BioFormatsImageUtils ...@@ -229,9 +230,9 @@ final class BioFormatsImageUtils
} }
} }
public static String generateHandleId() public static String generateHandleId(IFormatHandler formatHandler)
{ {
return UUID.randomUUID().toString(); return UUID.randomUUID().toString() + "." + formatHandler.getSuffixes()[0];
} }
private static void nullSafeAddAll(HashMap<String, Object> accumulator, private static void nullSafeAddAll(HashMap<String, Object> accumulator,
......
...@@ -35,7 +35,7 @@ public class BioFormatsReaderLibrary implements IImageReaderLibrary ...@@ -35,7 +35,7 @@ public class BioFormatsReaderLibrary implements IImageReaderLibrary
{ {
private static final List<String> TIFF_FORMAT_SUBSTRINGS = Arrays.asList("tiff", private static final List<String> TIFF_FORMAT_SUBSTRINGS = Arrays.asList("tiff",
"metamorph stk", "tagged image file format"); "metamorph stk", "tagged image file format", "deltavision", "leica", "nikon", "zeiss");
public String getName() public String getName()
{ {
......
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.imagereaders.bioformats;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import loci.formats.IFormatReader;
import loci.formats.gui.BufferedImageReader;
/**
* Stand-alone application which extracts all images from any image format understood by BioFormats.
* The images are stored in a folder as PNG images. Each argument is an image file. In case of no
* arguments a file dialog pops up.
*
* @author Franz-Josef Elmer
*/
public class BioFormatsImageExtractor
{
public static void main(String[] args) throws Exception
{
String[] fileNames = args;
if (args.length == 0)
{
FileDialog fileDialog = new FileDialog((Frame) null);
fileDialog.setMode(FileDialog.LOAD);
fileDialog.setVisible(true);
String dir = fileDialog.getDirectory();
fileNames = new String[] {dir + "/" + fileDialog.getFile()};
}
for (String fileName : fileNames)
{
IFormatReader reader = BioFormatsImageUtils.tryFindReaderForFile(fileName);
if (reader == null)
{
System.out.println("No reader found: " + fileName);
continue;
}
reader.setId(fileName);
int seriesCount = reader.getSeriesCount();
System.out.println("=========== file " + fileName + " has " + seriesCount + " series.");
File imageFolder = new File(fileName + ".extracted-images");
imageFolder.mkdirs();
for (int s = 0; s < seriesCount; s++)
{
reader.setSeries(s);
File serieFolder = new File(imageFolder, "s" + s);
serieFolder.mkdirs();
int effectiveSizeC = reader.getEffectiveSizeC();
int sizeT = reader.getSizeT();
int sizeZ = reader.getSizeZ();
System.out.println(" Serie " + s + " has " + sizeT + " time points, "
+ sizeZ + " focal planes and " + effectiveSizeC + " color channels.");
for (int t = 0; t < sizeT; t++)
{
for (int z = 0; z < sizeZ; z++)
{
for (int c = 0; c < effectiveSizeC; c++)
{
int index = reader.getIndex(z, c, t);
BufferedImageReader biReader =
BufferedImageReader.makeBufferedImageReader(reader);
BufferedImage image = biReader.openImage(index);
String imageName = "t" + t + "-z" + z + "-c" + c;
File imageFile = new File(serieFolder, imageName + ".png");
ImageIO.write(image, "PNG", imageFile);
System.out.println("Image extracted into " + imageFile + " (" + index + ")");
}
}
}
}
reader.close();
}
}
}
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.imagereaders.bioformats;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import javax.media.jai.widget.ScrollingImagePanel;
import ch.systemsx.cisd.imagereaders.IImageReader;
import ch.systemsx.cisd.imagereaders.TiffReadParams;
/**
*
*
* @author Franz-Josef Elmer
*/
public class BioFormatsImageViewer
{
public static void main(String[] args)
{
if (args.length == 0)
{
FileDialog fileDialog = new FileDialog((Frame) null);
fileDialog.setMode(FileDialog.LOAD);
fileDialog.setVisible(true);
String dir = fileDialog.getDirectory();
args = new String[] {dir + "/" + fileDialog.getFile()};
}
for (String fileName : args)
{
IImageReader reader = new BioFormatsReaderLibrary().tryGetReaderForFile(fileName);
System.out.println("=========== File: " + fileName);
System.out.println("Reader: " + reader);
File file = new File(fileName);
TiffReadParams readParams = new TiffReadParams(0);
readParams.setIntensityRescalingChannel(0);
final BufferedImage image = reader.readImage(file, readParams);
showImage(image, fileName);
}
}
private static void showImage(final RenderedImage image, String fileName)
{
final Frame frame = new Frame("Image: " + fileName);
final ScrollingImagePanel panel =
new ScrollingImagePanel(image, image.getWidth() + 10, image.getHeight() + 10);
frame.add(panel);
frame.setLocationByPlatform(true);
frame.pack();
frame.setVisible(true);
}
}
/*
* Copyright 2011 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.imagereaders.bioformats;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import loci.formats.CoreMetadata;
import loci.formats.IFormatReader;
/**
* Get some meta-data from an image.
*
* @author Franz-Josef Elmer
*/
public class BioFormatsInfo
{
private static final int CUTTOFF = 50;
public static void main(String[] args) throws Exception
{
for (String fileName : args)
{
IFormatReader reader = BioFormatsImageUtils.tryFindReaderForFile(fileName);
if (reader == null)
{
System.out.println("No image reader found for " + fileName);
continue;
}
reader.setId(fileName);
System.out.println("====== " + fileName);
System.out.println(" format: " + reader.getFormat());
System.out.println(" image count: " + reader.getImageCount());
System.out.println(" bits per pixel: " + reader.getBitsPerPixel());
System.out.println(" dimension order: " + reader.getDimensionOrder());
System.out.println(" size T: " + reader.getSizeT());
System.out.println(" size X: " + reader.getSizeX());
System.out.println(" size Y: " + reader.getSizeY());
System.out.println(" size Z: " + reader.getSizeZ());
System.out.println(" size C: " + reader.getSizeC());
System.out.println(" effective size C: " + reader.getEffectiveSizeC());
System.out.println(" pixel type: " + reader.getPixelType());
System.out.println(" RGB channel count: " + reader.getRGBChannelCount());
CoreMetadata[] coreMetadata = reader.getCoreMetadata();
System.out.println(" # of core meta-data: " + coreMetadata.length);
printMap(" global meta-data", reader.getGlobalMetadata());
int seriesCount = reader.getSeriesCount();
System.out.println(" series count: " + seriesCount);
for (int i = 0; i < Math.min(2, seriesCount); i++)
{
reader.setSeries(i);
printMap(" series meta-data " + i, reader.getSeriesMetadata());
}
}
}
private static void printMap(String title, Map<String, Object> map)
{
System.out.println(title + ":");
List<Entry<String, Object>> entries = new ArrayList<Entry<String, Object>>(map.entrySet());
Collections.sort(entries, new Comparator<Entry<String, Object>>()
{
public int compare(Entry<String, Object> o1, Entry<String, Object> o2)
{
return o1.getKey().compareTo(o2.getKey());
}
});
for (Entry<String, Object> entry : entries)
{
String value = entry.getValue().toString();
if (value.length() > CUTTOFF)
{
value = value.substring(0, CUTTOFF) + "...";
}
System.out.println(" " + entry.getKey() + " = " + value);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment