问题描述
我需要从Java代码中调用此MATLAB代码.该代码根据指定的聚类数量和指定的初始聚类中心对图像进行聚类(即此代码中的[176; 137]).
I need to call this MATLAB code from Java code. The code clusters an image according to the specified number of clusters and the specified initial cluster centers (i.e. [176;137] in this code).
nrows = size(a_image,1);
ncols = size(a_image,2);
double_a_2_image = double(reshape(a_image,nrows*ncols,1));
nColors = 2;
[cluster_idx_2_a cluster_center] =
kmeans(double_a_2_image,nColors,'distance','sqEuclidean','start',repmat([176;137],
[1,1,3]));
a_pixel_labels_2 = reshape(cluster_idx_2_a,nrows,ncols);
figure('Name','a* image labeled by cluster index: 2 colors'),imshow(a_pixel_labels_2,
[]);
将这段代码转换为jar文件(或.class文件)的最佳工具是什么?另一点:我需要在未安装matlab的计算机上运行生成的jar文件.可以吗?还是应该在这台机器上安装MATLAB Compiler Runtime(MCR)?
What is the best tool to convert this code into jar file (or maybe .class file)? Another point: I need to run the resulted jar file on a machine that do not have matlab installed. Is that possible or should I install MATLAB Compiler Runtime (MCR) on this machine?
推荐答案
在Google上进行的简单搜索即可为您提供以下链接: MATLAB Builder JA ,它将围绕您的MATLAB代码生成Java包装器.对于第二个问题,您将不需要它,因为包装程序将负责MATLAB代码本身.
A simple search on google gives you this link : MATLAB Builder JA, which generate a Java wrapper around your MATLAB code. And for your second question, you won't need it, as the wrapper is taking care of the MATLAB code itself.
这篇关于将MATLAB代码转换为Java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!