MATLAB 配置 Micro-Manager

Micro-Manager

注: Win10 配置 MATLAB 和 Miro-Manager 的联系,使得 MATLAB 可以调用 Miro-Manager 的内置函数。

第一步:系统环境变量配置,添加 Miro-Manager 安装路径 E:SoftSetUpMicro-Manager-1.4

第二步:在 MATLAB 命令行中敲入

>> edit([prefdir '/javaclasspath.txt']);

并将 Micro-Manager 安装路径下的 *.jar 文件加入到文本中。

E:SoftSetUpMicro-Manager-1.4ij.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managersh-2.0b4.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerclojure-1.3.0.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerclooj-0.2.7.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managercommons-math-2.2.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managercommons-math3-3.4.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managercore.cache-0.6.2.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managercore.memoize-0.5.2.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerdata.json-0.1.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerformats-api-5.1.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerformats-common-5.1.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managergson-2.2.4.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerguava-17.0.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerjcommon-1.0.23.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerjfreechart-1.0.19.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerjoda-time-2.2.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerkryo-2.24.0.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerlogback-classic-1.1.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerlogback-core-1.1.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managermiglayout-core-4.2.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managermiglayout-swing-4.2.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerminlog-1.2.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-ManagerMMAcqEngine.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-ManagerMMCoreJ.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-ManagerMMJ_.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerobjenesis-2.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerome-xml-5.1.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerprotobuf-java-2.5.0.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Manager
syntaxtextarea-2.5.2.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerserializer-2.7.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerslf4j-api-1.7.6.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerswingx-0.9.5.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-ManagerTSFProto-SVN.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerxalan-2.7.1.jar
E:SoftSetUpMicro-Manager-1.4pluginsMicro-Managerxml-apis-1.3.04.jar

第三步:在 MATLAB 中敲入

>> edit librarypath.txt 

将安装路径下的 E:SoftSetUpMicro-Manager-1.4 加入该文本。

第四步:重启 MATLAB

第五步:创建 MATLAB 函数 MMsetup_javaclasspath() ,并将之存于 javaclasspath.txt 所保存的文件夹 C:UsersghAppDataRoamingMathWorksMATLABR2017b 下

 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>
');
 8 cellfun(@(x) fprintf(fid,'%s
',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:SoftSetUpMicro-Manager-1.4MMConfig_demo.cfg ,在运行 MATLAB 和 Micro-Manager 时先运行此程序,会在文件夹 C:UsersghAppDataRoamingMathWorksMATLABR2017b 下生成一个txt文件 MMjavaclasspath.txt 。

第五步:调试并创建一个 Java 对象为类 MMCcore

>> import mmcorej.*;
>> mmc = CMMCore;
>> mmc.loadSystemConfiguration ('<span style="color:#4f4f4f;">E:SoftSetUpMicro-Manager-1.4</span>MMConfig_demo.cfg');

其中 E:SoftSetUpMicro-Manager-1.4MMConfig_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;
原文地址:https://www.cnblogs.com/ybqjymy/p/14429707.html