Commit 57afab00 authored by kulvait's avatar kulvait

Den File Opener

parents
Pipeline #130 failed with stages
/.classpath
/.project
/.settings/
/target/
This diff is collapsed.
ImageJ 1.x plugin to open DEN files
How to use this plugin
======================
Clone the repository
* `git clone ssh://git@gitlab.stimulate.ovgu.de:2200/vojtech.kulvait/den-file-opener.git`
Then:
1. Install maven by `apt-get install maven`
2. Run `mvn` command
3. Copy jar file from target directory to ~/.imagej/plugins
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>14.0.0</version>
<relativePath />
</parent>
<groupId>de.ovgu.imt</groupId>
<artifactId>Den_File_Opener</artifactId>
<version>1.0.23</version>
<name>DEN File Openner</name>
<description>ImageJ 1.x plugin to open files in DEN format</description>
<url>https://gitlab.stimulate.ovgu.de/vojtech.kulvait/den-file-opener</url>
<inceptionYear>2019</inceptionYear>
<organization>
<name>Institut für Medizintechnik, Otto-von-Guericke-Universität Magdeburg</name>
<url>http://www.imt.ovgu.de/</url>
</organization>
<licenses>
<license>
<name>GNU GENERAL PUBLIC LICENSE V3</name>
</license>
</licenses>
<developers>
<developer>
<id>kulvait</id>
<name>Vojtěch Kulvait</name>
<url>https://scholar.google.cz/citations?user=rsOToBIAAAAJ</url>
<roles>
<role>lead</role>
<role>developer</role>
<role>debugger</role>
<role>reviewer</role>
<role>support</role>
<role>maintainer</role>
</roles>
</developer>
</developers>
<contributors>
<contributor>
<name>Vojtěch Kulvait</name>
<url>https://scholar.google.cz/citations?user=rsOToBIAAAAJ</url>
</contributor>
</contributors>
<scm>
<connection>scm:git:ssh://git@gitlab.stimulate.ovgu.de:2200/vojtech.kulvait/den-file-opener.git</connection>
<developerConnection>scm:git:ssh://git@gitlab.stimulate.ovgu.de:2200/vojtech.kulvait/den-file-opener.git</developerConnection>
<tag>HEAD</tag>
<url>https://gitlab.stimulate.ovgu.de/vojtech.kulvait/den-file-opener</url>
</scm>
<mailingLists>
<mailingList>
<name>Dev null</name>
<archive>/dev/null</archive>
</mailingList>
</mailingLists>
<issueManagement>
<system>GitLab Issues</system>
<url>https://gitlab.stimulate.ovgu.de/vojtech.kulvait/den-file-opener/issues</url>
</issueManagement>
<ciManagement>
<system>None</system>
</ciManagement>
<properties>
<package-name>de.ovgu.lmt.imagej.denfileopener</package-name>
<main-class>de.ovgu.lmt.imagej.denfileopener.Den_File_Opener</main-class>
<license.licenseName>bsd_2</license.licenseName>
<license.copyrightOwners>Vojtěch Kulvait</license.copyrightOwners>
</properties>
<dependencies>
<dependency>
<groupId>net.imagej</groupId>
<artifactId>ij</artifactId>
</dependency>
</dependencies>
</project>
/*******************************************************************************
* Project : Stimulate, OpenJ plugin to open in house den format
* Author: Vojtěch Kulvait
* Licence: GNU GPL3
* Description : Modification of original file
*https://imagej.nih.gov/ij/plugins/raw-file-opener.html.
*Date: 2019
******************************************************************************/
package de.ovgu.lmt.imagej.denfileopener;
import ij.plugin.*;
import ij.*;
import ij.io.*;
import java.awt.EventQueue;
import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import java.nio.ByteOrder;
/** Uses the JFileChooser from Swing to open one or more raw images.
The "Open All Files in Folder" check box in the dialog is ignored. */
public class Den_File_Opener implements PlugIn {
static private String directory;
private File file;
public void run(String arg) {
openFiles();
}
public void openFiles() {
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
JFileChooser fc = new JFileChooser();
fc.setMultiSelectionEnabled(false);
File dir = null;
if (directory == null) {
directory = Prefs.getString(".options.denlastdir");
}
if (directory == null) {
directory = OpenDialog.getLastDirectory();
}
if (directory == null) {
directory = OpenDialog.getDefaultDirectory();
}
if (directory != null) {
fc.setCurrentDirectory(new File(directory));
System.out.println(
String.format("Directory is %s", directory));
} else {
System.out.println("Directory is null");
}
int returnVal = fc.showOpenDialog(IJ.getInstance());
if (returnVal != JFileChooser.APPROVE_OPTION)
return;
file = fc.getSelectedFile();
directory =
fc.getCurrentDirectory().getPath() + File.separator;
OpenDialog.setLastDirectory(directory);
Prefs.set("options.denlastdir", directory);
Prefs.savePreferences();
System.out.println(String.format("Storing directory %s.",
Prefs.getString(".options.denlastdir")));
}
});
} catch (Exception e) {
}
if (file == null) {
return;
}
List<Integer> dim = analyzeDenFile(file);
long fileSize = file.length();
FileInfo fi = new FileInfo();
fi.fileFormat = fi.RAW;
fi.fileName = file.getName();
fi.directory = directory;
fi.width = dim.get(0);
fi.height = dim.get(1);
fi.offset = 6;
fi.nImages = dim.get(2);
fi.gapBetweenImages = 0;
fi.intelByteOrder = true; // little endian
fi.whiteIsZero = false; // can be adjusted
long totalunits = (long) dim.get(0) * dim.get(1) * dim.get(2);
if (totalunits == 0)
throw new RuntimeException(
String.format("One or more dimensions are zero x=%d, y=%d, z=%d",
dim.get(0), dim.get(1), dim.get(2)));
if ((fileSize - 6) % totalunits != 0)
throw new RuntimeException(String.format(
"Dimensions do not match actual size of file. The file %s is not in den format or is corrupted.",
file.getPath()));
long unitsize = (fileSize - 6) / totalunits;
String typ;
if (unitsize == 1) {
fi.fileType = FileInfo.GRAY8;
typ = "uint8";
} else if (unitsize == 2) {
fi.fileType = FileInfo.GRAY16_UNSIGNED;
typ = "uint16";
} else if (unitsize == 4) {
fi.fileType = FileInfo.GRAY32_FLOAT;
typ = "float32";
} else if (unitsize == 8) {
fi.fileType = FileInfo.GRAY64_FLOAT;
typ = "float64";
} else {
throw new RuntimeException(String.format(
"The unit size of %d of the file %s does not match any number storage format used in den files.",
unitsize, file.getPath()));
}
System.out.println(String.format("%s with dimensions x=%d, y=%d, z=%d and type %s.",
file.getPath(), dim.get(0), dim.get(1), dim.get(2), typ));
FileOpener fo = new FileOpener(fi);
ImagePlus img = fo.open(false);
if (img != null) {
if (IJ.getVersion().compareTo("1.50e") >= 0)
img.setIJMenuBar(true);
img.setZ(dim.get(2) / 2);
img.resetDisplayRange();
img.show();
}
}
public static List<Integer> analyzeDenFile(File f) {
try {
RandomAccessFile df = new RandomAccessFile(f, "r");
FileChannel inChannel = df.getChannel();
MappedByteBuffer buffer = inChannel.map(
FileChannel.MapMode.READ_ONLY, 0, Math.min(1024, inChannel.size()));
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.load();
int ysize = buffer.getShort();
int xsize = buffer.getShort();
int zsize = buffer.getShort();
buffer.clear();
inChannel.close();
df.close();
List<Integer> dimensions = new ArrayList<Integer>();
dimensions.add(xsize);
dimensions.add(ysize);
dimensions.add(zsize);
return dimensions;
} catch (IOException e) {
return null;
}
}
}
# A single .jar file can contain multiple plugins, specified in separate lines.
#
# The format is: <menu>, "<menu label>", <class name>
#
# If something like ("<arg>") is appended to the class name, the setup() method
# will get that as arg parameter; otherwise arg is simply the empty string.
File, "Open DEN ...", de.ovgu.lmt.imagej.denfileopener.Den_File_Opener
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment