如何将MATLAB图像处理程序转换为java?

时间:2023-02-09 14:49:01

I've written an image processing program in MATLAB which makes heavy use of the MATLAB Image Processing Toolbox, especially the morphological operations (imopen, imclose) as well as imadjust. We do a lot of spline fit operations and medfilt2 and medfilt1 a lot also.

我在MATLAB中编写了一个图像处理程序,它大量使用MATLAB图像处理工具箱,特别是形态学操作(imopen,imclose)以及imadjust。我们也做了很多样条拟合操作和medfilt2和medfilt1。

We have a client who wants us to convert this program to Java. I would like to hear a detailed description of a Java image processing library which can duplicate MATLAB's functionality in image processing and splines, especially how the interface compares with MATLAB's.

我们有一个客户希望我们将此程序转换为Java。我想听一下Java图像处理库的详细描述,它可以复制MATLAB在图像处理和样条函数中的功能,特别是界面与MATLAB的比较。

I have read about Java's Advanced Image Processing Library but I haven't been able to find any detailed documentation on it on the web. Also, the little documentation I've read about it seems to indicate that it uses a rather complex model of images, combining them into tiles and so-forth. It would be great if there was a Java library which allowed me to continue to treat gray scale images as just 2D or 3D arrays.

我已经阅读了Java的高级图像处理库,但我无法在网上找到任何详细的文档。此外,我读过的关于它的小文档似乎表明它使用了相当复杂的图像模型,将它们组合成瓷砖等等。如果有一个Java库允许我继续将灰度图像视为2D或3D数组,那将会很棒。

Also, it would be great to learn of any general gotchas in converting between MATLAB and Java.

另外,了解在MATLAB和Java之间进行转换的任何一般问题都会很棒。


Edit: our app currently segments images of a relatively simple object. It:

编辑:我们的应用程序当前分割相对简单对象的图像。它:

1. Starts with a 3D matrix of gray scale image slices representing a single area
2. Does a medfilt1 to even out each slice. 
3. Does some imopen, imclose and imadjust operations on the image to remove some fuzziness, 
4. Does some simple thresholding in various areas to find boundary points
5. Fits splines to the boundary points, 
6. Uses the 3rd dimension in various ways to further perfect the point matching, especially using medfilt2. 
7. Saves each slice with the boundary splines written in color on it. 

I should note that we're doing "spline fitting" rather than spline matching - spline fitting is a least square match with a fixed number of knots - spline matching matches the points exactly with an arbitrary number of knots. I wouldn't want to implement spline matching from more simplistic spline functions.

我应该注意到,我们正在进行“样条拟合”而不是样条匹配 - 样条拟合是一个最小平方匹配的固定数量的结 - 样条匹配精确匹配点与任意数量的结。我不想从更简单的样条函数实现样条匹配。

MATLAB's Builder JA is an option but I would like to also know what's available in pure Java as well as know what kind of overhead Builder JA involves.

MATLAB的Builder JA是一个选项,但我想知道纯Java中可用的内容,以及了解Builder JA涉及的开销类型。


Edit 2:

Note that we are doing spine fitting - using a given point's fit to the spline as a way to decide whether to eliminate it - since the data is messy, we have a multi-step point elimination process, so splines are an integral part of the algorithm. And so, since I can't find any mention of splines in JAI at all, so if anyone knows a java library offering least-square spline fitting, that would be wonderful.

请注意,我们正在进行脊柱拟合 - 使用给定点适合样条曲线作为决定是否消除它的方法 - 因为数据很乱,我们有一个多步骤点消除过程,因此样条曲线是其中不可或缺的一部分。算法。因此,由于我根本无法在JAI中找到任何样条线,所以如果有人知道提供最小二乘样条拟合的java库,那就太棒了。


Edit 2.5: We're using a least-square approximation of a set of points using splines with a fixed number of knots (0-5 knots). If we have to re-implement that, things will get dicey, since right now we're using a MATLAB contributed library for it.

