I have a 2D array (not jagged) of doubles (representing an image).
I want to crop part of it, to display, do statistics on etc.
This is what I have till now:
private double[,] subimage(double[,] image, int x1, int y1, int x2, int y2)
{
int width = Math.Abs(x2 - x1);
int height = Math.Abs(y2 - y1);
double[,] newim = new double[width, height];
int x0 = Math.Min(x1, x2);
int y0 = Math.Min(y1, y2);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
newim[i, j] = image[x0+i,y0+j];
}
}
return newim;
}
Is there some way to avoid the double-for (for in general) loop?
e.g. Python has the convenient:
newim=image[x1:x2,y1:y2]