Java Array Compare createStainMask(float[] redOD, float[] greenOD, float[] blueOD, double stainThreshold, boolean excludeGray, boolean excludeUncommonColors, boolean[] mask)

Here you can find the source of createStainMask(float[] redOD, float[] greenOD, float[] blueOD, double stainThreshold, boolean excludeGray, boolean excludeUncommonColors, boolean[] mask)

Description

create Stain Mask

License

Open Source License

Declaration

public static boolean[] createStainMask(float[] redOD, float[] greenOD, float[] blueOD, double stainThreshold,
            boolean excludeGray, boolean excludeUncommonColors, boolean[] mask) 

Method Source Code


//package com.java2s;
/*-/*w  ww. ja  va 2  s . c  o m*/
 * #%L
 * This file is part of QuPath.
 * %%
 * Copyright (C) 2014 - 2016 The Queen's University of Belfast, Northern Ireland
 * Contact: IP Management (ipmanagement@qub.ac.uk)
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */

import java.util.Arrays;

public class Main {
    public static boolean[] createStainMask(float[] redOD, float[] greenOD, float[] blueOD, double stainThreshold,
            boolean excludeGray, boolean excludeUncommonColors, boolean[] mask) {
        if (mask == null) {
            mask = new boolean[redOD.length];
            Arrays.fill(mask, true);
        }

        double gray = 1 / Math.sqrt(3);
        double grayThreshold = Math.cos(0.2);
        for (int i = 0; i < mask.length; i++) {

            double r = redOD[i];
            double g = greenOD[i];
            double b = blueOD[i];

            //         if (r + g + b < stainThreshold)
            //            mask[i] = false;

            // All colors must exceed threshold
            if (r < stainThreshold || g < stainThreshold || b < stainThreshold)
                mask[i] = false;
            else if (excludeGray) {
                double norm = Math.sqrt(r * r + g * g + b * b);
                if (r * gray + g * gray + b * gray >= grayThreshold * norm)
                    mask[i] = false;
            } else if (excludeUncommonColors && ((g < r && r <= b) || (g <= b && b < r))) {
                // Remove colors that can easily be determined as far from the expected pink/purple/brown of common stains in pathology
                // See http://en.wikipedia.org/wiki/Hue (inverted for ODs)
                mask[i] = false;
            }

            //         if (r + g + b < stainThreshold)
            //            mask[i] = false;
            //         else if (r*gray + g*gray + b*gray > grayThreshold)
            //            mask[i] = false;
            //         else if (excludeUncommonColors &&
            //               !((g > r && r >= b) || (g >= b && b > r))) {
            //            // Remove colors that can easily be determined as far from the expected pink/purple/brown of common stains in pathology
            //            mask[i] = false;
            //         }

        }

        return mask;
    }
}

Related

  1. arrayCompare(byte[] b1, byte[] b2)
  2. arrayCompare(final T[] a, final T[] b)
  3. arrayCompare(int[] arr1, int[] arr2)
  4. arrayCompareLex(byte[] a, byte[] b)
  5. arrayContentsEq(Object[] a1, Object[] a2)
  6. getLongestCommonSubsequence(int[] a, int[] b)
  7. getRelativeSegments(String[] targetPath, int commonSegments, int discardedSegments)
  8. longestCommonPrefix(String[] stringArray)
  9. longestCommonSubsequence(E[] s1, E[] s2)