编辑2.5:我们使用具有固定结节数(0-5节)的样条曲线使用一组点的最小二乘近似。如果我们必须重新实现它,事情会变得冒险,因为现在我们正在使用MATLAB贡献的库。

And we certainly don't want to revisit the algorithm. It was hard enough getting something that worked...

我们当然不想重新审视算法。得到一些有用的东西真的很难......

8 个解决方案

#1


There are several general pitfalls about converting Matlab code to Java code. I've converted Matlab to C++ code, so my advice comes from those experiences.

将Matlab代码转换为Java代码有几个常见的缺陷。我已经将Matlab转换为C ++代码,所以我的建议来自于这些经验。

  1. If you're using for loops in Matlab, in general, you're doing it wrong. Adding matrices (images, etc) is a fairly simple:

    如果你在Matlab中使用for循环,一般来说,你做错了。添加矩阵(图像等)非常简单:

    a = b + c;

    a = b + c;

    no matter the size of the image. Filtering is also a fairly straightforward call:

    无论图像的大小。过滤也是一个相当简单的电话:

    a = imfilter('median', b); #or something like this, I'm not in front of my matlab machine at the moment.

    a = imfilter('median',b); #or这样的东西,我现在不在我的matlab机器前面。

    Similar function calls exist in JAI (Java Advanced Imaging), so see if you can find them. I don't know the specifics of your median filtering requirements (I assume medfilt1 is meant to be a 3x3 local median filtering kernel, rather than a 1D filtering kernel run on the data, because that would mean that you're filtering only in one direction), so take a look at what's there in the documentation. But, if you write your own, the above addition can be as simple as a doubly-nested for loop, or a complicated class that implements something like

    JAI(Java高级成像)中存在类似的函数调用,因此请查看是否可以找到它们。我不知道你的中值过滤要求的细节(我假设medfilt1是3x3本地中值过滤内核,而不是在数据上运行的1D过滤内核,因为这意味着你只在一个过滤方向),所以看一下文档中的内容。但是,如果你自己编写,上面的添加可以像双重嵌套的for循环一样简单,或者是一个复杂的类来实现像

    MyMatrix a = MyMatrix.Add(b, c);

    MyMatrix a = MyMatrix.Add(b,c);

    My point is, the simplicity of Matlab can obscure all the design decisions you need to make in order to make this an efficient java program.

    我的观点是,Matlab的简单性可能会掩盖您需要做出的所有设计决策,以使其成为一个高效的Java程序。

  2. Remember, when you do do for loops, matlab and java have reverse row/column order. Matlab is column-major, and java is row-major. You will need to rewrite your loops to take that change into account, or else your code will be slower than it should be.

    请记住,当您为循环执行操作时,matlab和java具有反向行/列顺序。 Matlab是专栏专业,java是行专业。您需要重写您的循环以将该更改考​​虑在内,否则您的代码将比它应该更慢。

  3. Personally, I'd tend to avoid the JAI except for specific operations that I need to have accomplished. For instance, just use it for the median filtering operations and so forth. I consider using it to be an optimization, but that's just because I'm Old School and tend to write my own image processing operations first. If you take that approach, you can write your code to be exactly what you want, and then you can add in the JAI calls and make sure that the output matches what your code already does. The problem with using advanced libraries like the JAI or the Intel IPP in C++ is that there are a lot of library-specific gotchas (like tiling, or whether or not each row is allocated like a bitmap with a few extra pixels on the end, or other such details), and you don't want to be dealing with those problems while at the same time moving your code over. JAI is fast, but it's not a magic bullet; if you don't know how to use it, better to make sure that you've got something before you've got something fast.

    就个人而言,除了我需要完成的具体操作外,我倾向于避开JAI。例如,只需将其用于中值滤波操作等。我认为使用它是一种优化,但这只是因为我是Old School并且倾向于首先编写我自己的图像处理操作。如果你采用这种方法,你可以编写你想要的代码,然后你可以添加JAI调用并确保输出与你的代码已经匹配。在C ++中使用JAI或Intel IPP等高级库的问题在于,存在许多特定于库的陷阱(例如,平铺,或者每行是否像位图一样分配,最后有一些额外的像素,或其他此类细节),并且您不希望在移动代码的同时处理这些问题。 JAI很快,但它不是一个神奇的子弹;如果你不知道如何使用它,最好确保在你得到快速的东西之前得到一些东西。

  4. If I can read between the lines a little bit, it looks like you're doing some kind of segmentation on medical imaging data. I don't know what the java libraries are for reading in DICOM images are, but gdcm works well for C++ and C#, and also has java wrappers. Matlab obscures the ease of image handling, especially DICOM image handling, so you may find yourself having to learn some DICOM library in order to handle the image file manipulations. I've learned a small fraction of the DICOM standard over the years; the specification is extremely complete, perhaps overly so, but you can figure out how to do what you need to do in excruciating detail. If you're trying to do segmentations of medical data, saving the spline on the data is not the right thing to do so that your images operate with other DICOM readers. Take a look at the way contours are specified.

    如果我可以在线条之间稍微阅读,看起来你正在对医学成像数据进行某种分割。我不知道在DICOM图像中读取的Java库是什么,但gdcm适用于C ++和C#,还有java包装器。 Matlab模糊了图像处理的简易性,特别是DICOM图像处理,因此您可能会发现自己必须学习一些DICOM库才能处理图像文件操作。多年来我学到了DICOM标准的一小部分;规范非常完整,可能过于严格,但你可以弄清楚如何在令人难以忍受的细节中做你需要做的事情。如果您正在尝试对医疗数据进行分段,则将样条保存在数据上并不是正确的做法,因此您的图像可以与其他DICOM读取器一起使用。看一下轮廓的指定方式。

