Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Retab

  • Loading branch information...
commit f4bbaf09014bb97052a39585b72aa965f102ccaf 1 parent b82648c
@thomie authored
Showing with 133 additions and 133 deletions.
  1. +133 −133 Ics_Opener_To_Tiff.java
View
266 Ics_Opener_To_Tiff.java
@@ -22,31 +22,31 @@ Modified by Wayne Rashband (wsr)
public class Ics_Opener_To_Tiff extends Opener implements PlugIn {
private static String defaultDirectory = null;
- boolean interlaced = false;
- // Maximmum number of channels displayed in individual stacks
- static int MAX_CHANNELS=5;
+ boolean interlaced = false;
+ // Maximmum number of channels displayed in individual stacks
+ static int MAX_CHANNELS=5;
Integer nChannelsSelected = 0;
boolean[] selectedChannels = new boolean[MAX_CHANNELS];
- public void run(String arg) {
- if (arg.equals("about")) {
- showAbout();
- } else {
+ public void run(String arg) {
+ if (arg.equals("about")) {
+ showAbout();
+ } else {
getChannels();
- this.openMultiple();
+ this.openMultiple();
if (nChannelsSelected > 0) {
IJ.showMessage("Converted the selected channels and images to TIFF files");
}
- }
- return;
- }
+ }
+ return;
+ }
- private void showAbout() {
- IJ.showMessage("Ics_Opener_To_Tiff", "This plugins opens Ics/Ids files and converts channel 3 to Tiff \n" +
- " Nico Stuurman, January 2007\n" +
- " Thomas Miedema (thomasmiedema@gmail.com), March 2011"
- );
- }
+ private void showAbout() {
+ IJ.showMessage("Ics_Opener_To_Tiff", "This plugins opens Ics/Ids files and converts channel 3 to Tiff \n" +
+ " Nico Stuurman, January 2007\n" +
+ " Thomas Miedema (thomasmiedema@gmail.com), March 2011"
+ );
+ }
private void getChannels() {
GenericDialog gd = new GenericDialog("Select channels");
@@ -68,7 +68,7 @@ private void getChannels() {
}
}
}
-
+
public void open(String path) {
if (!IJ.isJava2()) { //wsr
IJ.showMessage("ICS Opener", "This plugin requires Java 1.2 or later.");
@@ -89,7 +89,7 @@ public void open(String path) {
icsfileName=new String (fileName);
idsfileName=fileName.substring(0,fileName.length()-4)+".ids";
}
- else if (fileName.endsWith(".ICS")) {
+ else if (fileName.endsWith(".ICS")) {
icsfileName=new String (fileName);
idsfileName=fileName.substring(0,fileName.length()-4)+".IDS";
}
@@ -118,7 +118,7 @@ else if (fileName.endsWith(".IDS")) {
IcsImport d = new IcsImport(icsfileName, idsfileName, directory);
d.OpenIcs();
}
-
+
public class IcsImport {
private String icsFileName;
private String idsFileName;
@@ -129,7 +129,7 @@ public IcsImport (String icsFileName, String idsFileName, String directory) {
this.icsFileName=icsFileName;
this.idsFileName=idsFileName;
this.directory=directory;
-
+
}
public FileInfo[] IcsInfo () {
@@ -151,7 +151,7 @@ public IcsImport (String icsFileName, String idsFileName, String directory) {
Long offset=new Long(0);
int bits=0,x=0,y=0,z=1,t=1,ch=1;
int bitsOffset=0,xOffset=0,yOffset=0,zOffset=0,tOffset=0,chOffset=0;
-
+
if (!icsFile.canRead())
return null;
try {
@@ -181,7 +181,7 @@ public IcsImport (String icsFileName, String idsFileName, String directory) {
offset=new Long(tmp[2]);
}
}
-
+
if (tmp[0].equals("layout")) {
if (tmp[1].equals("parameters")) {
numpars=new Integer(tmp[2]);
@@ -192,9 +192,9 @@ public IcsImport (String icsFileName, String idsFileName, String directory) {
for (j=0;j<numpars.intValue();j++) {
paramkeys[j]=tmp[j+2];
}
- if (paramkeys[1].equals("ch") || paramkeys[1].equals("channels")) {
- interlaced = true;
- }
+ if (paramkeys[1].equals("ch") || paramkeys[1].equals("channels")) {
+ interlaced = true;
+ }
}
if (tmp[1].equals("sizes")) {
paramvalues=new Integer[numpars.intValue()];
@@ -206,25 +206,25 @@ public IcsImport (String icsFileName, String idsFileName, String directory) {
}
if (tmp[0].equals("representation")) {
if(tmp[1].equals("format"))
- format=new String(tmp[2]);
+ format=new String(tmp[2]);
if(tmp[1].equals("sign"))
- sign=new String(tmp[2]);
+ sign=new String(tmp[2]);
if(tmp[1].equals("compression"))
- compression=new String(tmp[2]);
+ compression=new String(tmp[2]);
if(tmp[1].equals("byte_order")) {
int nr_bytes=paramvalues[0].intValue()/8;
- byte_order=new Integer[nr_bytes];
+ byte_order=new Integer[nr_bytes];
for (int bo=0; bo<(nr_bytes); bo++)
- byte_order[bo]=new Integer(tmp[2 + bo]);
+ byte_order[bo]=new Integer(tmp[2 + bo]);
if (nr_bytes>1) {
- // This is counter intuitive to me, but seems to work alright:
+ // This is counter intuitive to me, but seems to work alright:
if (byte_order[1].intValue()>byte_order[0].intValue())
intelByteOrder=true;
else
intelByteOrder=false;
}
else
- intelByteOrder=false;
+ intelByteOrder=false;
}
}
if (tmp[0].equals("parameter")) {
@@ -289,7 +289,7 @@ public IcsImport (String icsFileName, String idsFileName, String directory) {
ch=paramvalues[j].intValue();
}
}
- //IJ.write (x + "," + y + ", " + z);
+ //IJ.write (x + "," + y + ", " + z);
//IJ.write (format+","+sign+","+compression+","+intelByteOrder);
// set Calibration based on ics-derived values
if (scalekeysFound) {
@@ -303,16 +303,16 @@ public IcsImport (String icsFileName, String idsFileName, String directory) {
// for version 2 ics files, the ids file is the same as the ics one:
- if (ics_version.compareTo(new Float(1.0)) > 0) {
+ if (ics_version.compareTo(new Float(1.0)) > 0) {
this.idsFileName=this.icsFileName;
}
- else {
- // for version 1 we need an ids file,check if it exists
+ else {
+ // for version 1 we need an ids file,check if it exists
File f = new File(this.directory, this.idsFileName);
if (!f.canRead()) {
IJ.showMessage("ICS Opener", "\""+this.idsFileName+"\" not found");
FileInfo[] fib=new FileInfo[0];
- return fib;
+ return fib;
}
}
@@ -349,122 +349,122 @@ else if ((bits==32)&&(sign.equals("unsigned")))
fia[k].fileType=FileInfo.GRAY32_INT;
else
fia[k].fileType=FileInfo.GRAY8;
-
- }
+
+ }
return fia;
}
public void OpenIcs () {
FileInfo[] fi=IcsInfo();
- ImagePlus[] ipStack = new ImagePlus[fi.length];
+ ImagePlus[] ipStack = new ImagePlus[fi.length];
if (fi==null)
return;
- IJ.showStatus ("Opening ICS file...");
- if (!interlaced) {
- for (int i=0; i<fi.length; i++) {
- //IJ.write (fi[i].intelByteOrder+"," + fi[i].fileType);
- FileOpener fo=new FileOpener(fi[i]);
- Integer chCount=new Integer(i+1);
- // only show when not interlaced
- ImagePlus ip=fo.open(!interlaced);
- if (ip==null) return;
- // Only used for de-interlacing:
- if (fi.length<=1)
- ip.setTitle(fi[i].fileName.substring(0,fi[i].fileName.length()-4));
- else
- ip.setTitle(fi[i].fileName.substring(0,fi[i].fileName.length()-4)+" ch: "+chCount.toString());
- ip.setCalibration(this.cal);
- ipStack[i]=ip;
- IJ.showProgress(i+1, fi.length);
- }
+ IJ.showStatus ("Opening ICS file...");
+ if (!interlaced) {
+ for (int i=0; i<fi.length; i++) {
+ //IJ.write (fi[i].intelByteOrder+"," + fi[i].fileType);
+ FileOpener fo=new FileOpener(fi[i]);
+ Integer chCount=new Integer(i+1);
+ // only show when not interlaced
+ ImagePlus ip=fo.open(!interlaced);
+ if (ip==null) return;
+ // Only used for de-interlacing:
+ if (fi.length<=1)
+ ip.setTitle(fi[i].fileName.substring(0,fi[i].fileName.length()-4));
+ else
+ ip.setTitle(fi[i].fileName.substring(0,fi[i].fileName.length()-4)+" ch: "+chCount.toString());
+ ip.setCalibration(this.cal);
+ ipStack[i]=ip;
+ IJ.showProgress(i+1, fi.length);
+ }
}
- // Deinterlace if interlaced
- // stackOld contains ch1 (t,z ??), ch2 (t,z ??) etc..
- if (interlaced) {
- IJ.showStatus ("Deinterlacing ICS file...");
- int width = fi[0].width;
- int height = fi[0].height;
- fi[0].width = fi[0].width * fi.length;
- FileOpener f=new FileOpener(fi[0]);
- // only show when not interlaced
- ImagePlus ip=f.open(false);
- if (ip==null) return;
- // Only used for de-interlacing:
- ip.setCalibration(this.cal);
- // Assemble the opened images in one big stack
- ImageStack stackOld = ip.getStack();
+ // Deinterlace if interlaced
+ // stackOld contains ch1 (t,z ??), ch2 (t,z ??) etc..
+ if (interlaced) {
+ IJ.showStatus ("Deinterlacing ICS file...");
+ int width = fi[0].width;
+ int height = fi[0].height;
+ fi[0].width = fi[0].width * fi.length;
+ FileOpener f=new FileOpener(fi[0]);
+ // only show when not interlaced
+ ImagePlus ip=f.open(false);
+ if (ip==null) return;
+ // Only used for de-interlacing:
+ ip.setCalibration(this.cal);
+ // Assemble the opened images in one big stack
+ ImageStack stackOld = ip.getStack();
- int dimension = fi[0].width * fi[0].height;
- int nChannels = fi.length;
- int nSlices = ip.getImageStackSize();
- short[] pixelsOld; //old stack data is read and processed one slice at a time
- short[][][] pixelsNew = new short[nSlices][nChannels][dimension];
- int xNew, yNew;
- // get pixels from old stack and deinterlace into new array
- for (int slice=1; slice<=nSlices; slice++) {
- //IJ.write(slice + " ");
- pixelsOld = (short[])stackOld.getPixels(slice);
- int pixNum = 0;
- for (int ch=0; ch < nChannels; ch++) {
- for (int j=0; j< (dimension); j++) {
- xNew=pixNum%(nChannels);
- yNew=(int)Math.floor(pixNum/(nChannels) );
- //IJ.write(xNew + ", " + yNew);
- // short value = pixelsOld[j];
- //if (yNew >= (width * height))
- //IJ.write (yNew + ", " + ch + ", " + pixNum);
- pixelsNew[slice-1][xNew][yNew]=pixelsOld[j];
- pixNum++;
- }
- }
- IJ.showProgress(slice, nSlices);
- }
- // order in the new de-interlaced array is still the same:
- // ch1 (t,z ???) ch2 (t,z ???), etc..
- // create new Image stack
- // when there are more than MAX_CHANNELS present them in a single stack
- // else split them out
- if (nChannels >= MAX_CHANNELS) {
- FileOpener fo=new FileOpener(fi[0]);
- ImageStack stackNew = new ImageStack(width, height, fo.createColorModel(fi[0]));
- for (int slice=0; slice<nSlices; slice++) {
- Integer sliceCount=new Integer(slice+1);
- for (int ch=0; ch < nChannels; ch++) {
- stackNew.addSlice(sliceCount.toString(),pixelsNew[slice][ch]);
- }
- IJ.showProgress(slice, nSlices);
- }
- ImagePlus impNew = new ImagePlus(fi[0].fileName.substring(0,fi[0].fileName.length()-4)+" ch: ", stackNew);
- impNew.getProcessor().resetMinAndMax();
- impNew.show();
- } else { // less than MAX_CHANNELS channels
+ int dimension = fi[0].width * fi[0].height;
+ int nChannels = fi.length;
+ int nSlices = ip.getImageStackSize();
+ short[] pixelsOld; //old stack data is read and processed one slice at a time
+ short[][][] pixelsNew = new short[nSlices][nChannels][dimension];
+ int xNew, yNew;
+ // get pixels from old stack and deinterlace into new array
+ for (int slice=1; slice<=nSlices; slice++) {
+ //IJ.write(slice + " ");
+ pixelsOld = (short[])stackOld.getPixels(slice);
+ int pixNum = 0;
+ for (int ch=0; ch < nChannels; ch++) {
+ for (int j=0; j< (dimension); j++) {
+ xNew=pixNum%(nChannels);
+ yNew=(int)Math.floor(pixNum/(nChannels) );
+ //IJ.write(xNew + ", " + yNew);
+ // short value = pixelsOld[j];
+ //if (yNew >= (width * height))
+ //IJ.write (yNew + ", " + ch + ", " + pixNum);
+ pixelsNew[slice-1][xNew][yNew]=pixelsOld[j];
+ pixNum++;
+ }
+ }
+ IJ.showProgress(slice, nSlices);
+ }
+ // order in the new de-interlaced array is still the same:
+ // ch1 (t,z ???) ch2 (t,z ???), etc..
+ // create new Image stack
+ // when there are more than MAX_CHANNELS present them in a single stack
+ // else split them out
+ if (nChannels >= MAX_CHANNELS) {
+ FileOpener fo=new FileOpener(fi[0]);
+ ImageStack stackNew = new ImageStack(width, height, fo.createColorModel(fi[0]));
+ for (int slice=0; slice<nSlices; slice++) {
+ Integer sliceCount=new Integer(slice+1);
+ for (int ch=0; ch < nChannels; ch++) {
+ stackNew.addSlice(sliceCount.toString(),pixelsNew[slice][ch]);
+ }
+ IJ.showProgress(slice, nSlices);
+ }
+ ImagePlus impNew = new ImagePlus(fi[0].fileName.substring(0,fi[0].fileName.length()-4)+" ch: ", stackNew);
+ impNew.getProcessor().resetMinAndMax();
+ impNew.show();
+ } else { // less than MAX_CHANNELS channels
for (int ch=0; ch < nChannels; ch++) {
if (!selectedChannels[ch]) {
continue;
}
- Integer chCount=new Integer(ch+1);
- FileOpener fo=new FileOpener(fi[ch]);
- ImageStack stackNew = new ImageStack(width, height,fo.createColorModel(fi[ch]));
- // assign new pixel array to new stack
- for (int i=0; i< nSlices; i++) {
- Integer sliceCount=new Integer(i+1);
- stackNew.addSlice(sliceCount.toString(),pixelsNew[i][ch]);
- }
+ Integer chCount=new Integer(ch+1);
+ FileOpener fo=new FileOpener(fi[ch]);
+ ImageStack stackNew = new ImageStack(width, height,fo.createColorModel(fi[ch]));
+ // assign new pixel array to new stack
+ for (int i=0; i< nSlices; i++) {
+ Integer sliceCount=new Integer(i+1);
+ stackNew.addSlice(sliceCount.toString(),pixelsNew[i][ch]);
+ }
String filename = fi[ch].fileName.substring(0,fi[ch].fileName.length()-4)+" ch "+chCount.toString()+".tif";
- ImagePlus impNew = new ImagePlus(filename, stackNew);
+ ImagePlus impNew = new ImagePlus(filename, stackNew);
FileSaver fileSaver = new FileSaver(impNew);
File file = new File(this.directory, filename);
fileSaver.saveAsTiff(file.getPath());
- impNew.getProcessor().resetMinAndMax();
- //impNew.show();
- }
- }
- }
- IJ.showStatus ("Done opening ICS file...");
+ impNew.getProcessor().resetMinAndMax();
+ //impNew.show();
+ }
+ }
+ }
+ IJ.showStatus ("Done opening ICS file...");
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.