O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading images

The first of these is a function to read an image from a file.

import java.awt.image.BufferedImage def loadImageFromFile(path: String): BufferedImage = {   ImageIO.read(new File(path)) }

This preceding code is available in Util.scala.

This returns an instance of a java.awt.image.BufferedImage class, which stores the image data, and provides a number of useful methods. Let's test it out by loading the first image into our Spark shell, as follows:

val aePath = "/PATH/lfw/Aaron_Eckhart/Aaron_Eckhart_0001.jpg" val aeImage = loadImageFromFile(aePath)

You should see the image details displayed in the shell.

aeImage: java.awt.image.BufferedImage = BufferedImage@f41266e: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required