Edit in response to further information:

编辑以回复更多信息:

Spline Fitting is probably best done from a numerical approach rather than a library approach. There may be a way to do this in JAI, but I'm not familiar enough with the language.

样条拟合最好用数值方法而不是库方法完成。在JAI中可能有一种方法可以做到这一点,但我对语言不够熟悉。

Instead, I'd check out Numerical Recipes, specifically Chapter 3, for code on spline fitting. The code is one based, not zero based, so it requires some translation, but it's entirely doable.

相反,我会查看Numerical Recipes,特别是第3章,了解样条拟合的代码。代码是基于一个,而不是基于零,所以它需要一些翻译,但它完全可行。

If you're trying to remove noise points from a boundary, you may also want to try blurring the edges that you're originally deriving your points from. Without knowing the spline fitting you're trying to do (there are many variations), it'd be hard to recommend an exact equivalent in another language.

如果您尝试从边界移除噪点,您可能还想尝试模糊您最初从中获取点的边。如果不知道你想要做的样条拟合(有很多变化),很难推荐另一种语言的精确等价物。

Edit 2.5: If by spline fitting from a contributed library, do you mean something like this code? If worst comes to worst, you'd at least have the source code. If you do end up having to do something like this, another very useful tip is that Matlab is all doubles, nothing else unless you force it (and even then, a lot of operations don't work on non-doubles). So, you'll need to do your code in doubles as well, in order to maintain reasonable agreement. I'd also make several tests. If you do end up rewriting that code (or something like it), having a group of known inputs and expected outputs (within some reasonable margin of error, where you have to define what 'reasonable' means) will be critical in making sure that the wheel you're copying (not really reinventing) has the same rotations per distance as the original. There are probably too many paranthetical expressions in that last sentence.

