Class ImageLoader

    • Constructor Detail

      • ImageLoader

        public ImageLoader()
      • ImageLoader

        public ImageLoader​(long height,
                           long width)
        Instantiate an image with the given height and width
        Parameters:
        height - the height to load*
        width - the width to load
      • ImageLoader

        public ImageLoader​(long height,
                           long width,
                           long channels)
        Instantiate an image with the given height and width
        Parameters:
        height - the height to load
        width - the width to load
        channels - the number of channels for the image*
      • ImageLoader

        public ImageLoader​(long height,
                           long width,
                           long channels,
                           boolean centerCropIfNeeded)
        Instantiate an image with the given height and width
        Parameters:
        height - the height to load
        width - the width to load
        channels - the number of channels for the image*
        centerCropIfNeeded - to crop before rescaling and converting
    • Method Detail

      • asRowVector

        public INDArray asRowVector​(BufferedImage image)
        Convert an image in to a row vector
        Parameters:
        image - the image to convert
        Returns:
        the row vector based on a rastered representation of the image
      • toRaveledTensor

        public INDArray toRaveledTensor​(File file)
        Changes the input stream in to an bgr based raveled(flattened) vector
        Parameters:
        file - the input stream to convert
        Returns:
        the raveled bgr values for this input stream
      • toRaveledTensor

        public INDArray toRaveledTensor​(InputStream is)
        Changes the input stream in to an bgr based raveled(flattened) vector
        Parameters:
        is - the input stream to convert
        Returns:
        the raveled bgr values for this input stream
      • toRaveledTensor

        public INDArray toRaveledTensor​(BufferedImage image)
        Convert an image in to a raveled tensor of the bgr values of the image
        Parameters:
        image - the image to parse
        Returns:
        the raveled tensor of bgr values
      • toBgr

        public INDArray toBgr​(File file)
        Convert an input stream to an bgr spectrum image
        Parameters:
        file - the file to convert
        Returns:
        the input stream to convert
      • toBgr

        public INDArray toBgr​(InputStream inputStream)
        Convert an input stream to an bgr spectrum image
        Parameters:
        inputStream - the input stream to convert
        Returns:
        the input stream to convert
      • toBgr

        public INDArray toBgr​(BufferedImage image)
        Convert an BufferedImage to an bgr spectrum image
        Parameters:
        image - the BufferedImage to convert
        Returns:
        the input stream to convert
      • asMatrix

        public INDArray asMatrix​(File f,
                                 boolean nchw)
                          throws IOException
        Description copied from class: BaseImageLoader
        Load an image from a file to an INDArray
        Specified by:
        asMatrix in class BaseImageLoader
        Parameters:
        f - File to load the image from
        nchw - If true: return image in NCHW/channels_first [1, channels, height width] format; if false, return in NHWC/channels_last [1, height, width, channels] format
        Returns:
        Image file as as INDArray
        Throws:
        IOException
      • asMatrix

        public INDArray asMatrix​(InputStream inputStream,
                                 boolean nchw)
                          throws IOException
        Description copied from class: BaseImageLoader
        Load an image file from an input stream to an INDArray
        Specified by:
        asMatrix in class BaseImageLoader
        Parameters:
        inputStream - Input stream to load the image from
        nchw - If true: return image in NCHW/channels_first [1, channels, height width] format; if false, return in NHWC/channels_last [1, height, width, channels] format
        Returns:
        Image file stream as as INDArray
        Throws:
        IOException
      • asMatrix

        public INDArray asMatrix​(BufferedImage image)
        Convert an BufferedImage to a matrix
        Parameters:
        image - the BufferedImage to convert
        Returns:
        the input stream to convert
      • asImageMiniBatches

        public INDArray asImageMiniBatches​(File f,
                                           int numMiniBatches,
                                           int numRowsPerSlice)
        Slices up an image in to a mini batch.
        Parameters:
        f - the file to load from
        numMiniBatches - the number of images in a mini batch
        numRowsPerSlice - the number of rows for each image
        Returns:
        a tensor representing one image as a mini batch
      • fromFile

        public int[][] fromFile​(File file)
                         throws IOException
        Load a rastered image from file
        Parameters:
        file - the file to load
        Returns:
        the rastered image
        Throws:
        IOException
      • fromFileMultipleChannels

        public int[][][] fromFileMultipleChannels​(File file)
                                           throws IOException
        Load a rastered image from file
        Parameters:
        file - the file to load
        Returns:
        the rastered image
        Throws:
        IOException
      • toBufferedImageRGB

        public void toBufferedImageRGB​(INDArray arr,
                                       BufferedImage image)
        Convert the given image to an rgb image
        Parameters:
        arr - the array to use
        image - the image to set
      • toBufferedImage

        public static BufferedImage toBufferedImage​(Image img,
                                                    int type)
        Converts a given Image into a BufferedImage
        Parameters:
        img - The Image to be converted
        type - The color model of BufferedImage
        Returns:
        The converted BufferedImage
      • toIntArrayArray

        protected int[][] toIntArrayArray​(BufferedImage image)
      • scalingIfNeed

        protected BufferedImage scalingIfNeed​(BufferedImage image,
                                              long dstHeight,
                                              long dstWidth,
                                              long dstImageType,
                                              boolean needAlpha)