当输出为数组时,如何将matlab转换为c#?
我尝试在matlab中使用surf算法,并将其转换为c#。 matlab中的算法返回坐标数组。数组的大小为[10,4]。 在c#中,我编写了一段代码,该代码在数组中没有返回正确的信息。 当我转换这个代码时,是否遗漏了什么当输出为数组时,如何将matlab转换为c#?,c#,matlab,C#,Matlab,我尝试在matlab中使用surf算法,并将其转换为c#。 matlab中的算法返回坐标数组。数组的大小为[10,4]。 在c#中,我编写了一段代码,该代码在数组中没有返回正确的信息。 当我转换这个代码时,是否遗漏了什么 private static void Main(string[] args) { Bitmap img1 = new Bitmap(Image.FromFile(@"C:\Users\cbencham\source\repos\3.jpg"))
private static void Main(string[] args)
{
Bitmap img1 = new Bitmap(Image.FromFile(@"C:\Users\cbencham\source\repos\3.jpg"));
Bitmap img2 = new Bitmap(Image.FromFile(@"C:\Users\cbencham\source\repos\4.jpg"));
//Get image dimensions
int width = img1.Width;
int height = img1.Height;
//Declare the double array of grayscale values to be read from "bitmap"
double[,] im1 = new double[width, height];
//Loop to read the data from the Bitmap image into the double array
int i, j;
for (i = 0; i < width; i++)
{
for (j = 0; j < height; j++)
{
Color pixelColor = img1.GetPixel(i, j);
double b = pixelColor.GetBrightness(); //the Brightness component
//Note that rows in C# correspond to columns in MWarray
im1.SetValue(b, i, j);
}
}
//Get image dimensions
width = img2.Width;
height = img2.Height;
//Declare the double array of grayscale values to be read from "bitmap"
double[,] im2 = new double[width, height];
//Loop to read the data from the Bitmap image into the double array
for (i = 0; i < width; i++)
{
for (j = 0; j < height; j++)
{
Color pixelColor = img2.GetPixel(i, j);
double b = pixelColor.GetBrightness(); //the Brightness component
//Note that rows in C# correspond to columns in MWarray
im2.SetValue(b, i, j);
}
}
MLApp.MLApp matlab = new MLApp.MLApp();
matlab.Execute(@"cd C:\Users\cbencham\source\repos");
object result = null;
matlab.Feval("surf", 1, out result, im1, im2);
// TODO: convert result to double Array [10,4]
for (i = 0; i < 10; i++)
{
for (j = 0; j < 4; j++)
{
Console.Write(arr[i, j]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
private static void Main(字符串[]args)
{
位图img1=新位图(Image.FromFile(@“C:\Users\cbencham\source\repos\3.jpg”);
位图img2=新位图(Image.FromFile(@“C:\Users\cbencham\source\repos\4.jpg”);
//获取图像尺寸
int width=img1.宽度;
内部高度=img1.高度;
//声明要从“位图”读取的灰度值的双数组
双精度[,]im1=新双精度[宽度,高度];
//循环将位图图像中的数据读取到双数组中
int i,j;
对于(i=0;i
}无法将对象数组转换为双数组。但为了你的目的,你不需要这样做。您只需将其强制转换为对象数组并打印其内容
var arr = result as object[,];
或
if(结果为对象[,]arr)
{
对于(i=0;i
无法将对象数组转换为双数组。但为了你的目的,你不需要这样做。您只需将其强制转换为对象数组并打印其内容
var arr = result as object[,];
或
if(结果为对象[,]arr)
{
对于(i=0;i
结果包含什么?结果包含零数组结果包含什么?结果包含零数组