Changeset 3177
- Timestamp:
- 09/19/07 10:55:41 (12 years ago)
- Location:
- trunk/loci
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/loci/formats/FormatTools.java
r3175 r3177 326 326 for (int i=0; i<lengths.length; i++) len *= lengths[i]; 327 327 return len; 328 } 329 330 public static int getReorderedIndex(IFormatReader r, String order, int no) 331 throws FormatException 332 { 333 int[] zct = getZCTCoords(order, r.getSizeZ(), r.getSizeC(), r.getSizeT(), 334 r.getImageCount(), no); 335 return getIndex(r.getDimensionOrder(), r.getSizeZ(), r.getSizeC(), 336 r.getSizeT(), r.getImageCount(), zct[0], zct[1], zct[2]); 328 337 } 329 338 -
trunk/loci/plugins/Importer.java
r3139 r3177 62 62 63 63 private Vector imps = new Vector(); 64 private String stackOrder = null; 64 65 65 66 // -- Constructor -- … … 381 382 382 383 int q = 0; 384 stackOrder = options.getStackOrder(); 385 if (stackOrder.equals(ImporterOptions.ORDER_DEFAULT)) { 386 stackOrder = r.getDimensionOrder(); 387 } 388 if (options.isViewView5D()) { 389 stackOrder = ImporterOptions.ORDER_XYZCT; 390 } 391 if (options.isViewImage5D()) { 392 stackOrder = ImporterOptions.ORDER_XYCZT; 393 } 394 383 395 for (int j=0; j<num[i]; j++) { 384 396 if (!load[j]) continue; … … 394 406 IJ.showProgress((double) q++ / total); 395 407 408 int ndx = FormatTools.getReorderedIndex(r, stackOrder, j); 409 396 410 // construct label for this slice 397 int[] zct = r.getZCTCoords( j);411 int[] zct = r.getZCTCoords(ndx); 398 412 StringBuffer sb = new StringBuffer(); 399 413 if (certain[i]) { … … 439 453 440 454 // get image processor for jth plane 441 ImageProcessor ip = Util.openProcessor(r, j);455 ImageProcessor ip = Util.openProcessor(r, ndx); 442 456 if (ip == null) { 443 457 plugin.canceled = true; … … 626 640 } 627 641 642 int[][] indices = new int[c][is.getSize() / c]; 643 int[] pt = new int[c]; 644 Arrays.fill(pt, 0); 645 646 for (int i=0; i<is.getSize(); i++) { 647 int[] zct = FormatTools.getZCTCoords(stackOrder, r.getSizeZ(), 648 r.getSizeC(), r.getSizeT(), r.getImageCount(), i); 649 int cndx = zct[1]; 650 indices[cndx][pt[cndx]++] = i; 651 } 652 628 653 for (int i=0; i<c; i++) { 629 654 if (range) { … … 636 661 } 637 662 else { 638 for (int j=0; j<z; j++) { 639 for (int k=0; k<t; k++) { 640 int s = r.getIndex(j, i, k) + 1; 641 newStacks[i].addSlice(is.getSliceLabel(s), is.getProcessor(s)); 642 } 663 for (int j=0; j<indices[i].length; j++) { 664 newStacks[i].addSlice(is.getSliceLabel(indices[i][j] + 1), 665 is.getProcessor(indices[i][j] + 1)); 643 666 } 644 667 } … … 719 742 } 720 743 catch (ReflectException exc) { 721 imp = new CustomImage(imp, r.getDimensionOrder(), r.getSizeZ(),744 imp = new CustomImage(imp, stackOrder, r.getSizeZ(), 722 745 r.getSizeT(), r.getSizeC()); 723 746 } 724 747 } 725 748 else { 726 imp = new CustomImage(imp, r.getDimensionOrder(), r.getSizeZ(),749 imp = new CustomImage(imp, stackOrder, r.getSizeZ(), 727 750 r.getSizeT(), r.getSizeC()); 728 751 } … … 753 776 if (options.isViewBrowser()) { } 754 777 else if (options.isViewImage5D()) { 755 int sizeZ = r.getSizeZ();756 int sizeT = r.getSizeT();757 int sizeC = r.getSizeC();758 if (imp.getStackSize() == sizeZ * sizeT) sizeC = 1;759 760 // reorder stack to Image5D's preferred order: XYCZT761 ImageStack is;762 ImageStack stack = imp.getStack();763 if (r.getDimensionOrder().equals("XYCZT")) is = stack;764 else {765 is = new ImageStack(r.getSizeX(), r.getSizeY());766 for (int t=0; t<sizeT; t++) {767 for (int z=0; z<sizeZ; z++) {768 for (int c=0; c<sizeC; c++) {769 int ndx = r.getIndex(z, c, t) + 1;770 is.addSlice(stack.getSliceLabel(ndx), stack.getProcessor(ndx));771 }772 }773 }774 }775 776 778 ReflectedUniverse ru = new ReflectedUniverse(); 777 779 try { 778 780 ru.exec("import i5d.Image5D"); 779 781 ru.setVar("title", imp.getTitle()); 780 ru.setVar("stack", i s);781 ru.setVar("sizeC", sizeC);782 ru.setVar("sizeZ", sizeZ);783 ru.setVar("sizeT", sizeT);782 ru.setVar("stack", imp.getStack()); 783 ru.setVar("sizeC", r.getSizeC()); 784 ru.setVar("sizeZ", r.getSizeZ()); 785 ru.setVar("sizeT", r.getSizeT()); 784 786 ru.exec("i5d = new Image5D(title, stack, sizeC, sizeZ, sizeT)"); 785 787 ru.setVar("cal", imp.getCalibration()); … … 797 799 } 798 800 else if (options.isViewView5D()) { 799 int sizeZ = r.getSizeZ();800 int sizeC = r.getSizeC();801 int sizeT = r.getSizeT();802 if (imp.getStackSize() == sizeZ * sizeT) sizeC = 1;803 ChannelMerger ndxReader = new ChannelMerger(r);804 805 // reorder stack to View5D's preferred order: XYZCT806 if (!r.getDimensionOrder().equals("XYZCT")) {807 ImageStack is = new ImageStack(r.getSizeX(), r.getSizeY());808 ImageStack stack = imp.getStack();809 for (int t=0; t<sizeT; t++) {810 for (int c=0; c<sizeC; c++) {811 for (int z=0; z<sizeZ; z++) {812 int ndx = mergeChannels ? ndxReader.getIndex(z, c, t) + 1 :813 r.getIndex(z, c, t) + 1;814 is.addSlice(stack.getSliceLabel(ndx), stack.getProcessor(ndx));815 }816 }817 }818 imp.setStack(imp.getTitle(), is);819 }820 801 WindowManager.setTempCurrentImage(imp); 821 802 IJ.run("View5D ", ""); … … 867 848 int sizeT = r.getSizeT(); 868 849 869 for (int z=0; z<sizeZ; z++) { 870 for (int t=0; t<sizeT; t++) { 871 byte[][] bytes = new byte[c][]; 872 for (int ch=0; ch<r.getSizeC()/c; ch++) { 873 for (int ch1=0; ch1<c; ch1++) { 874 int ndx = r.getIndex(z, ch*c + ch1, t) + 1; 875 bytes[ch1] = (byte[]) s.getProcessor(ndx).getPixels(); 876 } 877 ColorProcessor cp = new ColorProcessor(s.getWidth(), s.getHeight()); 878 cp.setRGB(bytes[0], bytes[1], bytes.length == 3 ? bytes[2] : 879 new byte[s.getWidth() * s.getHeight()]); 880 int ndx = r.getIndex(z, ch*c, t) + 1; 881 newStack.addSlice(s.getSliceLabel(ndx), cp); 882 } 883 } 884 } 850 int[][] indices = new int[c][s.getSize() / c]; 851 int[] pt = new int[c]; 852 Arrays.fill(pt, 0); 853 854 for (int i=0; i<s.getSize(); i++) { 855 int[] zct = FormatTools.getZCTCoords(stackOrder, sizeZ, r.getSizeC(), 856 sizeT, r.getImageCount(), i); 857 int cndx = zct[1]; 858 indices[cndx][pt[cndx]++] = i; 859 } 860 861 for (int i=0; i<indices[0].length; i++) { 862 ColorProcessor cp = new ColorProcessor(s.getWidth(), s.getHeight()); 863 byte[][] bytes = new byte[indices.length][]; 864 for (int j=0; j<indices.length; j++) { 865 bytes[j] = (byte[]) s.getProcessor(indices[j][i] + 1).getPixels(); 866 } 867 cp.setRGB(bytes[0], bytes[1], bytes.length == 3 ? bytes[2] : 868 new byte[s.getWidth() * s.getHeight()]); 869 newStack.addSlice(s.getSliceLabel( 870 indices[indices.length - 1][i] + 1), cp); 871 } 872 885 873 imp.setStack(imp.getTitle(), newStack); 886 874 } -
trunk/loci/plugins/ImporterOptions.java
r3015 r3177 64 64 public static final String VIEW_VIEW_5D = "View5D"; 65 65 66 // enumeration for stackOrder 67 public static final String ORDER_DEFAULT = "Default"; 68 public static final String ORDER_XYZCT = "XYZCT"; 69 public static final String ORDER_XYZTC = "XYZTC"; 70 public static final String ORDER_XYCZT = "XYCZT"; 71 public static final String ORDER_XYTCZ = "XYTCZ"; 72 public static final String ORDER_XYCTZ = "XYCTZ"; 73 public static final String ORDER_XYTZC = "XYTZC"; 74 66 75 public static final String MERGE_DEFAULT = "Do not merge"; 67 76 … … 82 91 // keys for use in IJ_Prefs.txt 83 92 public static final String PREF_STACK = "bioformats.stackFormat"; 93 public static final String PREF_ORDER = "bioformats.stackOrder"; 84 94 public static final String PREF_MERGE = "bioformats.mergeChannels"; 85 95 public static final String PREF_COLORIZE = "bioformats.colorize"; … … 94 104 // labels for user dialog; when trimmed these double as argument & macro keys 95 105 public static final String LABEL_STACK = "View stack with: "; 106 public static final String LABEL_ORDER = "Stack order: "; 96 107 public static final String LABEL_MERGE = "Merge channels to RGB"; 97 108 public static final String LABEL_COLORIZE = "Colorize channels"; … … 111 122 112 123 private Choice stackChoice; 124 private Choice orderChoice; 113 125 private Checkbox mergeBox; 114 126 private Checkbox colorizeBox; … … 123 135 124 136 private String stackFormat; 137 private String stackOrder; 125 138 private boolean mergeChannels; 126 139 private boolean colorize; … … 144 157 145 158 public String getStackFormat() { return stackFormat; } 159 public String getStackOrder() { return stackOrder; } 146 160 public boolean isMergeChannels() { return mergeChannels; } 147 161 public boolean isColorize() { return colorize; } … … 175 189 176 190 public void setStackFormat(String s) { stackFormat = s; } 191 public void setStackOrder(String s) { stackOrder = s; } 177 192 public void setMergeChannels(boolean b) { mergeChannels = b; } 178 193 public void setColorize(boolean b) { colorize = b; } … … 187 202 public void loadPreferences() { 188 203 stackFormat = Prefs.get(PREF_STACK, VIEW_STANDARD); 204 stackOrder = Prefs.get(PREF_ORDER, ORDER_DEFAULT); 189 205 mergeChannels = Prefs.get(PREF_MERGE, false); 190 206 colorize = Prefs.get(PREF_COLORIZE, false); … … 201 217 public void savePreferences() { 202 218 Prefs.set(PREF_STACK, stackFormat); 219 Prefs.set(PREF_ORDER, stackOrder); 203 220 Prefs.set(PREF_MERGE, mergeChannels); 204 221 Prefs.set(PREF_COLORIZE, colorize); … … 390 407 stackTypes.copyInto(stackFormats); 391 408 409 String[] stackOrders = new String[] { 410 ORDER_DEFAULT, ORDER_XYZCT, ORDER_XYZTC, ORDER_XYCZT, ORDER_XYCTZ, 411 ORDER_XYTZC, ORDER_XYTCZ 412 }; 413 392 414 // prompt user for parameters (or grab from macro options) 393 415 GenericDialog gd = new GenericDialog("Bio-Formats Import Options"); 394 416 gd.addChoice(LABEL_STACK, stackFormats, stackFormat); 417 gd.addChoice(LABEL_ORDER, stackOrders, stackOrder); 395 418 gd.addCheckbox(LABEL_MERGE, mergeChannels); 396 419 gd.addCheckbox(LABEL_COLORIZE, colorize); … … 405 428 if (choices != null) { 406 429 stackChoice = (Choice) choices.get(0); 430 orderChoice = (Choice) choices.get(1); 407 431 for (int i=0; i<choices.size(); i++) { 408 432 ((Choice) choices.get(i)).addItemListener(this); … … 427 451 428 452 stackFormat = stackFormats[gd.getNextChoiceIndex()]; 453 stackOrder = stackOrders[gd.getNextChoiceIndex()]; 429 454 mergeChannels = gd.getNextBoolean(); 430 455 colorize = gd.getNextBoolean();
Note: See TracChangeset
for help on using the changeset viewer.