编辑2.5:如果通过拟合库中的样条拟合,你的意思是这样的代码吗?如果最坏的情况发生,你至少要有源代码。如果你最终不得不做这样的事情,另一个非常有用的提示是Matlab都是双打,除非你强迫它,否则没有别的东西(即便如此,很多操作都不适用于非双打)。因此,您还需要在双打中执行代码,以保持合理的协议。我也做了几次测试。如果你最终重写了那段代码(或类似代码),那么拥有一组已知输入和预期输出(在一些合理的误差范围内,你必须定义'合理'的含义)对于确保你正在复制的*(不是真正重新发明)每个距离的旋转与原始*相同。在最后一句话中可能有太多的paranthetical表达。

Yet Another Edit: If all of the above is too much of a headache, then consider the JA builder already pointed out. Otherwise, the approach I've outlined, or something similar, will probably be where you end up.

然而另一个编辑:如果上述所有内容都太令人头疼,那么请考虑JA建设者已经指出。否则,我概述的方法或类似的方法可能就是你最终的方向。

#2


How about using the MATLAB Builder JA provided by The MathWorks itself, which is the developer of MATLAB itself.?

如何使用MathWorks本身提供的MATLAB Builder JA,它是MATLAB本身的开发人员。

#3


When I've converted MATLAB code to Java code in the past I've found the CERN COLT libraries very helpful. They won't do your image processing, but they have saved me a lot of time by making converting matrix math code very quick.

当我在过去将MATLAB代码转换为Java代码时,我发现CERN COLT库非常有用。他们不会进行图像处理,但通过快速转换矩阵数学代码,他们节省了大量时间。

#4


Without explicitly addressing the Matlab question you should look at ImageJ. This is an open source Java application with many contributed plugins for image analysis and manipulation. Median filtering is built in.

如果没有明确地解决Matlab问题,你应该看一下ImageJ。这是一个开源Java应用程序,有许多用于图像分析和操作的插件。内置中值过滤。

The biggest problem I have had with converting Matlab to Java is that you will be writing many loops to handle functions that are one line in Matlab.

我将Matlab转换为Java的最大问题是你将编写许多循环来处理Matlab中的一行函数。

If you can describe your spline operations in more detail I can most likely get you information on which ImageJ operations you need.

如果您可以更详细地描述样条操作,我很可能会向您提供有关您需要哪些ImageJ操作的信息。

Example of spline fitting in java: http://www.mste.uiuc.edu/exner/java.f/leastsquares/

java中样条拟合的示例:http://www.mste.uiuc.edu/exner/java.f/leastsquares/

#5


Just don't do it this way. I was going to recommend you find out what Weka uses to implement matrix operations (I've never used it) but I'm supposing it might not use another library for this. Even if it did, it may not be matlab-like, nor support images.

只是不要这样做。我打算建议你找出Weka用来实现矩阵运算的东西(我从未使用它),但我想它可能不会使用另一个库。即使它确实如此,也可能不像matlab,也不支持图像。

#6


You can compile a MATLAB script to have it run independently. This doesn't work in all cases but if it does, you can leave your fast MATLAB code alone and try calling the image processor from Java.

您可以编译MATLAB脚本以使其独立运行。这并不适用于所有情况,但如果确实如此,您可以单独保留快速MATLAB代码并尝试从Java调用图像处理器。

http://www.mathworks.com/products/compiler/

#7


I believe Raster.getPixels and WritableRaster.setPixels allow the kind of pixel data modification you're talking about.

我相信Raster.getPixels和WritableRaster.setPixels允许你正在谈论的那种像素数据修改。

I'm not going to pretend this port will be simple, though.

不过,我不打算假装这个端口很简单。

#8


Generally, image processing operations are time-consuming, so they are often implemented in C or C++ for the sake of speed, so it is not surprising that you are having trouble finding Java code for what you need. You may end up having to roll your own for at least some of them. The operations you have mentioned such as morphology or the median filters are well documented and are fairly simple to implement, especially when you have the matlab functions to look at and to test against.

