Package com.github.neuralnetworks.input

Examples of com.github.neuralnetworks.input.FileImageInputProvider


    @Test
    public void testImageInputProvider() {
  String imagesPath = Thread.currentThread().getContextClassLoader().getResource("images").getPath();

  // group by pixel
  FileImageInputProvider ip = new FileImageInputProvider(new File(imagesPath));
  ip.getProperties().setScaleColors(false);
  ip.getProperties().setGroupByChannel(false);
  ip.getProperties().setParallelPreprocessing(true);

  float[] image1 = ip.getNextInput();
  assertEquals(36f, image1[3], 0f);
  assertEquals(28f, image1[4], 0f);
  assertEquals(237f, image1[5], 0f);

  float[] image2 = ip.getNextInput();
  assertEquals(36f, image2[3], 0f);
  assertEquals(28f, image2[4], 0f);
  assertEquals(237f, image2[5], 0f);

  // gropu by channel
  ip = new FileImageInputProvider(new File(imagesPath));
  ip.getProperties().setScaleColors(false);
  ip.getProperties().setGroupByChannel(true);
  ip.getProperties().setParallelPreprocessing(true);

  image1 = ip.getNextInput();
  assertEquals(237f, image1[1], 0f);
  assertEquals(28f, image1[5], 0f);
  assertEquals(36f, image1[9], 0f);

  image2 = ip.getNextInput();
  assertEquals(237f, image2[1], 0f);
  assertEquals(28f, image2[5], 0f);
  assertEquals(36f, image2[9], 0f);

  // image crop
  ip = new FileImageInputProvider(new File(imagesPath));
  ip.getProperties().setScaleColors(false);
  ip.getProperties().setGroupByChannel(true);
  ip.getProperties().setCropX(1);
  ip.getProperties().setCropY(1);
  ip.getProperties().setParallelPreprocessing(true);

  image1 = ip.getNextInput();
  assertEquals(3, image1.length, 0);

  // scale
  ip = new FileImageInputProvider(new File(imagesPath));
  ip.getProperties().setScaleColors(false);
  ip.getProperties().setGroupByChannel(true);
  ip.getProperties().setParallelPreprocessing(true);
  AffineTransform af = new AffineTransform();
  af.scale(2, 2);
  ip.getProperties().setAffineTransform(af);

  image1 = ip.getNextInput();
  assertEquals(3, image1.length, 0);

  // scale input
  ip = new FileImageInputProvider(new File(imagesPath));
  ip.getProperties().setScaleColors(true);
  ip.getProperties().setGroupByChannel(false);
  ip.getProperties().setParallelPreprocessing(true);

  image1 = ip.getNextInput();
  assertEquals(36 / 255f, image1[3], 0f);
  assertEquals(28 / 255f, image1[4], 0f);
  assertEquals(237 / 255f, image1[5], 0f);

  image2 = ip.getNextInput();
  assertEquals(36 / 255f, image2[3], 0f);
  assertEquals(28 / 255f, image2[4], 0f);
  assertEquals(237 / 255f, image2[5], 0f);
    }
View Full Code Here

TOP

Related Classes of com.github.neuralnetworks.input.FileImageInputProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.