<commit_before>//
// LociImporter.java
//

/*
LOCI Plugins for ImageJ: a collection of ImageJ plugins including the 4D
Data Browser, OME Plugin and Bio-Formats Exporter. Copyright (C) 2006
<NAME>, <NAME>, <NAME> and <NAME>.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Library General Public License for more details.

You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.plugins;

import ij.*;
import ij.gui.GenericDialog;
import ij.io.OpenDialog;
import ij.plugin.PlugIn;
import ij.process.*;
import java.awt.BorderLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.image.*;
import java.io.File;
import javax.swing.*;
import loci.formats.*;

/**
 * ImageJ plugin for the LOCI Bio-Formats package.
 *
 * @author <NAME> <EMAIL>ueden at wisc.edu
 */
public class LociImporter implements PlugIn, ItemListener {

  // -- Static fields --

  /** Flag indicating whether last operation was successful. */
  public boolean success = false;

  private JCheckBox merge = null;
  private JCheckBox newWindows = null;
  private JCheckBox stitching = null;
  private boolean mergeChannels = true;
  private boolean splitWindows = false;
  private boolean stitchFiles = true;

  // -- PlugIn API methods --

  /** Executes the plugin. */
  public synchronized void run(String arg) {
    success = false;
    boolean quiet = !"".equals(arg);

    String id = null;
    ImageReader reader = new ImageReader();

    if ((new File(arg)).exists()) {
      id = arg;

      // we still want to prompt for channel merge/split

      GenericDialog gd = new GenericDialog("LOCI Bio-Formats Import Options");
      gd.addCheckbox("Merge channels", true);
      gd.addCheckbox("Open each channel in a new window", false);
      gd.addCheckbox("Stitch together files with a similar name", true);
      gd.showDialog();
      mergeChannels = gd.getNextBoolean();
      splitWindows = gd.getNextBoolean();
      stitchFiles = gd.getNextBoolean();
    }
    else {
      JFileChooser chooser = reader.getFileChooser();

      // add some additional options to the file chooser
      JPanel panel = new JPanel(new BorderLayout());
      merge = new JCheckBox("Merge channels", true);
      newWindows = new JCheckBox("Open each channel in a new window", false);
      stitching = new JCheckBox("Stitch together files with a similar name",
        true);
      merge.addItemListener(this);
      newWindows.addItemListener(this);
      stitching.addItemListener(this);
      panel.add(merge, BorderLayout.NORTH);
      panel.add(newWindows, BorderLayout.EAST);
      panel.add(stitching, BorderLayout.SOUTH);
      chooser.setAccessory(panel);

      int rval = chooser.showOpenDialog(null);
      if (rval == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();
        if (file != null) {
          id = file.getAbsolutePath();
          OpenDialog.setDefaultDirectory(
            chooser.getCurrentDirectory().getPath());
        }
      }
    }

    if (id == null) return;
    String fileName = id.substring(id.lastIndexOf(File.separator) + 1);

    IJ.showStatus("Opening " + fileName);
    try {
      FormatReader r = (FormatReader) reader.getReader(id);
      FileStitcher fs = new FileStitcher(r);
      ChannelMerger cm = new ChannelMerger(stitchFiles ? fs : r);
      cm.setSeparated(!mergeChannels);
      int num = cm.getImageCount(id);
      ImageStack stackB = null, stackS = null, stackF = null, stackO = null;
      long start = System.currentTimeMillis();
      long time = start;
      int channels = cm.getSizeC(id);

      for (int i=0; i<num; i++) {
        // limit message update rate
        long clock = System.currentTimeMillis();
        if (clock - time >= 50) {
          IJ.showStatus("Reading plane " + (i + 1) + "/" + num);
          time = clock;
        }
        IJ.showProgress((double) i / num);
        BufferedImage img = cm.openImage(id, i);

        ImageProcessor ip = null;<commit_msg>fixed importer plugin to handle stacks with mismatched dimensions<commit_after>//
// LociImporter.java
//

/*
LOCI Plugins for ImageJ: a collection of ImageJ plugins including the 4D
Data Browser, OME Plugin and Bio-Formats Exporter. Copyright (C) 2006
<NAME>, <NAME>, <NAME> and <NAME>.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Library General Public License for more details.

You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package loci.plugins;

import ij.*;
import ij.gui.GenericDialog;
import ij.io.OpenDialog;
import ij.plugin.PlugIn;
import ij.process.*;
import java.awt.BorderLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.image.*;
import java.io.File;
import javax.swing.*;
import loci.formats.*;

/**
 * ImageJ plugin for the LOCI Bio-Formats package.
 *
 * @author <NAME> ctrueden at wisc.edu
 */
public class LociImporter implements PlugIn, ItemListener {

  // -- Static fields --

  /** Flag indicating whether last operation was successful. */
  public boolean success = false;

  private JCheckBox merge = null;
  private JCheckBox newWindows = null;
  private JCheckBox stitching = null;
  private boolean mergeChannels = true;
  private boolean splitWindows = false;
  private boolean stitchFiles = true;

  // -- PlugIn API methods --

  /** Executes the plugin. */
  public synchronized void run(String arg) {
    success = false;
    boolean quiet = !"".equals(arg);

    String id = null;
    ImageReader reader = new ImageReader();

    if ((new File(arg)).exists()) {
      id = arg;

      // we still want to prompt for channel merge/split

      GenericDialog gd = new GenericDialog("LOCI Bio-Formats Import Options");
      gd.addCheckbox("Merge channels", true);
      gd.addCheckbox("Open each channel in a new window", false);
      gd.addCheckbox("Stitch together files with a similar name", true);
      gd.showDialog();
      mergeChannels = gd.getNextBoolean();
      splitWindows = gd.getNextBoolean();
      stitchFiles = gd.getNextBoolean();
    }
    else {
      JFileChooser chooser = reader.getFileChooser();

      // add some additional options to the file chooser
      JPanel panel = new JPanel(new BorderLayout());
      merge = new JCheckBox("Merge channels", true);
      newWindows = new JCheckBox("Open each channel in a new window", false);
      stitching = new JCheckBox("Stitch together files with a similar name",
        true);
      merge.addItemListener(this);
      newWindows.addItemListener(this);
      stitching.addItemListener(this);
      panel.add(merge, BorderLayout.NORTH);
      panel.add(newWindows, BorderLayout.EAST);
      panel.add(stitching, BorderLayout.SOUTH);
      chooser.setAccessory(panel);

      int rval = chooser.showOpenDialog(null);
      if (rval == JFileChooser.APPROVE_OPTION) {
        final File file = chooser.getSelectedFile();
        if (file != null) {
          id = file.getAbsolutePath();
          OpenDialog.setDefaultDirectory(
            chooser.getCurrentDirectory().getPath());
        }
      }
    }

    if (id == null) return;
    String fileName = id.substring(id.lastIndexOf(File.separator) + 1);

    IJ.showStatus("Opening " + fileName);
    try {
      FormatReader r = (FormatReader) reader.getReader(id);
      FileStitcher fs = new FileStitcher(r);
      ChannelMerger cm = new ChannelMerger(stitchFiles ? fs : r);
      cm.setSeparated(!mergeChannels);
      int num = cm.getImageCount(id);
      ImageStack stackB = null, stackS = null, stackF = null, stackO = null;
      long start = System.currentTimeMillis();
      long time = start;
      int channels = cm.getSizeC(id);

      for (int i=0; i<num; i++) {
        // limit message update rate
        long clock = System.currentTimeMillis();
        if (clock - time >= 50) {
          IJ.showStatus("Reading plane " + (i + 1) + "/" + num);
          time = clock;
        }
        IJ.showProgress((double) i / num);
        BufferedImage img = cm.openImage(id, i);
        img = ImageTools.padImage(img, cm.getSizeX(id), cm.getSizeY(id));

        ImageProcessor ip = null;
{'fraction_non_alphanumeric': 0.10258358662613981, 'fraction_numerical': 0.005427702996092054, 'mean_word_length': 3.0964873277012006, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4914039', 'n_tokens_mistral': 2732, 'n_tokens_neox': 2603, 'n_words': 899}