通常,图像处理操作非常耗时,因此为了提高速度,它们通常用C或C ++实现,因此您无法找到所需内容的Java代码也就不足为奇了。您可能最终不得不为至少其中一些人推出自己的产品。您提到的操作(如形态学或中值滤波器)已有详细记录,并且实现起来相当简单,尤其是当您具有要查看和测试的matlab函数时。

#1


There are several general pitfalls about converting Matlab code to Java code. I've converted Matlab to C++ code, so my advice comes from those experiences.

将Matlab代码转换为Java代码有几个常见的缺陷。我已经将Matlab转换为C ++代码,所以我的建议来自于这些经验。

  1. If you're using for loops in Matlab, in general, you're doing it wrong. Adding matrices (images, etc) is a fairly simple:

    如果你在Matlab中使用for循环,一般来说,你做错了。添加矩阵(图像等)非常简单:

    a = b + c;

    a = b + c;

    no matter the size of the image. Filtering is also a fairly straightforward call:

    无论图像的大小。过滤也是一个相当简单的电话:

    a = imfilter('median', b); #or something like this, I'm not in front of my matlab machine at the moment.

    a = imfilter('median',b); #or这样的东西,我现在不在我的matlab机器前面。

    Similar function calls exist in JAI (Java Advanced Imaging), so see if you can find them. I don't know the specifics of your median filtering requirements (I assume medfilt1 is meant to be a 3x3 local median filtering kernel, rather than a 1D filtering kernel run on the data, because that would mean that you're filtering only in one direction), so take a look at what's there in the documentation. But, if you write your own, the above addition can be as simple as a doubly-nested for loop, or a complicated class that implements something like

    JAI(Java高级成像)中存在类似的函数调用,因此请查看是否可以找到它们。我不知道你的中值过滤要求的细节(我假设medfilt1是3x3本地中值过滤内核,而不是在数据上运行的1D过滤内核,因为这意味着你只在一个过滤方向),所以看一下文档中的内容。但是,如果你自己编写,上面的添加可以像双重嵌套的for循环一样简单,或者是一个复杂的类来实现像

    MyMatrix a = MyMatrix.Add(b, c);

    MyMatrix a = MyMatrix.Add(b,c);

    My point is, the simplicity of Matlab can obscure all the design decisions you need to make in order to make this an efficient java program.

    我的观点是,Matlab的简单性可能会掩盖您需要做出的所有设计决策,以使其成为一个高效的Java程序。

  2. Remember, when you do do for loops, matlab and java have reverse row/column order. Matlab is column-major, and java is row-major. You will need to rewrite your loops to take that change into account, or else your code will be slower than it should be.

    请记住,当您为循环执行操作时,matlab和java具有反向行/列顺序。 Matlab是专栏专业,java是行专业。您需要重写您的循环以将该更改考​​虑在内,否则您的代码将比它应该更慢。

  3. Personally, I'd tend to avoid the JAI except for specific operations that I need to have accomplished. For instance, just use it for the median filtering operations and so forth. I consider using it to be an optimization, but that's just because I'm Old School and tend to write my own image processing operations first. If you take that approach, you can write your code to be exactly what you want, and then you can add in the JAI calls and make sure that the output matches what your code already does. The problem with using advanced libraries like the JAI or the Intel IPP in C++ is that there are a lot of library-specific gotchas (like tiling, or whether or not each row is allocated like a bitmap with a few extra pixels on the end, or other such details), and you don't want to be dealing with those problems while at the same time moving your code over. JAI is fast, but it's not a magic bullet; if you don't know how to use it, better to make sure that you've got something before you've got something fast.

    就个人而言,除了我需要完成的具体操作外,我倾向于避开JAI。例如,只需将其用于中值滤波操作等。我认为使用它是一种优化,但这只是因为我是Old School并且倾向于首先编写我自己的图像处理操作。如果你采用这种方法,你可以编写你想要的代码,然后你可以添加JAI调用并确保输出与你的代码已经匹配。在C ++中使用JAI或Intel IPP等高级库的问题在于,存在许多特定于库的陷阱(例如,平铺,或者每行是否像位图一样分配,最后有一些额外的像素,或其他此类细节),并且您不希望在移动代码的同时处理这些问题。 JAI很快,但它不是一个神奇的子弹;如果你不知道如何使用它,最好确保在你得到快速的东西之前得到一些东西。

  4. If I can read between the lines a little bit, it looks like you're doing some kind of segmentation on medical imaging data. I don't know what the java libraries are for reading in DICOM images are, but gdcm works well for C++ and C#, and also has java wrappers. Matlab obscures the ease of image handling, especially DICOM image handling, so you may find yourself having to learn some DICOM library in order to handle the image file manipulations. I've learned a small fraction of the DICOM standard over the years; the specification is extremely complete, perhaps overly so, but you can figure out how to do what you need to do in excruciating detail. If you're trying to do segmentations of medical data, saving the spline on the data is not the right thing to do so that your images operate with other DICOM readers. Take a look at the way contours are specified.

    如果我可以在线条之间稍微阅读,看起来你正在对医学成像数据进行某种分割。我不知道在DICOM图像中读取的Java库是什么,但gdcm适用于C ++和C#,还有java包装器。 Matlab模糊了图像处理的简易性,特别是DICOM图像处理,因此您可能会发现自己必须学习一些DICOM库才能处理图像文件操作。多年来我学到了DICOM标准的一小部分;规范非常完整,可能过于严格,但你可以弄清楚如何在令人难以忍受的细节中做你需要做的事情。如果您正在尝试对医疗数据进行分段,则将样条保存在数据上并不是正确的做法,因此您的图像可以与其他DICOM读取器一起使用。看一下轮廓的指定方式。

