2

有人知道 C# 的图像处理库,它的功能类似于matlab中的mat2gray函数吗?

谢谢。

4

3 回答 3

3

就像是:

public Bitmap mat2gray(int[,] mat,double? amin = null, double? amax = null){

  var sizex = mat.GetLength(0);
  var sizey = mat.GetLength(1);
  if (!amin.HasValue)
    amin = 0;
  if (!amax.HasValue)
    amax = 1;
  var ret = new Bitmap(sizex,sizey);
   for (int i=0; i< sizex;i++){
    for (int j=0; j< sizey;j++){
      int A = (int)((Math.Round(mat[i,j]-amin.Value)*(255.0/amax.Value))%amax.Value);
      ret.SetPixel(i,j,Color.FromArgb(A,A,A));
    }
}

但是 amin/amax 的东西需要一些微调

于 2011-03-24T12:13:39.593 回答
0

如果您有权访问 MATLAB Builder NE 工具箱,则另一种可能性是用于deploytool创建 mat2gray 的 .NET 接口(或您想从 C# 调用的任何其他 MATLAB 功能)。然后,您可以将参数包装为 MWArray 对象,调用 MATLAB 函数的 .NET 包装器,然后解包返回的 MWArray[] 结果。

于 2011-03-24T22:47:28.020 回答
0

您可以使用 type 关键字打印 MATLAB 函数的确切实现(内置函数除外)。

type mat2gray
于 2011-03-28T19:28:01.443 回答