Search in sources :

Example 1 with DoubleToIntFunction

use of java.util.function.DoubleToIntFunction in project qupath by qupath.

the class ColorModels method buildColorModel.

private static ColorModel buildColorModel(ColorMap colorMap, int band, double minDisplay, double maxDisplay, int alphaCountBand, double minAlpha, double maxAlpha, double alphaGamma) {
    DoubleToIntFunction alphaFun = null;
    if (alphaCountBand < 0) {
        if (alphaGamma <= 0) {
            alphaFun = null;
            alphaCountBand = -1;
        } else {
            alphaFun = ColorModelFactory.createGammaFunction(alphaGamma, minAlpha, maxAlpha);
            alphaCountBand = 0;
        }
    } else if (alphaFun == null) {
        if (alphaGamma < 0)
            alphaFun = d -> 255;
        else if (alphaGamma == 0)
            alphaFun = d -> d > minAlpha ? 255 : 0;
        else
            alphaFun = ColorModelFactory.createGammaFunction(alphaGamma, minAlpha, maxAlpha);
    }
    return ColorModelFactory.createColorModel(PixelType.FLOAT32, colorMap, band, minDisplay, maxDisplay, alphaCountBand, alphaFun);
}
Also used : Objects(java.util.Objects) ColorModel(java.awt.image.ColorModel) BufferedImage(java.awt.image.BufferedImage) ColorMap(qupath.lib.color.ColorMaps.ColorMap) PixelType(qupath.lib.images.servers.PixelType) GsonTools(qupath.lib.io.GsonTools) SubTypeAdapterFactory(qupath.lib.io.GsonTools.SubTypeAdapterFactory) DoubleToIntFunction(java.util.function.DoubleToIntFunction) DoubleToIntFunction(java.util.function.DoubleToIntFunction)

Example 2 with DoubleToIntFunction

use of java.util.function.DoubleToIntFunction in project qupath by qupath.

the class ColorModels method buildColorModel.

private static ColorModel buildColorModel(ColorMap colorMap, int band, double minDisplay, double maxDisplay, int alphaCountBand, double minAlpha, double maxAlpha, double alphaGamma) {
    DoubleToIntFunction alphaFun = null;
    if (alphaCountBand < 0) {
        if (alphaGamma <= 0) {
            alphaFun = null;
            alphaCountBand = -1;
        } else {
            alphaFun = ColorModelFactory.createGammaFunction(alphaGamma, minAlpha, maxAlpha);
            alphaCountBand = 0;
        }
    } else if (alphaFun == null) {
        if (alphaGamma < 0)
            alphaFun = d -> 255;
        else if (alphaGamma == 0)
            alphaFun = d -> d > minAlpha ? 255 : 0;
        else
            alphaFun = ColorModelFactory.createGammaFunction(alphaGamma, minAlpha, maxAlpha);
    }
    return ColorModelFactory.createColorModel(PixelType.FLOAT32, colorMap, band, minDisplay, maxDisplay, alphaCountBand, alphaFun);
}
Also used : Objects(java.util.Objects) ColorModel(java.awt.image.ColorModel) BufferedImage(java.awt.image.BufferedImage) ColorMap(qupath.lib.color.ColorMaps.ColorMap) PixelType(qupath.lib.images.servers.PixelType) GsonTools(qupath.lib.io.GsonTools) SubTypeAdapterFactory(qupath.lib.io.GsonTools.SubTypeAdapterFactory) ColorModelFactory(qupath.lib.color.ColorModelFactory) DoubleToIntFunction(java.util.function.DoubleToIntFunction) ColorMaps(qupath.lib.color.ColorMaps) DoubleToIntFunction(java.util.function.DoubleToIntFunction)

Example 3 with DoubleToIntFunction

use of java.util.function.DoubleToIntFunction in project streamex by amaembo.

the class DoubleStreamExTest method testMinMax.

