Class ImageExtractor


  • public class ImageExtractor
    extends Object
    Extract sub-images from an image.
    • Constructor Detail

      • ImageExtractor

        public ImageExtractor​(String filePath)
                       throws IOException
        Init from a path.
        Parameters:
        filePath - Path to the file.
        Throws:
        IOException - Throws if the file can't be accessed.
    • Method Detail

      • getPageCount

        public int getPageCount()
        Returns:
        The number of pages in the file.
      • extractImagesFromPage

        public <FieldT extends PositionDataList<ExtractedImage> extractImagesFromPage​(List<FieldT> fields,
                                                                                        int pageIndex)
        Extract multiple images on a given page from a list of fields having position data.
        Type Parameters:
        FieldT - Type of field (needs to support positioning data).
        Parameters:
        fields - List of Fields to extract.
        pageIndex - The page index to extract, begins at 0.
        Returns:
        A list of ExtractedImage.
      • extractImagesFromPage

        public <FieldT extends PositionDataList<ExtractedImage> extractImagesFromPage​(List<FieldT> fields,
                                                                                        int pageIndex,
                                                                                        String outputName)
        Extract multiple images on a given page from a list of fields having position data.
        Type Parameters:
        FieldT - Type of field (needs to support positioning data).
        Parameters:
        fields - List of Fields to extract.
        pageIndex - The page index to extract, begins at 0.
        outputName - The base output filename, must have an image extension.
        Returns:
        A list of ExtractedImage.
      • extractImage

        public <FieldT extends PositionDataExtractedImage extractImage​(FieldT field,
                                                                         int pageIndex,
                                                                         int index,
                                                                         String filename)
        Extract a single image from a field having position data.
        Type Parameters:
        FieldT - Type of field (needs to support positioning data).
        Parameters:
        field - The field to extract.
        index - The index to use for naming the extracted image.
        filename - Name of the file.
        pageIndex - The page index to extract, begins at 0.
        Returns:
        The ExtractedImage, or null if the field does not have valid position data.
      • extractImage

        public <FieldT extends PositionDataExtractedImage extractImage​(FieldT field,
                                                                         int pageIndex,
                                                                         int index)
        Extract a single image from a field having position data.
        Type Parameters:
        FieldT - Type of field (needs to support positioning data).
        Parameters:
        field - The field to extract.
        index - The index to use for naming the extracted image.
        pageIndex - The page index to extract, begins at 0.
        Returns:
        The ExtractedImage, or null if the field does not have valid position data.