1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| import ij.IJ;
import ij.ImagePlus;
import ij.plugin.ImageCalculator;
import ij.plugin.PlugIn;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
public class TESTPlugin_ implements PlugIn{
public void run(String arg) {
ImageCalculator ic = new ImageCalculator();
String directory = directoryChooser();
String nameimageref = fileChooser();
File[] listeFichiers;
File repertoire = new File(directory);
listeFichiers = repertoire.listFiles();
ImagePlus impbackground = new ImagePlus(nameimageref);
ImagePlus imp = new ImagePlus();
ImagePlus impResult = new ImagePlus();
for (File imgname : listeFichiers) {
imp = new ImagePlus(imgname.getPath());
impResult = ic.run("Subtract create",imp ,impbackground);
impResult.setTitle("Result_"+imp.getTitle());
saveImg(impResult, directory);
}
IJ.showStatus("Done...");
}
public void saveImg(ImagePlus imp, String path) {
String fname = path +"\\" +imp.getTitle();
IJ.save(imp, fname);
}
public String directoryChooser()
{
JFileChooser choix = new JFileChooser();
choix.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int retour = choix.showOpenDialog(new JFrame());
if(retour == JFileChooser.APPROVE_OPTION) {
return choix.getSelectedFile().getAbsolutePath();
} else {
return "Le dossier n'a pas été choisi!"; }
}
public String fileChooser()
{
JFileChooser choix = new JFileChooser();
int retour = choix.showOpenDialog(new JFrame());
if(retour == JFileChooser.APPROVE_OPTION) {
return choix.getSelectedFile().getAbsolutePath();
} else {
return "L'image n'a pas étée choisie !"; }
}
} |
Partager