ImageJ:如何将 txt 文件转换为插件

Posted

技术标签:

【中文标题】ImageJ:如何将 txt 文件转换为插件【英文标题】:ImageJ: How convert txt file into a plugin 【发布时间】:2021-11-06 14:18:49 【问题描述】:

这是一个很容易有人回答的问题,但我似乎无法解决它。我下载了 Microscope_Scale 插件 (https://imagej.nih.gov/ij/plugins/microscope-scale.html) 的源代码 (.java)。我通过添加几个显微镜物镜的校准来编辑文件。我似乎无法弄清楚如何将 .txt 文件编译(?)成 ImageJ(也尝试过 FIJI)可以运行的插件。这是一个如此基本的概念,我真的不明白为什么它不起作用。

问题是如何将之前编辑的.java文件(现在是.txt文件)转换成插件?

未经编辑的 .class 文件运行良好。

非常感谢,非常感谢您的帮助!

-jh

以下是编辑后插件的代码:

import ij.plugin.filter.PlugInFilter;
import ij.process.*;
import ij.gui.*;
import ij.measure.Calibration;
import java.awt.*;
import ij.plugin.*;

public class Microscope_Scale implements  PlugInFilter 

/* DESCRIPTION & CUSTOMIZATION INSTRUCTIONS
        This plugin lets you calibrate images spatially using hard-coded arrays of magnifications,
        calibration values and length units. The calibration can optionally be set as global. After
        spatial calibration the plugin will also optionally run Wayne's new scale-bar plugin, available
        in version 1.28h. To customize the plugin for your specific microscope, edit the arrays
        between the "START EDIT" and "END EDIT" comments below. Save anywhere in the
        "plugins" directory, then use "Compile and Run" option under the "plugins" menu to create
        a java class. Restart ImageJ.
**/
        ImagePlus imp;
        private static boolean addScaleBar = false;  //  if true run scalebar plugin - available in version 1.28h
        private static boolean isGlobalCal = false; // if true, set selected calibration as the global calibration
        private static int magIndex = 4; // index of initial selected magnification in dropdown menu

/* START EDIT
        Edit the following arrays using your microscope's nominal magnification steps, the
        corresponding spatial calibration and the length units of the spatial calibration.
        Make sure the arrays are of equal length.
**/
        // nominal magnification settings of the microscope
        private static String[] mags =   "PLM_10", "PLM_25", "PLM_50", "PLM_100", "Stereo_8", "Stereo_10", "Stereo_12.5", "Stereo_16", "Stereo_20", "Stereo_25", "Stereo_30", "Stereo_35", "Comp_10", "Comp_20", "Comp_40", "Fluoro_10", "Fluoro_20", "Fluoro_40", "Fluoro_100";
        // spatial calibration for the nominal magnification settings - width of one pixel (pixelWidth)
        private static double[] xscales = 0.193, 0.077, 0.040, 0.020, 0.0066, 0.0053, 0.0043, 0.0034, 0.0027, 0.0022, 0.0018, 0.0015, 0.36337, 0.179533, 0.09107, 0.36630, 0.18450, 0.09208, 0.036144;
        // units for the spacial calibrations given in xscales array above
        private static String[] units =   "um",  "um",  "um",  "um",  "mm", "mm",  "mm",  "mm",  "mm",  "mm",  "mm",  "mm", "um", "um", "um", "um", "um", "um", "um";
/* END EDIT **/

        public int setup(String arg, ImagePlus imp) 
                this.imp = imp;
                if (imp==null)
                        IJ.noImage(); return DONE;
                return DOES_ALL;
        

        public void run(ImageProcessor ip) 
                if (doDialog()) 
                        Calibration oc = imp.getCalibration().copy();
                        oc.setUnit(units[magIndex]);
                        oc.pixelWidth=xscales[magIndex];
                        oc.pixelHeight=oc.pixelWidth;
                        if (isGlobalCal) 
                                imp.setGlobalCalibration(oc);
                                int[] list = WindowManager.getIDList();
                                if (list==null) return;
                                for (int i=0; i<list.length; i++) 
                                        ImagePlus imp2 = WindowManager.getImage(list[i]);
                                        if (imp2!=null) imp2.getWindow().repaint();
                                
                                 else 
                                imp.setGlobalCalibration(null);
                                imp.setCalibration(oc);
                                imp.getWindow().repaint();
                        
                        if (addScaleBar)
                                IJ.run("Scale Bar...");
                        
                
        

        private boolean doDialog() 
                GenericDialog gd = new GenericDialog("Scale Microscope Image...");
                gd.addChoice("Nominal Magnification", mags, mags[magIndex]);
                gd.addCheckbox("Global Calibration", isGlobalCal);
                gd.addCheckbox("Add Scale Bar", addScaleBar);
                gd.showDialog();
                if (gd.wasCanceled()) return false;
                magIndex=gd.getNextChoiceIndex();
                isGlobalCal = gd.getNextBoolean();
                addScaleBar = gd.getNextBoolean();
                return true;
        

【问题讨论】:

请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。 【参考方案1】:

我能够通过使用不同的插件包解决我的问题:显微镜测量工具 (https://imagej.net/plugins/microscope-measurement-tools)。非常容易定制目标特定的校准。请注意,此插件适用于 FIJI。

【讨论】:

以上是关于ImageJ:如何将 txt 文件转换为插件的主要内容,如果未能解决你的问题,请参考以下文章

TXT文件文字转语音有啥方法?

如何批量的把WORD文件变为TXT文件???

matlab将txt格式转成wav格式

如何把一个json文件转换成字符串

深度学习数据txt转json

请问用批处理命令如何将ANSI编码的txt文件批量转换utf8编码的?就右键另存为那种,但是量太大。