@Test
public void testMinMax() {
    checkEmpty(s -> s.maxBy(Double::valueOf), s -> s.maxByInt(x -> (int) x), s -> s.maxByLong(x -> (long) x), s -> s.maxByDouble(x -> x), s -> s.minBy(Double::valueOf), s -> s.minByInt(x -> (int) x), s -> s.minByLong(x -> (long) x), s -> s.minByDouble(x -> x));
    assertEquals(9, IntStreamEx.range(5, 12).asDoubleStream().max(Comparator.comparing(String::valueOf)).getAsDouble(), 0.0);
    assertEquals(10, IntStreamEx.range(5, 12).asDoubleStream().min(Comparator.comparing(String::valueOf)).getAsDouble(), 0.0);
    assertEquals(9, IntStreamEx.range(5, 12).asDoubleStream().maxBy(String::valueOf).getAsDouble(), 0.0);
    assertEquals(10, IntStreamEx.range(5, 12).asDoubleStream().minBy(String::valueOf).getAsDouble(), 0.0);
    assertEquals(5, IntStreamEx.range(5, 12).asDoubleStream().maxByDouble(x -> 1.0 / x).getAsDouble(), 0.0);
    assertEquals(11, IntStreamEx.range(5, 12).asDoubleStream().minByDouble(x -> 1.0 / x).getAsDouble(), 0.0);
    assertEquals(29.0, DoubleStreamEx.of(15, 8, 31, 47, 19, 29).maxByInt(x -> (int) (x % 10 * 10 + x / 10)).getAsDouble(), 0.0);
    assertEquals(31.0, DoubleStreamEx.of(15, 8, 31, 47, 19, 29).minByInt(x -> (int) (x % 10 * 10 + x / 10)).getAsDouble(), 0.0);
    assertEquals(29.0, DoubleStreamEx.of(15, 8, 31, 47, 19, 29).maxByLong(x -> (long) (x % 10 * 10 + x / 10)).getAsDouble(), 0.0);
    assertEquals(31.0, DoubleStreamEx.of(15, 8, 31, 47, 19, 29).minByLong(x -> (long) (x % 10 * 10 + x / 10)).getAsDouble(), 0.0);
    Supplier<DoubleStreamEx> s = () -> DoubleStreamEx.of(1, 50, 120, 35, 130, 12, 0);
    DoubleToIntFunction intKey = x -> String.valueOf(x).length();
    DoubleToLongFunction longKey = x -> String.valueOf(x).length();
    DoubleUnaryOperator doubleKey = x -> String.valueOf(x).length();
    DoubleFunction<Integer> objKey = x -> String.valueOf(x).length();
    List<Function<DoubleStreamEx, OptionalDouble>> minFns = Arrays.asList(is -> is.minByInt(intKey), is -> is.minByLong(longKey), is -> is.minByDouble(doubleKey), is -> is.minBy(objKey));
    List<Function<DoubleStreamEx, OptionalDouble>> maxFns = Arrays.asList(is -> is.maxByInt(intKey), is -> is.maxByLong(longKey), is -> is.maxByDouble(doubleKey), is -> is.maxBy(objKey));
    minFns.forEach(fn -> assertEquals(1, fn.apply(s.get()).getAsDouble(), 0.0));
    minFns.forEach(fn -> assertEquals(1, fn.apply(s.get().parallel()).getAsDouble(), 0.0));
    maxFns.forEach(fn -> assertEquals(120, fn.apply(s.get()).getAsDouble(), 0.0));
    maxFns.forEach(fn -> assertEquals(120, fn.apply(s.get().parallel()).getAsDouble(), 0.0));
}
Also used : MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) Spliterators(java.util.Spliterators) DoubleStreamEx(one.util.streamex.DoubleStreamEx) OptionalDouble(java.util.OptionalDouble) DoubleFunction(java.util.function.DoubleFunction) Scanner(java.util.Scanner) Random(java.util.Random) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) ArrayList(java.util.ArrayList) OfDouble(java.util.PrimitiveIterator.OfDouble) Assert.assertSame(org.junit.Assert.assertSame) DoubleBinaryOperator(java.util.function.DoubleBinaryOperator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Map(java.util.Map) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Builder(java.util.stream.DoubleStream.Builder) LongStream(java.util.stream.LongStream) LongStreamEx(one.util.streamex.LongStreamEx) DoubleBuffer(java.nio.DoubleBuffer) TestHelpers.checkSpliterator(one.util.streamex.TestHelpers.checkSpliterator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DoubleToIntFunction(java.util.function.DoubleToIntFunction) DoubleStream(java.util.stream.DoubleStream) TestHelpers.streamEx(one.util.streamex.TestHelpers.streamEx) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) DoubleToLongFunction(java.util.function.DoubleToLongFunction) StreamEx(one.util.streamex.StreamEx) Assert.assertFalse(org.junit.Assert.assertFalse) IntStreamEx(one.util.streamex.IntStreamEx) Comparator(java.util.Comparator) FixMethodOrder(org.junit.FixMethodOrder) Spliterator(java.util.Spliterator) Assert.assertEquals(org.junit.Assert.assertEquals) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DoubleFunction(java.util.function.DoubleFunction) Function(java.util.function.Function) DoubleToIntFunction(java.util.function.DoubleToIntFunction) DoubleToLongFunction(java.util.function.DoubleToLongFunction) DoubleToLongFunction(java.util.function.DoubleToLongFunction) DoubleStreamEx(one.util.streamex.DoubleStreamEx) DoubleToIntFunction(java.util.function.DoubleToIntFunction) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) Test(org.junit.Test)

Aggregations

DoubleToIntFunction (java.util.function.DoubleToIntFunction)3 BufferedImage (java.awt.image.BufferedImage)2 ColorModel (java.awt.image.ColorModel)2 Objects (java.util.Objects)2 ColorMap (qupath.lib.color.ColorMaps.ColorMap)2 PixelType (qupath.lib.images.servers.PixelType)2 GsonTools (qupath.lib.io.GsonTools)2 SubTypeAdapterFactory (qupath.lib.io.GsonTools.SubTypeAdapterFactory)2 DoubleBuffer (java.nio.DoubleBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 OptionalDouble (java.util.OptionalDouble)1 OfDouble (java.util.PrimitiveIterator.OfDouble)1 Random (java.util.Random)1 Scanner (java.util.Scanner)1 Spliterator (java.util.Spliterator)1