Java Array One Dimension to Two Dimension array2multidim(float[] arr, int width, int height)

Here you can find the source of array2multidim(float[] arr, int width, int height)

Description

converts a 1D image array to and array of rows

License

Open Source License

Parameter

Parameter Description
width a parameter
height a parameter

Return

a 2D array with [height][width] indices

Declaration

public static float[][] array2multidim(float[] arr, int width,
        int height) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Jay Unruh, Stowers Institute for Medical Research.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 ******************************************************************************/

public class Main {
    /**********************
     * converts a 1D image array to and array of rows
     * @param arr: the array/*www  .  j a v  a 2 s.  c om*/
     * @param width
     * @param height
     * @return a 2D array with [height][width] indices
     */
    public static float[][] array2multidim(float[] arr, int width,
            int height) {
        float[][] temp = new float[height][width];
        int temp2 = 0;
        for (int i = 0; i < height; i++) {
            System.arraycopy(arr, temp2, temp[i], 0, width);
            temp2 += width;
        }
        return temp;
    }
}

Related

  1. array1DTo2D(final Object data, final int bitpix, final int width, final int height)
  2. array1dTo2d(float[] in, int firstDim)
  3. array1Dto2D(int m, int n, double[] b)
  4. array1DTo2D(int[] array1D)
  5. array1Dto2D(int[] d1, int imageWidth, int imageHeight)
  6. ArrayOutOfMultiDimArray(String _sMultiDimArray[][], int _index)