Java Matrix Transpose transpose_image(Object source, int width, int height)

Here you can find the source of transpose_image(Object source, int width, int height)

Description

transposimage

License

Open Source License

Declaration

public static Object transpose_image(Object source, 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 {
    public static Object transpose_image(Object source, int width,
            int height) {
        if (source instanceof float[]) {
            float[] temp = new float[width * height];
            for (int i = 0; i < width; i++) {
                float[] temp2 = (float[]) get_image_col(source, width,
                        height, i);/*from  w  ww  .j  av  a 2  s . co m*/
                System.arraycopy(temp2, 0, temp, i * height, height);
            }
            return temp;
        } else {
            if (source instanceof short[]) {
                short[] temp = new short[width * height];
                for (int i = 0; i < width; i++) {
                    short[] temp2 = (short[]) get_image_col(source, width,
                            height, i);
                    System.arraycopy(temp2, 0, temp, i * height, height);
                }
                return temp;
            } else {
                if (source instanceof byte[]) {
                    byte[] temp = new byte[width * height];
                    for (int i = 0; i < width; i++) {
                        byte[] temp2 = (byte[]) get_image_col(source,
                                width, height, i);
                        System.arraycopy(temp2, 0, temp, i * height, height);
                    }
                    return temp;
                } else {
                    int[] temp = new int[width * height];
                    for (int i = 0; i < width; i++) {
                        int[] temp2 = (int[]) get_image_col(source, width,
                                height, i);
                        System.arraycopy(temp2, 0, temp, i * height, height);
                    }
                    return temp;
                }
            }
        }
    }

    public static Object get_image_col(Object source, int width,
            int height, int col) {
        if (source instanceof float[]) {
            float[] temp = new float[height];
            int counter = col;
            for (int i = 0; i < height; i++) {
                temp[i] = ((float[]) source)[counter];
                counter += width;
            }
            return temp;
        } else {
            if (source instanceof short[]) {
                short[] temp = new short[height];
                int counter = col;
                for (int i = 0; i < height; i++) {
                    temp[i] = ((short[]) source)[counter];
                    counter += width;
                }
                return temp;
            } else {
                if (source instanceof byte[]) {
                    byte[] temp = new byte[height];
                    int counter = col;
                    for (int i = 0; i < height; i++) {
                        temp[i] = ((byte[]) source)[counter];
                        counter += width;
                    }
                    return temp;
                } else {
                    int[] temp = new int[height];
                    int counter = col;
                    for (int i = 0; i < height; i++) {
                        temp[i] = ((int[]) source)[counter];
                        counter += width;
                    }
                    return temp;
                }
            }
        }
    }
}

Related

  1. transpose(Object[][] matrix)
  2. transpose2d(Object[][] array)
  3. transpose2DArray(Double[][] data)
  4. transpose3x3Matrix(float[][] m)
  5. transpose4x4(float m[], float t[])
  6. transposeBooleanMatrix(boolean[][] matrix)
  7. transposeInPlace(float[] src)
  8. transposeMatrix(double[][] m)
  9. transposeMatrix(double[][] m)