Edit in response to further information:

编辑以回复更多信息:

Spline Fitting is probably best done from a numerical approach rather than a library approach. There may be a way to do this in JAI, but I'm not familiar enough with the language.

样条拟合最好用数值方法而不是库方法完成。在JAI中可能有一种方法可以做到这一点,但我对语言不够熟悉。

Instead, I'd check out Numerical Recipes, specifically Chapter 3, for code on spline fitting. The code is one based, not zero based, so it requires some translation, but it's entirely doable.

相反,我会查看Numerical Recipes,特别是第3章,了解样条拟合的代码。代码是基于一个,而不是基于零,所以它需要一些翻译,但它完全可行。

If you're trying to remove noise points from a boundary, you may also want to try blurring the edges that you're originally deriving your points from. Without knowing the spline fitting you're trying to do (there are many variations), it'd be hard to recommend an exact equivalent in another language.

如果您尝试从边界移除噪点,您可能还想尝试模糊您最初从中获取点的边。如果不知道你想要做的样条拟合(有很多变化),很难推荐另一种语言的精确等价物。

Edit 2.5: If by spline fitting from a contributed library, do you mean something like this code? If worst comes to worst, you'd at least have the source code. If you do end up having to do something like this, another very useful tip is that Matlab is all doubles, nothing else unless you force it (and even then, a lot of operations don't work on non-doubles). So, you'll need to do your code in doubles as well, in order to maintain reasonable agreement. I'd also make several tests. If you do end up rewriting that code (or something like it), having a group of known inputs and expected outputs (within some reasonable margin of error, where you have to define what 'reasonable' means) will be critical in making sure that the wheel you're copying (not really reinventing) has the same rotations per distance as the original. There are probably too many paranthetical expressions in that last sentence.

编辑2.5:如果通过拟合库中的样条拟合,你的意思是这样的代码吗?如果最坏的情况发生,你至少要有源代码。如果你最终不得不做这样的事情,另一个非常有用的提示是Matlab都是双打,除非你强迫它,否则没有别的东西(即便如此,很多操作都不适用于非双打)。因此,您还需要在双打中执行代码,以保持合理的协议。我也做了几次测试。如果你最终重写了那段代码(或类似代码),那么拥有一组已知输入和预期输出(在一些合理的误差范围内,你必须定义'合理'的含义)对于确保你正在复制的*(不是真正重新发明)每个距离的旋转与原始*相同。在最后一句话中可能有太多的paranthetical表达。

