Here you can find the source of normalizeMatrix(float[] cm)
Parameter | Description |
---|---|
cm | The matrix to be normalized. |
public static void normalizeMatrix(float[] cm)
//package com.java2s; /*//from ww w . j a va 2s . co m Copyright 2005, 2006 by Gerald Friedland and Kristian Jantz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ public class Main { /** * Normalizes the matrix to values to [0..1]. * * @param cm The matrix to be normalized. */ public static void normalizeMatrix(float[] cm) { float max = 0.0f; for (int i = 0; i < cm.length; i++) { if (max < cm[i]) { max = cm[i]; } } if (max <= 0.0) { return; } else if (max == 1.00) { return; } final float alpha = 1.00f / max; premultiplyMatrix(alpha, cm); } /** * Multiplies matrix with the given scalar. * * @param alpha The scalar value. * @param cm The matrix of values be multiplied with alpha. */ public static void premultiplyMatrix(float alpha, float[] cm) { for (int i = 0; i < cm.length; i++) { cm[i] = alpha * cm[i]; } } }