Java Array Min Value findMinAndMax(float[] buffer, int pixelStride, int numBands)

Here you can find the source of findMinAndMax(float[] buffer, int pixelStride, int numBands)

Description

find Min And Max

License

Open Source License

Declaration

public static float[] findMinAndMax(float[] buffer, int pixelStride, int numBands) 

Method Source Code

//package com.java2s;
/*//from www .j a  va  2  s  . co m
 * =========================================================================
 * This file is part of NITRO
 * =========================================================================
 * 
 * (C) Copyright 2004 - 2010, General Dynamics - Advanced Information Systems
 * 
 * NITRO is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, If not,
 * see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static float[] findMinAndMax(float[] buffer, int pixelStride, int numBands) {
        float min = Float.MAX_VALUE;
        float max = -Float.MAX_VALUE;
        for (int i = 0; i < buffer.length; i += numBands) {
            for (int j = 0; j < pixelStride; ++j) {
                float value = buffer[i + j];
                if (!Float.isInfinite(value)) {
                    if (value < min)
                        min = value;
                    if (value > max)
                        max = value;
                }
            }
        }
        return new float[] { min, max };
    }

    public static double[] findMinAndMax(double[] buffer, int pixelStride, int numBands) {
        double min = Double.MAX_VALUE;
        double max = -Double.MAX_VALUE;
        for (int i = 0; i < buffer.length; i += numBands) {
            for (int j = 0; j < pixelStride; ++j) {
                double value = buffer[i + j];
                if (!Double.isInfinite(value)) {
                    if (value < min)
                        min = value;
                    if (value > max)
                        max = value;
                }
            }
        }
        return new double[] { min, max };
    }

    public static int[] findMinAndMax(short[] buffer, int pixelStride, int numBands) {
        int min = 65535;
        int max = 0;
        for (int i = 0; i < buffer.length; i += numBands) {
            for (int j = 0; j < pixelStride; ++j) {
                short value = buffer[i + j];
                if (value < min)
                    min = value;
                if (value > max)
                    max = value;
            }
        }
        return new int[] { min, max };
    }
}

Related

  1. findMin(float[] array)
  2. findMin(int[] workArray, int idx)
  3. findMin(String[] strs)
  4. findMin2(int[] workArray, int idx, int min)
  5. findMinAndMax(double[] array)
  6. findMinDiff(double[] values)
  7. findMinIndex(double[] arr, int offset, int length)
  8. maxLength(T[] array)
  9. maxMinValues(int[] array)