Yet Another Edit: If all of the above is too much of a headache, then consider the JA builder already pointed out. Otherwise, the approach I've outlined, or something similar, will probably be where you end up.

然而另一个编辑:如果上述所有内容都太令人头疼,那么请考虑JA建设者已经指出。否则,我概述的方法或类似的方法可能就是你最终的方向。

#2


How about using the MATLAB Builder JA provided by The MathWorks itself, which is the developer of MATLAB itself.?

如何使用MathWorks本身提供的MATLAB Builder JA,它是MATLAB本身的开发人员。

#3


When I've converted MATLAB code to Java code in the past I've found the CERN COLT libraries very helpful. They won't do your image processing, but they have saved me a lot of time by making converting matrix math code very quick.

当我在过去将MATLAB代码转换为Java代码时,我发现CERN COLT库非常有用。他们不会进行图像处理,但通过快速转换矩阵数学代码,他们节省了大量时间。

#4


Without explicitly addressing the Matlab question you should look at ImageJ. This is an open source Java application with many contributed plugins for image analysis and manipulation. Median filtering is built in.

如果没有明确地解决Matlab问题,你应该看一下ImageJ。这是一个开源Java应用程序,有许多用于图像分析和操作的插件。内置中值过滤。

The biggest problem I have had with converting Matlab to Java is that you will be writing many loops to handle functions that are one line in Matlab.

我将Matlab转换为Java的最大问题是你将编写许多循环来处理Matlab中的一行函数。

If you can describe your spline operations in more detail I can most likely get you information on which ImageJ operations you need.

如果您可以更详细地描述样条操作,我很可能会向您提供有关您需要哪些ImageJ操作的信息。

Example of spline fitting in java: http://www.mste.uiuc.edu/exner/java.f/leastsquares/

java中样条拟合的示例:http://www.mste.uiuc.edu/exner/java.f/leastsquares/

#5


Just don't do it this way. I was going to recommend you find out what Weka uses to implement matrix operations (I've never used it) but I'm supposing it might not use another library for this. Even if it did, it may not be matlab-like, nor support images.

只是不要这样做。我打算建议你找出Weka用来实现矩阵运算的东西(我从未使用它),但我想它可能不会使用另一个库。即使它确实如此,也可能不像matlab,也不支持图像。

#6


You can compile a MATLAB script to have it run independently. This doesn't work in all cases but if it does, you can leave your fast MATLAB code alone and try calling the image processor from Java.

您可以编译MATLAB脚本以使其独立运行。这并不适用于所有情况,但如果确实如此,您可以单独保留快速MATLAB代码并尝试从Java调用图像处理器。

http://www.mathworks.com/products/compiler/

#7


I believe Raster.getPixels and WritableRaster.setPixels allow the kind of pixel data modification you're talking about.

我相信Raster.getPixels和WritableRaster.setPixels允许你正在谈论的那种像素数据修改。

I'm not going to pretend this port will be simple, though.

不过,我不打算假装这个端口很简单。

#8


Generally, image processing operations are time-consuming, so they are often implemented in C or C++ for the sake of speed, so it is not surprising that you are having trouble finding Java code for what you need. You may end up having to roll your own for at least some of them. The operations you have mentioned such as morphology or the median filters are well documented and are fairly simple to implement, especially when you have the matlab functions to look at and to test against.

通常,图像处理操作非常耗时,因此为了提高速度,它们通常用C或C ++实现,因此您无法找到所需内容的Java代码也就不足为奇了。您可能最终不得不为至少其中一些人推出自己的产品。您提到的操作(如形态学或中值滤波器)已有详细记录,并且实现起来相当简单,尤其是当您具有要查看和测试的matlab函数时。