Micro-Manager
注: Win10 配置 MATLAB 和 Miro-Manager 的联系,使得 MATLAB 可以调用 Miro-Manager 的内置函数。
第一步:系统环境变量配置,添加 Miro-Manager 安装路径 E:\SoftSetUp\Micro-Manager-1.4
第二步:在 MATLAB 命令行中敲入
>> edit([prefdir \'/javaclasspath.txt\']);
并将 Micro-Manager 安装路径下的 *.jar 文件加入到文本中。
E:\SoftSetUp\Micro-Manager-1.4\ij.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\bsh-2.0b4.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\clojure-1.3.0.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\clooj-0.2.7.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\commons-math-2.2.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\commons-math3-3.4.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\core.cache-0.6.2.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\core.memoize-0.5.2.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\data.json-0.1.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\formats-api-5.1.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\formats-common-5.1.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\gson-2.2.4.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\guava-17.0.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\jcommon-1.0.23.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\jfreechart-1.0.19.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\joda-time-2.2.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\kryo-2.24.0.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\logback-classic-1.1.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\logback-core-1.1.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\miglayout-core-4.2.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\miglayout-swing-4.2.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\minlog-1.2.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\MMAcqEngine.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\MMCoreJ.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\MMJ_.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\objenesis-2.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\ome-xml-5.1.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\protobuf-java-2.5.0.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\rsyntaxtextarea-2.5.2.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\serializer-2.7.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\slf4j-api-1.7.6.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\swingx-0.9.5.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\TSFProto-SVN.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\xalan-2.7.1.jar
E:\SoftSetUp\Micro-Manager-1.4\plugins\Micro-Manager\xml-apis-1.3.04.jar
第三步:在 MATLAB 中敲入
>> edit librarypath.txt
将安装路径下的 E:\SoftSetUp\Micro-Manager-1.4\ 加入该文本。
第四步:重启 MATLAB
第五步:创建 MATLAB 函数 MMsetup_javaclasspath() ,并将之存于 javaclasspath.txt 所保存的文件夹 C:\Users\gh\AppData\Roaming\MathWorks\MATLAB\R2017b 下
1 function [] = MMsetup_javaclasspath(path2MM)
2 fileList = getAllFiles(path2MM);
3 fileListJarBool = regexp(fileList,\'.jar$\',\'end\');
4 fileListJarBool = cellfun(@isempty,fileListJarBool);
5 fileListJar = fileList(~fileListJarBool);
6 fid = fopen(fullfile(prefdir,\'MMjavaclasspath.txt\'),\'w\');
7 fprintf(fid,\'<before>\r\n\');
8 cellfun(@(x) fprintf(fid,\'%s\r\n\',x), fileListJar);
9 fclose(fid);
10 %% nested directory listing ala gnovice from stackoverflow
11 % inputs and outputs are self-explanatory
12 function fileList = getAllFiles(dirName)
13 dirData = dir(dirName); % Get the data for the current directory
14 dirIndex = [dirData.isdir]; % Find the index for directories
15 fileList = {dirData(~dirIndex).name}\'; % Get a list of the files
16 if ~isempty(fileList)
17 fileList = cellfun(@(x) fullfile(dirName,x),fileList,\'UniformOutput\',false);
18 end
19 subDirs = {dirData(dirIndex).name}; % Get a list of the subdirectories
20 validIndex = ~ismember(subDirs,{\'.\',\'..\'}); % Find index of subdirectories
21 % that are not \'.\' or \'..\'
22 for iDir = find(validIndex) % Loop over valid subdirectories
23 nextDir = fullfile(dirName,subDirs{iDir}); % Get the subdirectory path
24 fileList = vertcat(fileList, getAllFiles(nextDir)); % Recursively call getAllFiles
25 end
其中 path2MM 为 E:\SoftSetUp\Micro-Manager-1.4\MMConfig_demo.cfg ,在运行 MATLAB 和 Micro-Manager 时先运行此程序,会在文件夹 C:\Users\gh\AppData\Roaming\MathWorks\MATLAB\R2017b 下生成一个txt文件 MMjavaclasspath.txt 。
第五步:调试并创建一个 Java 对象为类 MMCcore
>> import mmcorej.*;
>> mmc = CMMCore;
>> mmc.loadSystemConfiguration (\'<span style="color:#4f4f4f;">E:\SoftSetUp\Micro-Manager-1.4\</span>MMConfig_demo.cfg\');
其中 E:\SoftSetUp\Micro-Manager-1.4\MMConfig_demo.cfg 是显微镜和 Micro-Manager 之间的配置文件,依据不同的配置加载不同的文件。根据加载的配置文件,调试 MATLAB 是否能够正常调用内置函数
>> mmc.snapImage();%抓拍图
>> tipImage = mmc.getImage();
>> width = mmc.getImageWidth();
>> height = mmc.getImageHeight();
>> if mmc.getBytesPerPixel == 2
pixelType = \'uint16\';
>> else
pixelType = \'uint8\';
>> end
>> tipImage = typecast(tipImage, pixelType);
>> tipImage = reshape(tipImage, [width, height]);
>> tipImage = transpose(tipImage);
以上程序实现的功能是将显微镜的相机抓拍的图通过变换转化为可读的图像,也可以将图像保存到电脑文件夹中
>> imwrite(tipImage,\'E;\img.tif\');
到此,调试成功!
注:如要使用 MMGUI ,则使用以下代码代替第五步中的 Java 对象的创建
>> import org.micromanager.MMStudio;
>> gui = MMStudio(false);
>> gui.show;
>> mmc = gui.getCore;
>> acq = gui.getAcquisitionEngine;