100% found this document useful (4 votes)
31 views

Download full Image Processing and Computer Vision in iOS Oge Marques ebook all chapters

Image

Uploaded by

hayekdobie5d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
31 views

Download full Image Processing and Computer Vision in iOS Oge Marques ebook all chapters

Image

Uploaded by

hayekdobie5d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Image Processing and Computer Vision in iOS Oge


Marques

https://textbookfull.com/product/image-processing-and-
computer-vision-in-ios-oge-marques/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Nonlinear Eigenproblems in Image Processing and Computer


Vision Guy Gilboa

https://textbookfull.com/product/nonlinear-eigenproblems-in-image-
processing-and-computer-vision-guy-gilboa/

textboxfull.com

Computer Vision Pattern Recognition Image Processing and


Graphics Renu Rameshan

https://textbookfull.com/product/computer-vision-pattern-recognition-
image-processing-and-graphics-renu-rameshan/

textboxfull.com

Image Processing Computer Vision and Pattern Recognition


Hamid R. Arabnia

https://textbookfull.com/product/image-processing-computer-vision-and-
pattern-recognition-hamid-r-arabnia/

textboxfull.com

Feature extraction and image processing for computer


vision Fourth Edition Aguado

https://textbookfull.com/product/feature-extraction-and-image-
processing-for-computer-vision-fourth-edition-aguado/

textboxfull.com
Computer Vision and Image Analysis Digital Image
Processing and Analysis 4th Edition Scott E Umbaugh

https://textbookfull.com/product/computer-vision-and-image-analysis-
digital-image-processing-and-analysis-4th-edition-scott-e-umbaugh/

textboxfull.com

Feature Extraction and Image Processing for Computer


Vision 4th Edition Mark Nixon

https://textbookfull.com/product/feature-extraction-and-image-
processing-for-computer-vision-4th-edition-mark-nixon/

textboxfull.com

Applied Computer Vision and Image Processing Proceedings


of ICCET 2020 Volume 1 Brijesh Iyer

https://textbookfull.com/product/applied-computer-vision-and-image-
processing-proceedings-of-iccet-2020-volume-1-brijesh-iyer/

textboxfull.com

Introduction to Visual Computing: Core Concepts in


Computer Vision, Graphics, and Image Processing 1st
Edition Aditi Majumder
https://textbookfull.com/product/introduction-to-visual-computing-
core-concepts-in-computer-vision-graphics-and-image-processing-1st-
edition-aditi-majumder/
textboxfull.com

Proceedings of 2nd International Conference on Computer


Vision Image Processing CVIP 2017 Volume 2 Bidyut B.
Chaudhuri
https://textbookfull.com/product/proceedings-of-2nd-international-
conference-on-computer-vision-image-processing-
cvip-2017-volume-2-bidyut-b-chaudhuri/
textboxfull.com
SPRINGER BRIEFS IN COMPUTER SCIENCE

Oge Marques

Image Processing
and Computer
Vision in iOS

1 23
SpringerBriefs in Computer Science

Series Editors
Stan Zdonik, Brown University, Providence, RI, USA
Shashi Shekhar, University of Minnesota, Minneapolis, MN, USA
Xindong Wu, University of Vermont, Burlington, VT, USA
Lakhmi C. Jain, University of South Australia, Adelaide, SA, Australia
David Padua, University of Illinois Urbana-Champaign, Urbana, IL, USA
Xuemin Sherman Shen, University of Waterloo, Waterloo, ON, Canada
Borko Furht, Florida Atlantic University, Boca Raton, FL, USA
V. S. Subrahmanian, Department of Computer Science, University of Maryland,
College Park, MD, USA
Martial Hebert, Carnegie Mellon University, Pittsburgh, PA, USA
Katsushi Ikeuchi, Meguro-ku, University of Tokyo, Tokyo, Japan
Bruno Siciliano, Dipartimento di Ingegneria Elettrica e delle Tecnologie
dell’Informazione, Università di Napoli Federico II, Napoli, Italy
Sushil Jajodia, George Mason University, Fairfax, VA, USA
Newton Lee, Institute for Education, Research, and Scholarships, Los Angeles,
CA, USA
SpringerBriefs present concise summaries of cutting-edge research and practical
applications across a wide spectrum of fields. Featuring compact volumes of 50 to
125 pages, the series covers a range of content from professional to academic.
Typical topics might include:
• A timely report of state-of-the art analytical techniques
• A bridge between new research results, as published in journal articles, and a
contextual literature review
• A snapshot of a hot or emerging topic
• An in-depth case study or clinical example
• A presentation of core concepts that students must understand in order to make
independent contributions
Briefs allow authors to present their ideas and readers to absorb them with minimal
time investment. Briefs will be published as part of Springer’s eBook collection,
with millions of users worldwide. In addition, Briefs will be available for individual
print and electronic purchase. Briefs are characterized by fast, global electronic
dissemination, standard publishing contracts, easy-to-use manuscript preparation
and formatting guidelines, and expedited production schedules. We aim for pub-
lication 8–12 weeks after acceptance. Both solicited and unsolicited manuscripts
are considered for publication in this series.
**Indexing: This series is indexed in Scopus, Ei-Compendex, and zbMATH **

More information about this series at http://www.springer.com/series/10028


Oge Marques

Image Processing and


Computer Vision in iOS
Oge Marques
Department of Computer & Electrical
Engineering and Computer Science
Florida Atlantic University
Boca Raton, FL, USA

ISSN 2191-5768 ISSN 2191-5776 (electronic)


SpringerBriefs in Computer Science
ISBN 978-3-030-54030-2 ISBN 978-3-030-54032-6 (eBook)
https://doi.org/10.1007/978-3-030-54032-6

© The Author(s) 2020


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of
the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology
now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication
does not imply, even in the absence of a specific statement, that such names are exempt from the relevant
protective laws and regulations and therefore free for general use.
The publisher, the authors, and the editors are safe to assume that the advice and information in this book
are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or
the editors give a warranty, expressed or implied, with respect to the material contained herein or for any
errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

This Springer imprint is published by the registered company Springer Nature Switzerland AG.
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
To Ingrid, with eternal gratitude for her
unfailing support.
Preface

This book was motivated by the synergy between two main driving forces in today’s
technological landscape: (1) the maturity and popularity of image processing and
computer vision (IPCV) techniques and algorithms; and (2) the unprecedented
success of iOS-powered mobile devices, such as iPhone and iPad. The combination
of these techniques and skills has been driving the emerging era of mobile visual
computing.
This book presents a technical overview of some of the tools and technologies
currently available for developing iOS applications with IPCV capabilities, includ-
ing the latest advances on the use of machine learning and deep learning to build
intelligent IPCV apps. Its main goal is to provide the reader a guided tour of what is
currently available and a path to successfully tackle this rather complex, but highly
rewarding, task.
This book is targeted at developers, researchers, engineers, and students who
might need a roadmap to navigate the ever-changing maze of languages, libraries,
frameworks, and APIs involved in developing IPCV applications for iOS.
The following are some of the highlights of each chapter in this book:
• Chapter 1 introduces the field of mobile visual computing and provides support-
ing facts and statistics that motivate the development of iOS apps in this space.
• Chapter 2 provides an overview of the basic steps in image processing and
computer vision as well as the main aspects of the process of developing iOS
applications for IPCV, with a particular emphasis on libraries and frameworks
related to acquiring, storing, processing, and displaying images.
• Chapter 3 introduces the Core Image library and shows the examples of using
Core Image for image filtering and face detection.
• Chapter 4 provides a quick conceptual review of Machine Learning and Deep
Learning as well as an up-to-date coverage of how to develop intelligent IPCV
apps using Core ML and Create ML.
• Chapter 5 presents Apple’s Vision Framework and shows how it can be integrated
with Core ML to develop intelligent IPCV apps.

vii
viii Preface

• Finally, Chap. 6 provides an overview of the widely popular OpenCV library,


with a special emphasis on the integration of OpenCV into iOS apps.
At the end of each chapter, I have included useful resources for the reader who
wants to go further and start developing IPCV apps for iOS. These include books,
tutorials, videos, GitHub repos, and selected examples.
Image Processing and Computer Vision remain extremely relevant fields, whose
techniques can help solve many problems and whose growth has been propelled by
many recent developments, particularly the popularization of deep-learning-based
approaches for most IPCV tasks, which—thanks to Core Image, Core ML, Create
ML, and Vision Framework—have become relatively easy to incorporate into iOS
apps. I expect that this book will fulfill its goal of serving as a preliminary reference
on these topics. Readers who want to deepen their understanding of specific topics
will find more than a hundred references to additional sources of related information
throughout the book.
I would like to express my gratitude to Christian Garbin for his comments and
suggestions on an earlier version of the manuscript; Nataliia Neshenko, Humyra
Chowdhury, and Steven Alexander for their assistance with diagrams and figures;
and Roshni Merugu for her diligent fact-checking and bibliography research.
I would also like to thank Paul Drougas and his team at Springer for their
patience, kindness, and support throughout this project.

Boca Raton, FL, USA Oge Marques


July 2020
Contents

1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 The Age of Mobile Visual Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Mobile Visual Computing and iOS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Image Processing and Computer Vision iOS App Development:
The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 Image Processing, Image Analysis, and Computer Vision . . . . . . . . . . . . . 7
2.2 The iOS Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3 Useful Frameworks, APIs, and Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.4 Learn More About It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3 Core Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Fundamental Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4 Face Detection Using Core Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.5 Auto Enhancement Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.6 Learn More About It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4 Machine Learning with Core ML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.1 Machine Learning: The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.2 The Era of Deep Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.3 Core ML Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.4 Using Pre-trained Models with Core ML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.5 Training Your Own Models with Create ML . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.6 Computer Vision and Core ML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.7 Learn More About It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

ix
x Contents

5 Computer Vision and Image Analysis with the Vision Framework . . . . . 41


5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
5.2 The Image Analysis Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
5.3 Practical Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.4 Integration with Core ML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.5 Examples of IPCV Solutions Using Vision Framework . . . . . . . . . . . . . . . 46
5.6 Learn More About It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
6 OpenCV and iOS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
6.1 OpenCV: Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
6.2 OpenCV: Fundamental Classes and Operations . . . . . . . . . . . . . . . . . . . . . . . . 53
6.3 OpenCV and iOS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
6.4 Learn More About It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Chapter 1
Introduction

1.1 Motivation

This book was motivated by two main factors: (i) the maturity and popularity
of image processing and computer vision techniques and algorithms; and (ii) the
unprecedented success of iOS-powered mobile devices, such as iPhone and iPad.
On one side of the equation lie the mature fields of digital image processing and
computer vision, whose techniques and algorithms have left the realm of exclusively
scientific pursuits and associated demanding requirements (notably, the need for
expensive, specialized hardware and software) to reach the lives of computer users
and developers of virtually all levels. Digital cameras became ubiquitous over the
past few years, to the point that we inevitably think of film-based cameras (and
tape- or disk-based camcorders) as a thing of the past. The wide availability of
image editing, retouching, and processing software helped popularize imaging terms
and increase the use of image processing techniques, e.g., posterization, gamma
correction, or Gaussian blur, to name but a few. The area of computer vision
also experienced a transition through which the most successful algorithms for
frequently used tasks have become commodities, available through libraries, several
of which are open and free for developers and users.
On the other side of the equation lies the iPhone, originally released by Apple
in 2007, which has revolutionized the smartphone industry with more than 2.2
billion units sold worldwide since then [6]. The tremendously successful iPhone
was later joined by Apple’s electronic tablet, the iPad, which—since its release in
2010—has sold more than 425 million units [5]. In their latest generations, both
the iPhone and the iPad have a wide range of rich capabilities, including built-in
camera sensors, multi-touch screen, and powerful processors, which have made it
possible to conceive and develop applications that perform rich and complex image
processing and computer vision tasks “on the go”.

© The Author(s) 2020 1


O. Marques, Image Processing and Computer Vision in iOS, SpringerBriefs in
Computer Science, https://doi.org/10.1007/978-3-030-54032-6_1
2 1 Introduction

From a developer’s standpoint, three factors combine to make the iOS a


very attractive development platform for creating image-rich applications: (i) the
devices’ rich capabilities for image and video processing; (ii) Apple’s programming
architecture and its frameworks and libraries for image and multimedia and—more
recently—machine learning; and (iii) third-party support for iOS-based develop-
ment through open APIs and libraries, such as OpenCV. As a result, more than
37,000 photography-related apps are currently available in the App store [2, 11],
with specialized subcategories such as: camera enhancement, image editing and
processing, image sharing, and image printing, among others.

1.2 The Age of Mobile Visual Computing

We live in a world where images and videos are, indeed, everywhere [20]!
Recent statistics indicate that more than 3.2 billion people have a smartphone with
camera [10]. Thanks to technological developments during the past 25 years, there
has been a significant increase in the production and consumption of visually rich
contents, including high-quality images and high-definition videos. This growth has
been accompanied by a shift towards performing many of these tasks, much of the
time, using mobile devices such as iPhone and iPad.
There is, however, a big mismatch between the processes of producing visual
resources and organizing them for further cataloguing and consumption. Production
tasks (such as capturing, producing, editing, sharing, remixing, and distributing
visual content) have become easier thanks to an extensive array of highly-capable
devices and powerful apps. Organizational tasks (such as annotating, tagging,
making sense of, searching for, and retrieving visual content), however, remain
difficult and expensive.

Image and Video Capture

Taking pictures and videos has become an easy and inexpensive task. The increasing
popularity of smartphones has made it possible to carry a photo camera and video
recorder (app) at all times. The resolution and quality of images and videos produced
with a smartphone camera are appropriate for everyday needs and even acceptable
for venturing into amateur photography. The popularization of using smartphone
cameras can be attested by the birth of a new term: iPhoneography, defined as
“the art of shooting and processing photos with an Apple iPhone” [21].
1.2 The Age of Mobile Visual Computing 3

Image and Video Editing

It has never been easier to enhance and fix a photo or perform basic video editing
(such as trimming a video clip) and today’s smartphones provide built-in features
for such tasks. If the functionality provided by the smartphone’s operating system
and built-in apps is not enough, there are plenty of options to choose from: it is
estimated that 2% [2] of the 1.85 million apps available at the Apple App store [11]
belong to the Photo and Video category, which translates to more than 37,000 iOS
apps to chose from!

Image and Video Publishing and Sharing

There are tens of websites (with companion iOS apps) for photo hosting and sharing
to choose from, including: Flickr, Google Photos, SmugMug, 500px, Dropbox, and
Amazon Prime Photos.
On the video arena, YouTube is—by far—the larger and most popular website for
hosting user-generated videos, with more than 2 billion monthly users [18], an order
of magnitude larger than one of its closest competitors, Vimeo [1]. Astonishingly
enough, more than 500 hours of video content are uploaded to YouTube every
minute [17]. The platform, which was created in 2005 (and acquired by Google
for $1.65 billion USD in late 2006), has become one of the most visited websites
in the world and a global phenomenon. Approximately 60% of mobile users in the
U.S. access YouTube via a mobile device (smartphone or tablet) [15].
When it comes to social sharing of photos, Facebook, Instagram, WhatsApp,
and Snapchat are the leading apps—at least 350 million photos are uploaded to
Facebook every day [4], and Snapchat, Instagram, and WhatsApp users (combined)
share at least 7.5 billion photos each day [8, 12, 16]. Other noteworthy players in
the space of social media sharing of images and videos include TikTok, Periscope,
and DailyMotion.

Image and Video Retrieval

Despite many technological advances in the field of Visual Information Retrieval


(VIR) [20], the tasks of searching and retrieving relevant and useful images and
videos remain rather challenging, whether we are searching for photos and videos
from our personal smartphone or the web at large. During the past few years,
however, several content-based image retrieval (CBIR) prototypes have graduated
from research labs and become commercial apps, several of which in the form of
Mobile Visual Search (MVS) [19] apps.
4 1 Introduction

MVS solutions leverage the increasing availability and popularity of smartphones


with cameras which have provided a much-needed use case for the query-by-
example (QBE) paradigm, which consists of showing an image to the app and ask
for information related to that image, such as: (i) can you find more images that look
like (or are related to) this? (ii) where can I buy this product?—or simply—(iii)
what, exactly, is this? There are, after all, numerous everyday scenarios in which
the example image is right in front of the user’s eyes and it’s extremely easy and
natural to snap a picture and use it to trigger a query. Examples of MVS apps include
CamFind [3], Google Lens (embedded in the Google app for iOS) and a growing
number of apps in which the ability to perform visual searches is embedded into
an app, such as Vivino [14] (for wine labels), and the Amazon mobile app (for
several product categories, such as books, toys, clothes, accessories, and even office
supplies).
Developers have a broad range of APIs available for embedding visual search
capabilities to their apps and websites. Examples of available APIs include:
CloudSight [7] (the search engine behind the CamFind app [3] and TapTapSee [13],
a mobile camera app designed specifically for blind and visually impaired users,
which identifies objects and speaks the identification result out loud), and Mobile-
Search [9] (from TinEye). These APIs allow the development of customer-centric
solutions for which the intelligent processing of visual information is a requirement.

1.3 Mobile Visual Computing and iOS

The field of computer vision is advancing more rapidly than ever before. Many
sophisticated algorithms for image processing and analysis have become available
as commodities, thanks to the popularization of libraries such as Core Image (see
Chap. 3) and OpenCV (see Chap. 6).
The growing use of deep learning algorithms to solve computer vision problems
has energized the field and advanced the state of the art in several areas, from image
classification to object detection and tracking, from image denoising to semantic
image segmentation. It is now possible to use sophisticated pre-trained models
for tasks such as age estimation, gender classification, and many others to build
intelligent mobile apps with relative ease (see Chaps. 4 and 5).
In summary, iOS-based devices have become a rich platform for the development
of mobile apps with rich visual computing capabilities in a wide variety of
domains, from entertainment, to healthcare, to education. Thanks to Core Image,
Core ML and the Vision Framework, the iOS ecosystem allows developers to
create amazingly rich apps with intelligent visual processing capabilities, whose
complexity is conveniently abstracted behind pre-trained models and powerful
libraries.
References 5

References

1. 20 Vimeo Statistics and Facts (2020). https://bit.ly/2O5W8wJ. Accessed: 2020-07-06.


2. Apple: most popular app store categories in June 2020, by share of available apps — Statista.
https://bit.ly/3e1tKGU. Accessed: 2020-07-06.
3. CamFind App - powered by CloudSight.ai API. Visual Search & Image Recognition API.
http://camfindapp.com/. Accessed: 2020-07-06.
4. Facebook by the Numbers (2020): Stats, Demographics & Fun Facts. https://bit.ly/38vrYfW.
Accessed: 2020-07-06.
5. How Many iPads Have Been Sold? A Breakdown by Quarter. https://bit.ly/38wV3ri. Accessed:
2020-07-06.
6. How Many iPhones Have Been Sold Worldwide? https://bit.ly/2AxNuUI. Accessed: 2020-07-
06.
7. Image Recognition API & Visual Search Results — CloudSight AI. https://cloudsight.ai/.
Accessed: 2020-07-06.
8. Instagram by the Numbers (2020): Stats, Demographics & Fun Facts. https://bit.ly/2ZBM18s.
Accessed: 2020-07-06.
9. MobileEngine: Mobile Image Recognition and Augmented Reality. https://services.tineye.
com/MobileEngine. Accessed: 2020-07-06.
10. Newzoo’s Global Mobile Market Report: Insights into the World’s 3.2 Billion Smartphone
Users, the Devices They Use & the Mobile Games They Play. https://bit.ly/38tXGKD.
Accessed: 2020-07-06.
11. Number of apps in leading app stores — Statista. https://bit.ly/38yApqF. Accessed: 2020-07-
06.
12. Snapchat by the Numbers (2020): Stats, Demographics & Fun Facts. https://bit.ly/2Z41EGx.
Accessed: 2020-07-06.
13. TapTapSee - Blind and Visually Impaired Assistive Technology. https://taptapseeapp.com/.
Accessed: 2020-07-06.
14. The Vivino App. https://www.vivino.com/app. Accessed: 2020-07-06.
15. U.S. reach of leading video platforms 2018 — Statista. https://bit.ly/321Xb9x. Accessed:
2020-07-06.
16. WhatsApp blog: Connecting one billion users every day. https://bit.ly/3iy2djH. Accessed:
2020-07-06.
17. YouTube: hours of video uploaded every minute 2019 — Statista. https://bit.ly/2ZKwnHI.
Accessed: 2020-07-06.
18. YouTube Revenue and Usage Statistics (2020). https://bit.ly/2BLbQuJs. Accessed: 2020-07-
06.
19. B. Girod, V. Chandrasekhar, D. M. Chen, N.-M. Cheung, R. Grzeszczuk, Y. Reznik, G. Takacs,
S. S. Tsai, and R. Vedantham. Mobile visual search. IEEE Signal Processing Magazine,
28(4):61–76, 2011.
20. O. Marques. Visual information retrieval: The state of the art. IT Professional, 18(4):7–9, July
2016.
21. S. Roberts. The art of iphoneography : a guide to mobile creativity. Pixiq, Asheville, 2012.
Chapter 2
Image Processing and Computer Vision
iOS App Development: The Basics

2.1 Image Processing, Image Analysis, and Computer Vision

Digital image processing can be defined as the science of modifying digital images
by means of carefully designed algorithms running on a digital computer—which,
for the sake of this book, is an iPhone or iPad.
Traditionally, image processing operations used to be classified in three lev-
els [41]:
• Low-level: primitive operations (e.g., noise reduction, contrast enhancement,
etc.) where both the input and output are images.
• Mid-level: extraction of attributes (e.g., edges, contours, regions, etc.) from
images.
• High-level: analysis and interpretation of the contents of a scene.
Since there is no universal terminology to delimit the boundaries between image
processing, image analysis, and computer vision, for the sake of this chapter we will
adopt the following convention:
• Image processing: operations where the input is an image,1 and the output is a
modified version of the image. Examples of techniques and algorithms in this
category include: denoising (Fig. 2.1), sharpening, blurring, pseudocoloring, etc.
• Image analysis: operations where the input is an image and the output is a
labeled image, where specific regions, edges, or contours from the input image
have been outlined. Examples of techniques and algorithms in this category
include: semantic segmentation (Fig. 2.2), corner detection, and edge extraction,
among many others.

1 Depending on the algorithm, the input could also be a series of (2D or 3D) images and/or one or
more videos. This is valid for all three categories described here.

© The Author(s) 2020 7


O. Marques, Image Processing and Computer Vision in iOS, SpringerBriefs in
Computer Science, https://doi.org/10.1007/978-3-030-54032-6_2
8 2 Image Processing and Computer Vision iOS App Development: The Basics

Fig. 2.1 Image processing example—denoising: (a) input image; (b) output image

Fig. 2.2 Image analysis example—semantic segmentation: relevant portions of the image have
been automatically assigned a (color-coded) label, such as pedestrian, car, road, or sky

• Computer vision: operations where the input is an image which is used by


an algorithm to perform tasks, such as object detection, object recognition,
image classification (Fig. 2.3), object tracking (across multiple frames of a video
sequence), as well as answer questions related to the semantic contents of the
image/video, e.g., how many people appear in this photo? where was it taken? etc.
When the distinction among the three categories is irrelevant we might refer
to them collectively as IPCV (image processing and computer vision) or group
them under the umbrella of intelligent processing of visual information. The IPCV
2.1 Image Processing, Image Analysis, and Computer Vision 9

Fig. 2.3 Computer vision example—image classification: an image classifier (usually a pre-
trained neural network) takes an image as input and produces the most likely label for that image

Fig. 2.4 IPCV pipeline example: original image (left), filtered (center), and subsequently cropped
(right)

pipeline (or workflow) usually consists of several operations that are chained
together in a meaningful sequence. For example, an image may be filtered and
cropped before being used as an input to an object classifier (Fig. 2.4).
During the past two decades, thanks to the popularization of libraries, frame-
works and toolboxes such as OpenCV [39] (for C++ and Python developers),
MATLAB [24] (and its toolboxes2), ImageJ [20] and Fiji [16] (for Java developers),
and many others, the building blocks of the IPCV pipeline have become commodi-
ties. More often than not—whether you are a developer, student, practitioner, or
engineer—the fundamental operations behind each stage in your IPCV pipeline are
immediately available through library functions. More recently, many of the most
sophisticated algorithms for intelligent processing of visual information have also
become available via cloud-based services and their APIs (e.g., Microsoft Azure
Cognitive Services [8], Amazon AWS [1], Google Cloud AutoML [7]) which has
led to enormous flexibility in building web-based vision applications.
Moreover, the impact of deep learning techniques on image processing and
computer vision since the successful image classification results obtained by
Krizhevsky et al. in ImageNet 2012 [40] has been so significant that there are
deep-learning-based versions of virtually every IPCV task, often achieving state-
of-the-art results for that task.3

2 Notably the Image Processing, Deep Learning, and Computer Vision toolboxes.
3 It
is commonly said that the history of computer vision will be written in two volumes: (i) before
deep learning (1950s–2012); and (ii) after deep learning (2012–present).
10 2 Image Processing and Computer Vision iOS App Development: The Basics

Most importantly for the sake of this book, the iOS ecosystem offers a rich
platform for developing IPCV apps, thanks to several frameworks, libraries, and
APIs (Sect. 2.3), particularly Core Image (Chap. 3), Core ML (Chap. 4), and the
Vision Framework (Chap. 5). Moreover, the rich functionality of OpenCV can also
be accessed by iOS apps (Chap. 6).

2.2 The iOS Development Environment

Xcode

Xcode [36] is the Integrated Development Environment (IDE) for designing, coding,
debugging, and testing iOS apps. It includes a text editor where you write the source
code that defines what your app does and a visual editor where you design your app’s
user interface [21].
Xcode also includes a compiler, a debugger, and a vast array of features for iOS
app development. You can download Xcode for free from the Mac App Store. At the
time of writing, the latest version of Xcode is Xcode 12, which assumes that you use
Swift as a programming language and includes the new SwiftUI framework [21].

Swift

In the early days of iOS programming, the language of choice was Objective-C.
Most of the code for iOS today is written in Swift. However, for legacy apps or IPCV
apps that need to interface with OpenCV (see Chap. 6), knowledge of Objective-C
and/or C++ is crucial.
The Swift programming language was announced in 2014 at Apple’s World-
wide Developers Conference (WWDC) and has become one of the most popular
programming languages since then. It supports the object-oriented and functional
programming paradigms that most programmers are comfortable with, and it also
introduces a new one: protocol-oriented programming [21].
Swift prevents many common programming errors by adopting modern program-
ming patterns, such as [32]:
• Variables are always initialized before use.
• Array indices are checked for out-of-bounds errors.
• Integers are checked for overflow.
• Optionals ensure that nil values are handled explicitly.
• Memory is managed automatically.
• Error handling allows controlled recovery from unexpected failures.
2.3 Useful Frameworks, APIs, and Libraries 11

UIKit and SwiftUI

From the very beginning of iOS programming and up to iOS 12, iOS apps were
written using the iPhone’s original user interface framework, UIKit. UIKit was
designed at a time when the general philosophy behind mobile app development
was that mobile apps are like desktop apps, but on a less-powerful computer with
a tiny screen. The overwhelming majority of iOS apps and their code are based on
UIKit [21].
iOS 13 introduced SwiftUI, a new way for iOS developers to build user
interfaces for their apps and to make it easier to port iOS apps to Apple’s other
platforms: macOS, watchOS and tvOS. If you’re new to iOS development, experts
recommend that you learn UIKit first and then transition to SwiftUI [21].

A Recipe for Success

To conclude this section, these are the suggested steps to learn the basic steps that
should lead you to become a successful developer of IPCV iOS apps.
1. Get a Mac computer. You will need a Mac to run Xcode.
2. Download and install Xcode [36].
3. Sign up with Apple to become a registered iOS developer [2].
4. Learn the basics of iOS programming using Swift.4
5. Get an iPhone and/or iPad to test your apps.5
6. Learn about useful Apple frameworks, libraries, and APIs for IPCV tasks (see
Sect. 2.3), particularly Core Image (Chap. 3), Core ML (Chap. 4), and the Vision
Framework (Chap. 5).
7. Read as much as you can (books, blogs, Apple documentation, tutorials, etc.).
8. Practice, practice, practice.

2.3 Useful Frameworks, APIs, and Libraries

This section contains a list (in alphabetical order) of the most relevant Apple frame-
works, APIs, and libraries for iOS developers working in IPCV and related areas

4 This is a potentially time-consuming step, since it involves learning a new programming language

and many software development aspects that are crucial to mobile app development. Fortunately,
there are plenty of resources online to learn them, some of which appear at then end of this chapter.
5 You can test much of the functionality of an iOS app using the iOS simulator that is bundled with

Xcode, but for certain aspects of some apps (e.g., live video capture) you must deploy and test on
a physical device.
12 2 Image Processing and Computer Vision iOS App Development: The Basics

(e.g., augmented reality, multimedia, computer graphics, games, video processing,


and machine learning), with pointers to official documentation and additional
information.

ARKit

One of the most exciting developments in mobile app development in recent years
has been the growth of Augmented Reality (AR) [4]—often called mixed reality—
apps, which allow the creation of “user experiences that add 2D or 3D elements to
the live view from a device’s camera in a way that makes those elements appear to
inhabit the real world” [3].
ARKit is a framework that combines device motion tracking, camera scene
capture, advanced scene processing, and display conveniences to simplify the task
of building an AR experience, using the front or rear camera of an iOS device [3].

AVFoundation

The AVFoundation framework combines six major technology areas to support


a broad range of tasks for handling audiovisual media on Apple platforms,
namely [5]:
• Media Assets and Metadata: load, inspect, and export media assets and metadata,
and perform low-level reading and writing of media sample data.
• Media Playback and Selection: get and inspect media assets; queue media for
playback and customize playback behavior; edit and combine assets; import and
export raw media streams.
• Cameras and Media Capture: capture photos and record video and audio;
configure built-in cameras and microphones or external capture devices.
• Media Composition and Editing: combine, edit, and remix audio and video tracks
from multiple sources in a single composition.
• Audio Playback, Recording, and Processing: play, record, and process audio;
configure your app’s system audio behavior.
• Speech Synthesis: convert text to spoken audio.

AVKit

AVKit is a framework that provides a high-level interface for playing video content,
by allowing the creation of view-level services for media playback, complete with
user controls, chapter navigation, and support for subtitles and closed captioning [6].
2.3 Useful Frameworks, APIs, and Libraries 13

Core Graphics

The Core Graphics framework is based on the Quartz advanced drawing engine
available for iOS, tvOS and macOS application development. Quartz 2D provides
low-level, lightweight 2D rendering with unmatched output fidelity. Quartz 2D is
resolution- and device-independent. You can use the Core Graphics framework to
handle path-based drawing, transformations, color management, offscreen render-
ing, patterns, gradients and shadings, image data management, image creation, and
image masking, as well as PDF document creation, display, and parsing [9].
The Quartz 2D API is easy to use and provides access to powerful features
such as transparency layers, path-based drawing, offscreen rendering, advanced
color management, anti-aliased rendering, and PDF document creation, display, and
parsing [29].

Core Image

Core Image encapsulates image processing and analysis technologies that provide
high-performance processing for still and video images. it includes many built-
in image filters that can be used to process images and build complex effects by
chaining filters [10]. Chapter 3 explores Core Image in greater detail.

Core Media

The Core Media framework defines the media pipeline used by AVFoundation
and other high-level media frameworks found on Apple platforms. You can use Core
Media’s low-level data types and interfaces to efficiently process media samples and
manage queues of media data [11].

Core ML

Core ML is a machine learning framework that allows developers to integrate


machine learning models into their apps [12]. Chapter 4 explores Core ML in greater
detail.
14 2 Image Processing and Computer Vision iOS App Development: The Basics

Core Video

Core Video provides a pipeline model for digital video. It simplifies working with
video by partitioning the process into discrete steps, which makes it easier for
developers to access and manipulate individual frames without having to worry
about translating between data types or display synchronization issues [13].

Create ML

Create ML allows developers to create and train custom machine learning models
to perform tasks such as recognizing images, extracting meaning from text, or
finding relationships between numerical values [14]. Section 4.5 provides additional
information on how to use Create ML to create intelligent iOS apps.

Image I/O

The Image I/O programming interface framework allows applications to read


and write most image file formats. This framework offers high efficiency, color
management, and access to image metadata [18].

ImageCaptureCore

The ImageCaptureCore framework, introduced in iOS 13, allows you to browse


for media devices and control them programmatically from your app [19].

Metal

Metal is a framework for leveraging the computational power of graphics processors


(GPUs) to quickly render graphics and perform data-parallel calculations. Many
high level Apple frameworks are built on top of Metal to take advantage of its
performance, including Core Image. Using one of these high-level frameworks
shields you from the details of GPU programming, but writing custom Metal code
enables you to achieve the highest level of performance [25].
2.3 Useful Frameworks, APIs, and Libraries 15

Metal Performance Shaders

The Metal Performance Shaders framework contains a collection of highly opti-


mized compute and graphics shaders that are designed to take advantage of the
unique hardware characteristics of each GPU family to ensure optimal performance.
It supports image processing operations, such as high-performance filters and
histogram-based computations [17], as well as training neural networks for machine
learning inference [33].

ML Compute

The ML Compute framework, introduced in iOS 14, can be used to accelerate


training of neural networks across the CPU or one or more available GPUs.
ML Compute uses the high performance BNNS primitives from the Accelerate
framework for the CPU and Metal Performance Shaders for the GPU [26].

OpenGL ES

The OpenGL ES framework was one of the earliest 2D and 3D graphics frameworks
in iOS. It was made available with iOS 2 and deprecated in iOS 12 in favor of the
Metal framework [27].

PhotoKit

PhotoKit provides support for building photo-editing extensions for the Photos app,
including direct access to the photo and video assets managed by the Photos app.
Using PhotoKit, you can fetch and cache assets for display and playback, edit image
and video content, or manage collections of assets such as albums, Moments, and
Shared Albums [28].

VideoToolbox

The VideoToolbox is a low-level framework that provides direct access to hardware


encoders and decoders, including services for video compression and decompres-
sion, and for conversion between raster image formats stored in CoreVideo pixel
buffers [34].
16 2 Image Processing and Computer Vision iOS App Development: The Basics

Vision

The Vision Framework [37], introduced in iOS 11, encapsulates advanced capabil-
ities for handling face detection and recognition, barcode and QR code detection,
text detection, horizon detection, image registration (alignment), as well as object
detection and tracking. It also interfaces with Core ML (Chap. 4) models for image
analysis and machine learning tasks in the same workflow. Chapter 5 explores the
Vision Framework in greater detail.

VisionKit

VisionKit is a small framework, introduced in iOS 13, that allow you to use the iOS
camera as a document scanner [35].

2.4 Learn More About It

The official Apple site for Swift contains links to numerous books, sample code
examples, videos, university courses, and official Apple documentation [31].
Ray Wanderlich’s site is a rich source for high-quality books, tutorials, courses,
and videos on iOS and mobile app development [30].
Since the early days of iOS programming, Stanford University’s CS193p (Devel-
oping Applications for iOS) course has been a reference of high-quality materials
and instructions. Slides, reading materials, and lecture videos are freely available
online [15].
For a deeper look into design patterns and app architectures (and their limitations
and alternatives), and how the same app can be implemented using a handful of
different architectures, see [38].
Two special issues of the objc.io electronic magazine remain relevant for getting
a deeper understanding of the development process behind mobile visual computing
apps in iOS:
• Issue 21: Camera and Photos [22], which covers a wide range of topics, from
image acquisition using the iPhone camera to selected frameworks, extensions,
and GPU-accelerated apps.
• Issue 23: Video [23], which extends the discussion to video capturing, filtering,
and hardware acceleration.
References 17

References

1. Amazon Web Services (AWS) Cloud Computing Services. https://aws.amazon.com/.


Accessed: 2020-07-23.
2. Apple Developer Program — Apple Developer. https://apple.co/2WPfVoW. Accessed: 2020-
07-23.
3. ARKit — Apple Developer Documentation. https://apple.co/2ZRcnEO. Accessed: 2020-07-
14.
4. Augmented Reality — Apple. https://www.apple.com/augmented-reality/. Accessed: 2020-
07-14.
5. AVFoundation — Apple Developer Documentation. https://apple.co/2ZVFyGN. Accessed:
2020-07-14.
6. AVKit — Apple Developer Documentation. https://apple.co/2WKmUQf. Accessed: 2020-07-
14.
7. Cloud AutoML— Google Cloud. https://cloud.google.com/automl. Accessed: 2020-07-23.
8. Cognitive Services: APIs for AI Developers — Microsoft Azure. https://bit.ly/3eRsuGN.
Accessed: 2020-07-23.
9. Core Graphics — Apple Developer Documentation. https://apple.co/2CK6ZdV. Accessed:
2020-07-14.
10. Core Image — Apple Developer Documentation. https://apple.co/30t8Xst. Accessed: 2020-
07-14.
11. Core Media — Apple Developer Documentation. https://apple.co/2OWsOct. Accessed: 2020-
07-14.
12. Core ML. https://apple.co/316Pf6h. Accessed: 2020-06-23.
13. Core Video — Apple Developer Documentation. https://apple.co/2EdBqto. Accessed: 2020-
07-14.
14. Create ML. https://apple.co/2VekAQy. Accessed: 2020-06-23.
15. CS193p - Developing Apps for iOS. https://cs193p.sites.stanford.edu/. Accessed: 2020-07-28.
16. Fiji: ImageJ, with “Batteries Included”. https://fiji.sc/. Accessed: 2020-07-23.
17. Image Filters — Apple Developer Documentation. https://apple.co/3eQiLjL. Accessed: 2020-
07-22.
18. Image I/O — Apple Developer Documentation. https://apple.co/3jB7lE3. Accessed:
2020-07-23.
19. ImageCaptureCore — Apple Developer Documentation. https://apple.co/2WOgmjF.
Accessed: 2020-07-23.
20. ImageJ. https://imagej.nih.gov/ij/. Accessed: 2020-07-23.
21. iOS Apprentice. https://bit.ly/30H3ZH5. Accessed: 2020-07-22.
22. Issue 21: Camera and Photos — objc.io. https://bit.ly/2EdCUUu. Accessed: 2020-07-14.
23. Issue 23: Video — objc.io. https://bit.ly/3jz7x6Z. Accessed: 2020-07-14.
24. MATLAB — MathWorks. https://www.mathworks.com/products/matlab.html. Accessed:
2020-07-23.
25. Metal — Apple Developer Documentation. https://apple.co/3hyMn7h. Accessed: 2020-07-22.
26. ML Compute — Apple Developer Documentation. https://apple.co/3fTEiJK. Accessed: 2020-
07-22.
27. OpenGL ES — Apple Developer Documentation. https://apple.co/32N1KEX. Accessed: 2020-
07-22.
28. PhotoKit — Apple Developer Documentation. https://apple.co/2BtnHxy. Accessed:
2020-07-22.
29. Quartz 2D: Introduction. https://apple.co/3eSsINS. Accessed: 2020-07-14.
30. raywenderlich.com. https://www.raywenderlich.com/. Accessed: 2020-07-28.
31. Swift — Resources — Apple Developer. https://apple.co/39kVMfN. Accessed: 2020-07-23.
32. The Swift Programming Language (Swift 5.3 beta) on Apple Books. https://apple.co/
3fY8TWD. Accessed: 2020-07-23.
18 2 Image Processing and Computer Vision iOS App Development: The Basics

33. Training a Neural Network with Metal Performance Shaders — Apple Developer Documenta-
tion. https://apple.co/3jvB9Ca. Accessed: 2020-07-22.
34. VideoToolbox — Apple Developer Documentation. https://apple.co/2Ef7xcb. Accessed: 2020-
07-22.
35. VisionKit — Apple Developer Documentation. https://apple.co/39pwEnT. Accessed: 2020-
07-22.
36. Xcode — Apple Developer. https://apple.co/2CInyXt. Accessed: 2020-07-22.
37. Apple Vision Framework. https://apple.co/37V2bxg, 2018. Accessed: 2020-06-23.
38. C. Eidhof. App architecture. objc, Berlin, Germany, 2018.
39. A. Kaehler and G. Bradski. Learning OpenCV 3: Computer Vision in C++ with the OpenCV
Library. O’Reilly Media, Inc., 2017.
40. A. Krizhevsky, I. Sutskever, and G. E. Hinton. Imagenet classification with deep convolutional
neural networks. In Advances in neural information processing systems, pages 1097–1105,
2012.
41. O. Marques. Practical Image and Video Processing Using MATLAB. Wiley - IEEE. Wiley,
2011.
Chapter 3
Core Image

3.1 Introduction

Core Image is an image processing and analysis framework for iOS and macOS.
Core Image provides a broad array of useful image processing and computer vision
(such as face- and facial features detection in images and videos, and face tracking
in videos) as well as almost 200 built-in image filters, organized into more than a
dozen categories (Sect. 3.3) [7]. Moreover, thanks to its plug-in architecture, Core
Image allows users to extend its functionality by writing custom filters that integrate
with the system-provided filters [16].

3.2 Fundamental Classes

Core Image has three classes that support image processing on iOS [8]:
• CIFilter is a mutable object that represents an effect. A filter object has at
least one input parameter and produces an output image.
• CIImage is an immutable object that represents an image, which can be
synthesized from image data, read from a file, or produced at the output of
another CIFilter object.
• CIContext is an object through which Core Image draws the results produced
by a filter. A Core Image context can be based on the CPU or the GPU.
Listing 3.1 shows the fundamental steps for processing an image using Core
Image methods specific to iOS. In line 2, a CIContext object is created with

© The Author(s) 2020 19


O. Marques, Image Processing and Computer Vision in iOS, SpringerBriefs in
Computer Science, https://doi.org/10.1007/978-3-030-54032-6_3
20 3 Core Image

1 import CoreImage
2 let context = CIContext()
3 let filter = CIFilter(name: "CISepiaTone")!
4 filter.setValue(0.8, forKey: kCIInputIntensityKey)
5 let image = CIImage(contentsOfURL: myURL)
6 filter.setValue(image, forKey: kCIInputImageKey)
7 let result = filter.outputImage!
8 let cgImage = context.createCGImage(result, from: result.extent)
Listing 3.1 The basics of applying a filter to an image on iOS [8]

default options. The code in lines 3–4 creates a filter1and sets values for its
parameters. In lines 5–6, a CIImage object representing the image to be processed
is created (in this particular case, using a URL as its source). In line 7, the output
image (another CIImage object) is produced (but not yet rendered). Finally, in line
8, the resulting image is rendered to a Core Graphics image, which can be displayed
or saved to a file [8].

3.3 Filters

Within the context of Core Image, a filter is an object that has a number of inputs
and outputs and performs some kind of transformation. For example, a sharpening
filter might take an input image and an additional (scalar) parameter indicating the
desired amount of sharpening and produce an output image with a crisper look.
A filter graph is a network (directed acyclic graph) of filters, chained together so
that the output of one filter can be used as the input of another; by chaining filters in
this way, elaborate effects can be achieved [16].
Core Image comes with dozens of built-in filters, organized into categories.2
A filter category specifies the type of effect—for example blur, color adjustment,
or halftone—or its intended use—still images, video, non-square pixels, and so on.
A filter can be a member of more than one category. A filter also has a display
name, which is the name used to show to users and a filter name, which is the
name used to access the filter programmatically. Since the list of built-in filters can
change over time, Core Image provides methods that allow for querying the system
for the available filters [8].
Most filters have one or more input parameters; each input parameter has an
attribute class that specifies its data type, such as NSNumber. An input parameter
can optionally have other attributes, such as its default value, the allowable

1 In this example, the filter is CISepiaTone, which maps the colors of an image to various shades

of brown.
2 The official Core Image Filter Reference [5] lists the filters currently available, their characteristics

and parameters, and shows a sample image produced by each filter.


Another Random Scribd Document
with Unrelated Content
too, but they have a standard doctrine, and they can trap you into a
heresy trial. But in the Baptist and Methodist Churches, man! There’s
the berth for philosophers like me and hoot-owls like you, Eddie! All
you have to do with Baptists and Methodists, as Father Carp
suggests—”
“If you agree with me about anything, I withdraw it,” said Horace.
“All you have to do,” said Zenz, “is to get some sound and
perfectly meaningless doctrine and keep repeating it. You won’t bore
the laymen—in fact the only thing they resent is something that is
new, so they have to work their brains. Oh, no, Father Carp—the
Episcopal pulpit for actors that aren’t good enough to get on the
stage, but the good old Baptist fold for realists!”
“You make me tired, Harry!” complained Eddie. “You just want to
show off, that’s all. You’re a lot better Baptist and a lot better
Christian than you let on to be, and I can prove it. Folks wouldn’t go
on listening to your sermons unless they carried conviction. No, sir!
You can fool folks once or twice with a lot of swell-sounding words
but in the long run it’s sincerity they look for. And one thing that
makes me know you’re on the right side is that you don’t practise
open communion. Golly, I feel that everything we Baptists stand for
is threatened by those darn’ so-called liberals that are beginning to
practise open communion.”
“Rats!” grumbled Harry. “Of all the fool Baptist egotisms, close
communion is the worst! Nobody but people we consider saved to be
allowed to take communion with us! Nobody can meet God unless
we introduce ’em! Self-appointed guardians of the blood and body of
Jesus Christ! Whew!”
“Absolutely,” from Horace Carp. “And there is absolutely no
Scriptural basis for close communion.”
“There certainly is!” shrieked Eddie. “Frank, where’s your Bible?”
“Gee, I left it in O. T. E. Where’s yours, Don?”
“Well, I’ll be switched! I had the darn’ thing here just this
evening,” lamented Don Pickens, after a search.
“Oh, I remember. I was killing a cockroach with it. It’s on top of
your wardrobe,” said Elmer.
“Gee, honest, you hadn’t ought to kill cockroaches with a Bible!”
mourned Eddie Fislinger. “Now here’s the Bible, good and straight,
for close communion, Harry. It says in First Corinthians, 11:27 and
29: ‘Whoever shall eat this bread and drink this cup of the Lord
unworthily shall be guilty of the body and the blood of the Lord. For
he that eateth and drinketh unworthily eateth and drinketh damnation
to himself.’ And how can there be a worthy Christian unless he’s
been baptized by immersion?”
“I do wonder sometimes,” mused Frank Shallard, “if we aren’t
rather impious, we Baptists, to set ourselves up as the keepers of
the gates of God, deciding just who is righteous, who is worthy to
commune.”
“But there’s nothing else we can do,” explained Eddie. “The
Baptist Church, being the only pure Scriptural church, is the one real
church of God, and we’re not setting ourselves up—we’re just
following God’s ordinances.”
Horace Carp had also been reveling in the popular Mizpah sport
of looking up Biblical texts to prove a preconceived opinion. “I don’t
find anything here about Baptists,” he said.
“Nor about your doggoned old Episcopalians, either—darn’
snobs!—and the preachers wearing nightshirts!” from Eddie.
“You bet your life you find something—it talks about bishops, and
that means Episcopal bishops—the papes and the Methodists are
uncanonical bishops,” rejoiced Horace. “I’ll bet you two dollars and
sixty-seven cents I wind up as an Episcopal bishop, and, believe me,
I’ll be high-church as hell—all the candles I can get on the altar.”
Harry Zenz was speculating, “I suppose it’s unscientific to believe
that because I happen to be a Baptist practitioner myself and see
what word-splitting, text-twisting, applause-hungry, job-hunting,
medieval-minded second-raters even the biggest Baptist leaders are,
therefore the Baptist Church is the worst of the lot. I don’t suppose
it’s really any worse than the Presbyterian or the Congregational or
Disciples or Lutheran or any other. But— Say, you, Fislinger, ever
occur to you how dangerous it is, this Bible-worship? You and I might
have to quit preaching and go to work. You tell the muttonheads that
the Bible contains absolutely everything necessary for salvation,
don’t you?”
“Of course.”
“Then what’s the use of having any preachers? Any church? Let
people stay home and read the Bible!”
“Well—well—it says—”
The door was dashed open, and Brother Karkis entered.
Brother Karkis was no youthful student. He was forty-three,
heavy-handed and big-footed, and his voice was the voice of a Great
Dane. Born to the farm, he had been ordained a Baptist preacher for
twenty years now, and up and down through the Dakotas, Nebraska,
Arkansas, he had bellowed in up-creek tabernacles.
His only formal education had been in country schools; and of all
books save the Bible, revivalistic hymnals, a concordance handy for
finding sermon-texts, and a manual of poultry-keeping, he was
soundly ignorant. He had never met a woman of the world, never
drunk a glass of wine, never heard a bar of great music, and his
neck was not free from the dust of cornfields.
But it would have been a waste of pity to sigh over Brother Karkis
as a plucky poor student. He had no longing for further knowledge;
he was certain that he already had it all. He despised the faculty as
book-adulterated wobblers in the faith—he could “out-pray and out-
holler and out-save the whole lot of ’em.” He desired a Mizpah
degree only because it would get him a better paid job—or, as he put
it, with the 1850 vocabulary which he found adequate for 1905,
because it would “lead him into a wider field of usefulness.”
“Say, don’t you fellers ever do anything but sit around and argue
and discuss and bellyache?” he shouted. “My lands, I can hear your
racket way down the hall! Be a lot better for you young fellers if you’d
forget your smart-aleck arguin’ and spend the evening on your knees
in prayer! Oh, you’re a fine lot of smart educated swells, but you’ll
find where that rubbish gets you when you go out and have to
wrestle with old Satan for unregenerate souls! What are you
gasbags arguing about, anyway?”
“Harry says,” wailed Eddie Fislinger, “that there’s nothing in the
Bible that says Christians have to have a church or preachers.”
“Huh! And him that thinks he’s so educated. Where’s a Bible?”
It was now in the hands of Elmer, who had been reading his
favorite book, “The Song of Solomon.”
“Well, Brother Gantry, glad see there’s one galoot here that’s got
sense enough to stick by the Old Book and get himself right with
God, ’stead of shooting off his face like some Pedo-Baptist. Now look
here, Brother Zenz: It says here in Hebrews, ‘Forsake not the
assembling of yourselves together.’ There, I guess that’ll hold you!”
“My dear brother in the Lord,” said Harry, “the only thing
suggested there is an assembly like the Plymouth Brotherhood, with
no regular paid preachers. As I was explaining to Brother Fislinger:
Personally, I’m so ardent an admirer of the Bible that I’m thinking of
starting a sect where we all just sing a hymn together, then sit and
read our Bibles all day long, and not have any preachers getting
between us and the all-sufficient Word of God. I expect you to join,
Brother Karkis, unless you’re one of these dirty higher critics that
want to break down the Bible.”
“Oh, you make me tired,” said Eddie.
“You make me tired—always twisting the plain commands of
Scripture,” said Brother Karkis, shutting the door—weightily, and
from the outside.
“You all make me tired. My God, how you fellows can argue!” said
Elmer, chewing his Pittsburgh stogie.
The room was thick now with tobacco fumes. Though in Mizpah
Seminary smoking was frowned on, practically forbidden by custom,
all of the consecrated company save Eddie Fislinger were at it.
He rasped, “This air is something terrible! Why you fellows touch
that vile weed— Worms and men are the only animals who indulge
in tobacco! I’m going to get out of here.”
There was strangely little complaint.
Rid of Eddie, the others turned to their invariable topic: what they
called “sex.”
Frank Shallard and Don Pickens were virgins, timid and
fascinated, respectful and urgent; Horace Carp had had one
fumbling little greensick experience; and all three listened with
nervous eagerness to the experiences of Elmer and Harry Zenz.
Tonight Elmer’s mind reeked with it, and he who had been almost
silent during the ecclesiastical wrangling was voluble now. The
youngsters panted as he chronicled his meetings with a willing choir-
singer, this summer past.
“Tell me—tell me,” fretted Don. “Do girls, oh—nice girls—do they
really ever—uh—go with a preacher? And aren’t you ashamed to
face them afterwards, in church?”
“Huh!” observed Zenz, and “Ashamed? They worship you!”
declared Elmer. “They stand by you the way no wife ever would—as
long as they do fall for you. Why, this girl— Oh, well, she sang
something elegant.”
He finished vaguely, reminiscently. Suddenly he was bored at
treading the mysteries of sex with these mooncalves. He lunged up.
“Going?” said Frank.
Elmer posed at the door, smirking, his hands on his hips, “Oh, no.
Not a-tall.” He looked at his watch. (It was a watch which reminded
you of Elmer himself: large, thick, shiny, with a near-gold case.) “I
merely have a date with a girl, that’s all!”
He was lying, but he had been roused by his own stories, and he
would have given a year of life if his boast were true. He returned to
his solitary room in a fever. “God, if Juanita were only here, or
Agatha, or even that little chambermaid at Solomon Junction—what
the dickens was her name now?” he longed.
He sat motionless on the edge of his bed. He clenched his fists.
He groaned and gripped his knees. He sprang up, to race about the
room, to return and sit dolorously entranced.
“Oh, God, I can’t stand it!” he moaned.
He was inconceivably lonely.
He had no friends. He had never had a friend since Jim Lefferts.
Harry Zenz despised his brains, Frank Shallard despised his
manners, and the rest of them he himself despised. He was bored by
the droning seminary professors all day, the schoolboyish arguing all
evening; and in the rash of prayer-meetings and chapel-meetings
and special praise-meetings he was bored by hearing the same
enthusiasts gambol in the same Scriptural rejoicings.
“Oh, yes, I want to go on and preach. Couldn’t go back to just
business or the farm. Miss the hymns, the being boss. But—I can’t
do it! God, I am so lonely! If Juanita was just here!”
CHAPTER VII

I
the Reverend Jacob Trosper, D. D., Ph. D., LL. D., dean and
chief executive of Mizpah Theological Seminary, and Professor of
Practical Theology and Homiletics, was a hard-faced active man with
a large active voice. His cheeks were gouged with two deep
channels. His eyebrows were heavy. His hair, now gray and bristly,
must once have been rusty, like Eddie Fislinger’s. He would have
made an excellent top-sergeant. He looked through the students and
let them understand that he knew their sins and idlenesses before
they confessed them.
Elmer was afraid of Dean Trosper. When he was summoned to
the dean’s office, the morning after the spiritual conference in Frank
Shallard’s room, he was uneasy.
He found Frank with the dean.
“God! Frank’s been tattling about my doings with women!”
“Brother Gantry,” said the dean.
“Yes, sir!”
“I have an appointment which should give you experience and a
little extra money. It’s a country church down at Schoenheim, eleven
miles from here, on the spur line of the Ontario, Omaha and
Pittsburgh. You will hold regular Sunday morning services and
Sunday School; if you are able to work up afternoon or evening
services and prayer-meeting, so much the better. The pay will be ten
dollars a Sunday. If there’s to be anything extra for extra work—that’s
up to you and your flock. I’d suggest that you go down there on a
hand-car. I’m sure you can get the section-gang boss here to lend
you one, as it’s for the Lord’s work, and the boss’ brother does a lot
of gardening here. I’m going to send Brother Shallard with you to
conduct the Sunday School and get some experience. He has a
particularly earnest spirit—which it wouldn’t entirely hurt you to
emulate, Brother Gantry—but he’s somewhat shy in contact with sin-
hardened common people.
“Now, boys, this is just a small church, but never forget that it’s
priceless souls that I’m entrusting to your keeping; and who knows
but that you may kindle there such a fire as may some day illumine
all the world . . . providing, Brother Gantry, you eliminate the worldly
things I suspect you of indulging in!”
Elmer was delighted. It was his first real appointment. In Kansas,
this summer, he had merely filled other people’s pulpits for two or
three weeks at a time.
He’d show ’em! Some of these fellows that thought he was just a
mouth-artist! Show ’em how he could build up church membership,
build up the collections, get ’em all going with his eloquence—and, of
course, carry the message of salvation into darkened hearts.
It would be mighty handy to have the extra ten a week—and
maybe more if he could kid the Schoenheim deacons properly.
His first church . . . his own . . . and Frank had to take his orders!

II
In the virginal days of 1905 section gangs went out to work on the
railway line not by gasoline power but on a hand-car, a platform with
two horizontal bars worked up and down like pump-handles.
On a hand-car Elmer and Frank Shallard set out for their first
charge. They did not look particularly clerical as they sawed at the
handles; it was a chilly November Sunday morning, and they wore
shabby greatcoats. Elmer had a moth-eaten plush cap over his ears,
Frank exhibited absurd ear-muffs under a more absurd derby, and
both had borrowed red flannel mittens from the section gang.
The morning was icily brilliant. Apple orchards glistened in the
frost, and among the rattling weed-stalks by the worm-fences quail
were whistling.
Elmer felt his lungs free of library dust as he pumped. He
broadened his shoulders, rejoiced in sweating, felt that his ministry
among real men and living life was begun. He pitied the pale Frank a
little, and pumped the harder . . . and made Frank pump the harder
. . . up and down, up and down, up and down. It was agony to the
small of his back and shoulders, now growing soft, to labor on the
up-grade, where the shining rails toiled round the curves through
gravel cuts. But down-hill, swooping toward frosty meadows and the
sound of cowbells in the morning sun, he whooped with exhilaration,
and struck up a boisterous:
There is power, power, wonder-working power
In the blood
Of the Lamb—
The Schoenheim church was a dingy brown box with a toy
steeple, in a settlement consisting of the church, the station, a
blacksmith shop, two stores, and half a dozen houses. But at least
thirty buggies were gathered along the rutty street or in the carriage-
sheds behind the church; at least seventy people had come to
inspect their new pastor; and they stood in gaping circles, staring
between frosty damp mufflers and visored fur caps.
“I’m scared to death!” murmured Frank, as they strode up the one
street from the station, but Elmer felt healthy, proud, expansive. His
own church, small but somehow—somehow different from these
ordinary country meeting-houses—quite a nice-shaped steeple—not
one of these shacks with no steeple at all! And his people, waiting for
him, their attention flowing into him and swelling him—
He threw open his overcoat, held it back with his hand imperially
poised on his left hip, and let them see not only the black broadcloth
suit bought this last summer for his ordination but something choice
he had added since—elegant white piping at the opening of his vest.
A red-faced mustached man swaggered up to greet them,
“Brother Gantry? And Brother Shallard? I’m Barney Bains, one of the
deacons. Pleased to meet you. The Lord give power to your
message. Some time since we had any preachin’ here, and I guess
we’re all pretty hungry for spiritual food and the straight gospel. Bein’
from Mizpah, I guess there’s no danger you boys believe in this open
communion!”
Frank had begun to worry, “Well, what I feel is—” when Elmer
interrupted him with a very painful bunt in the side, and chanted with
holy joy:
“Pleased meet you, Brother Bains. Oh, Brother Shallard and I are
absolutely sound both on immersion and close communion. We trust
you will pray for us, Brother, that the Holy Ghost may be present in
this work today, and that all the brethren may rejoice in a great
reawakening and a bountiful harvest!”
Deacon Bains and all who heard him muttered, saint to saint,
“He’s pretty young yet, but he’s got the right idee. I’m sure we’re
going to have real rousing preaching. Don’t think much of Brother
Shallard, though. Kind of a nice-looking young fella, but dumm in the
head. Stands there like a bump on a log. Well, he’s good enough to
teach the kids in Sunday School.”
Brother Gantry was shaking hands all round. His sanctifying
ordination, or it might have been his summer of bouncing from pulpit
to pulpit, had so elevated him that he could greet them as
impressively and fraternally as a sewing-machine agent. He shook
hands with a good grip, he looked at all the more aged sisters as
though he were moved to give them a holy kiss, he said the right
things about the weather, and by luck or inspiration it was to the
most acidly devout man in Boone County that he quoted a homicidal
text from Malachi.
As he paraded down the aisle, leading his flock, he panted:
“Got ’em already! I can do something to wake these hicks up,
where gas-bags like Frank or Carp would just chew the rag. How
could I of felt so down in the mouth and so—uh—so carnal last
week? Lemme at that pulpit!”
They faced him in hard straight pews, rugged heads seen against
the brown wall and the pine double doors grained to mimic oak; they
gratifyingly crowded the building, and at the back stood shuffling
young men with unshaven chins and pale blue neckties.
He felt power over them while he trolled out the chorus of “The
Church in the Wildwood.”
His text was from Proverbs: “Hatred stirreth up strifes: but love
covereth all sins.”
He seized the sides of the pulpit with his powerful hands, glared
at the congregation, decided to look benevolent after all, and
exploded:
“In the hustle and bustle of daily life I wonder how many of us
stop to think that in all that is highest and best we are ruled not by
even our most up-and-coming efforts but by Love? What is Love—
the divine Love of which the—the great singer teaches us in
Proverbs? It is the rainbow that comes after the dark cloud. It is the
morning star and it is also the evening star, those being, as you all
so well know, the brightest stars we know. It shines upon the cradle
of the little one and when life has, alas, departed, to come no more,
you find it still around the quiet tomb. What is it inspires all great men
—be they preachers or patriots or great business men? What is it,
my brethren, but Love? Ah, it fills the world with melody, with such
sacred melodies as we have just indulged in together, for what is
music? What, my friends, is music? Ah, what indeed is music but the
voice of Love!”
He explained that hatred was low.
However, for the benefit of the more leathery and zealous
deacons down front, he permitted them to hate all Catholics, all
persons who failed to believe in hell and immersion, and all rich
mortgage-holders, wantoning in the betraying smiles of scarlet
women, each of whom wore silk and in her jeweled hand held a ruby
glass of perfidious wine.
He closed by lowering his voice to a maternal whisper and
relating a totally imaginary but most improving experience with a
sinful old gentleman who on his bed of pain had admitted, to Elmer’s
urging, that he ought to repent immediately, but who put it off too
long, died amid his virtuous and grief-stricken daughters, and
presumably went straight to the devil.
When Elmer had galloped down to the door to shake hands with
such as did not remain for Sabbath School, sixteen several auditors
said in effect, “Brother, that was a most helpful sermon and elegantly
expressed,” and he wrung their hands with a boyish gratitude
beautiful to see.
Deacon Bains patted his shoulder. “I’ve never heard so young a
preacher hand out such fine doctrine, Brother. Meet my daughter
Lulu.”
And she was there, the girl for whom he had been looking ever
since he had come to Mizpah.
Lulu Bains was a gray-and-white kitten with a pink ribbon. She
had sat at the back of the church, behind the stove, and he had not
seen her. He looked down at her thirstily. His excitement at having
played his sermon to such applause was nothing beside his
excitement over the fact that he would have her near him in his
future clerical labors. Life was a promising and glowing thing as he
held her hand and tried not to sound too insistently affectionate.
“Such a pleasure to meet you, Sister Lulu.”
Lulu was nineteen or twenty. She had a diminutive class of
twelve-year-old boys in the Sunday School. Elmer had intended to
sneak out during Sunday School, leaving Frank Shallard
responsible, and find a place where he could safely smoke a
Pittsburgh stogie, but in view of this new spiritual revelation he hung
about, beaming with holy approbation of the good work and being
manly and fraternal with the little boys in Lulu’s class.
“If you want to grow up and be big fellows, regular sure-enough
huskies, you just listen to what Miss Bains has to tell you about how
Solomon built that wonderful big ole temple,” he crooned at them;
and if they twisted and giggled in shyness, at least Lulu smiled at
him . . . gray-and-white kitten with sweet kitten eyes . . . small soft
kitten who purred, “Oh, now, Brother Gantry, I’m just so scared I
don’t hardly dare teach” . . . big eyes that took him into their depths,
till he heard her lisping as the voice of angels, larks, and whole
orchestras of flutes.
He could not let her go at the end of Sunday School. He must
hold her—
“Oh, Sister Lulu, come see the hand-car Frank and I—Brother
Shallard and I—came down on. The fun-niest! Just laugh your head
off!”
As the section gang passed through Schoenheim at least ten
times a week, hand-cars could have been no astounding novelty to
Lulu, but she trotted beside him, and stared prettily, and caroled,
“Oh, hon-est! Did you come down on that? Well, I never!”
She shook hands cheerfully with both of them. He thought
jealously that she was as cordial to Frank as to himself.
“He better watch out and not go fooling round my girl!” Elmer
reflected, as they pumped back toward Babylon.
He did not congratulate Frank on having overcome his dread of
stolid country audiences (Frank had always lived in cities) or on
having made Solomon’s temple not merely a depressing object
composed of a substance called “cubits” but an actual shrine in
which dwelt an active and terrifying god.

III
For two Sundays now Elmer had striven to impress Lulu not only
as an efficient young prophet but as a desirable man. There were
always too many people about. Only once did he have her alone.
They walked half a mile then to call on a sick old woman. On their
way Lulu had fluttered at him (gray-and-white kitten in a close bonnet
of soft fuzzy gray, which he wanted to stroke).
“I suppose you’re just bored to death by my sermons,” he fished.
“Oh, nnnno! I think they’re just wonderful!”
“Do you, honest?”
“Honest, I do!”
He looked down at her childish face till he had caught her eyes,
then, jocularly:
“My, but this wind is making the little cheeks and the cute lips
awful’ red! Or I guess maybe some fella must of been kissing ’em
before church!”
“Oh, no—”
She looked distressed, almost frightened.
“Whoa up!” he counseled himself. “You’ve got the wrong track.
Golly, I don’t believe she’s as much of a fusser as I thought she was.
Really is kinda innocent. Poor kid, shame to get her all excited. Oh,
thunder, won’t hurt her a bit to have a little educated love-making!”
He hastily removed any possible blots on his clerical reputation:
“Oh, I was joking. I just meant—be a shame if as lovely a girl as
you weren’t engaged. I suppose you are engaged, of course?”
“No. I liked a boy here awfully, but he went to Cleveland to work,
and I guess he’s kind of forgotten me.”
“Oh, that is really too bad!”
Nothing could be stronger, more dependable, more comforting,
than the pressure of his fingers on her arm. She looked grateful; and
when she came to the sick-room and heard Brother Gantry pray,
long, fervently, and with the choicest words about death not really
mattering nor really hurting (the old woman had cancer) then Lulu
also looked worshipful.
On their way back he made his final probe:
“But even if you aren’t engaged, Sister Lulu, I’ll bet there’s a lot of
the young fellows here that’re crazy about you.”
“No, honest there aren’t. Oh, I go round some with a second
cousin of mine—Floyd Naylor—but, my! he’s so slow, he’s no fun.”
The Rev. Mr. Gantry planned to provide fun.

IV
Elmer and Frank had gone down on Saturday afternoon to
decorate the church for the Thanksgiving service. To save the trip to
Babylon and back, they were to spend Saturday night in the broad
farmhouse of Deacon Bains, and Lulu Bains and her spinster cousin,
Miss Baldwin, were assisting in the decoration—in other words doing
it. They were stringing pine boughs across the back of the hall, and
arranging a harvest feast of pumpkins, yellow corn, and velvety
sumach in front of the pulpit.
While Frank and the spinster cousin of the Bainses discussed the
artistic values of the pumpkins, Elmer hinted to Lulu:
“I want your advice, Lulu—Sister Lulu. Don’t you think in my
sermon tomorrow it might be helpful to explain—”
(They stood side by side. How sweet were her little shoulders,
her soft pussy-cat cheeks! He had to kiss them! He had to! He
swayed toward her. Damn Frank and that Baldwin female! Why
didn’t they get out?)
“—to explain that all these riches of the harvest, priceless though
they are in themselves and necessary for grub—for the festal board,
yet they are but symbols and indications of the—Do sit down, Lulu;
you look a little tired.—of the deeper spiritual blessings which he also
showers on us and not just at harvest time, and this is a very
important point—”
(Her hand dropped against his knee; lay, so white, on the drab
pew. Her breasts were young and undrained under her plaid blouse.
He had to touch her hand. His fingers crept toward it, touched it by
accident, surely by accident, while she looked devotion and he
intoned sublimity.)
“—a very important point indeed; all the year round we receive
those greater inner blessings, and it is for them more than for any
material, uh, material gains that we should lift our voices in
Thanksgiving. Don’t you think it might be valuable to all of us if I
brought that out?”
“Oh, yes! Indeed I do! I think that’s a lovely thought!”
(His arms tingled. He had to slip them about her.)
Frank and Miss Baldwin had sat down, and they were in an
intolerably long discussion as to what ought to be done about that
terrible little Cutler boy who said that he didn’t believe that the ravens
brought any bread and meat to Elijah, not if he knew anything about
these ole crows! Frank explained that he did not wish to rebuke
honest doubt; but when this boy went and made a regular business
of cutting up and asking foolish questions—
“Lulu!” Elmer urged. “Skip back in the other room with me a
second. There’s something about the church work I want to ask you,
and I don’t want them to hear.”
There were two rooms in the Schoenheim church: the auditorium
and a large closet for the storage of hymn books, mops, brooms,
folding chairs, communion cups. It was lighted by a dusty window.
“Sister Bains and I are going to look over the Sunday School
lesson-charts,” Elmer called largely and brightly.
The fact that she did not deny it bound them together in secrecy.
He sat on an upturned bucket; she perched on a step-ladder. It was
pleasant to be small in her presence and look up to her.
What the “something about church work” which he was going to
ask her was, he had no notion, but Elmer was a very ready talker in
the presence of young women. He launched out:
“I need your advice. I’ve never met anybody that combined
common sense and spiritual values like what you do.”
“Oh, my, you’re just flattering me, Brother Gantry!”
“No, I’m not. Honest, I ain’t! You don’t appreciate yourself. That’s
because you’ve always lived in this little burg, but if you were in
Chicago or some place like that, believe me, they’d appreciate your,
uh, that wonderful sense of spiritual values and everything.”
“Oh—Chicago! My! I’d be scared to death!”
“Well, I’ll have to take you there some day and show you the
town! Guess folks would talk about their bad old preacher then!”
They both laughed heartily.
“But seriously, Lulu, what I want to know is—uh— Oh! What I
wanted to ask you: Do you think I ought to come down here and hold
Wednesday prayer-meetings?”
“Why, I think that’d be awfully nice.”
“But, you see, I’d have to come down on that ole hand-car.”
“That’s so.”
“And you can’t know how hard I got to study every evening at the
Seminary.”
“Oh, yes, I can imagine!”
They both sighed in sympathy, and he laid his hand on hers, and
they sighed again, and he removed his hand almost prudishly.
“But of course I wouldn’t want to spare myself in any way. It’s a
pastor’s privilege to spend himself for his congregation.”
“Yes, that’s so.”
“But on the other hand, with the roads the way they are here,
especially in winter and all, and most of the congregation living way
out on farms and all—hard for ’em to get in, eh?”
“That’s so. The roads do get bad. Yes, I think you’re right, Brother
Gantry.”
“Oh! Lulu! And here I’ve been calling you by your first name!
You’re going to make me feel I been acting terrible if you rebuke me
that way and don’t call me Elmer!”
“But then you’re the preacher, and I’m just nobody.”
“Oh, yes, you are!”
“Oh, no, I’m not!”
They laughed very much.
“Listen, Lulu, honey. Remember I’m really still a kid—just twenty-
five this month—only ’bout five or six years older’n you are. Now try
calling me Elmer, and see how it sounds.”
“Oh, my! I wouldn’t dare!”
“Well, try it!”
“Oh, I couldn’t! Imagine!”
“ ’Fraid cat!”
“I am not so.”
“Yes, you are!”
“No, I’m not!”
“I dare you!”
“Well—Elmer, then! So there now!”
They laughed intimately, and in the stress of their merriment he
picked up her hand, squeezed it, rubbed it against his arm. He did
not release it, but it was only with the friendliest and least emphatic
pressure that he held it while he crooned:
“You aren’t really scared of poor old Elmer?”
“Yes, I am, a tiny bit!”
“But why?”
“Oh, you’re big and strong and dignified, like you were lots older,
and you have such a boom-boom voice—my, I love to listen to it, but
it scares me—I feel like you’d turn on me and say, ‘You bad little girl,’
and then I’d have to ’fess. My! And then you’re so terribly educated
—you know such long words, and you can explain all these things
about the Bible that I never can understand. And of course you are a
real ordained Baptist clergyman.”
“Um, uh— But does that keep me from being a man, too?”
“Yes, it does! Sort of!”
Then there was no playfulness, but a grim urgency in his voice:
“Then you couldn’t imagine me kissing you? . . . Look at me! . . .
Look at me, I tell you! . . . There! . . . No, don’t look away now. Why,
you’re blushing! You dear, poor, darling kid! You can imagine me
kissing—”
“Well, I oughtn’t to!”
“ ’Shamed?”
“Yes, I am!”
“Listen, dear. You think of me as so awfully grown-up, and of
course I have to impress all these folks when I’m in the pulpit, but
you can see through it and— I’m really just a big bashful kid, and I
need your help so. Do you know, dear, you remind me of my mother
—”

V
Frank Shallard turned on Elmer in their bedroom, while they were
washing for supper—their first moment alone since Lulu and Miss
Baldwin had driven them to the Bains farm to spend the night before
the Thanksgiving service.
“Look here, Gantry—Elmer. I don’t think it looked well, the way
you took Miss Bains in the back room at the church and kept her
there—must have been half an hour—and when I came in you two
jumped and looked guilty.”
“Uh-huh, so our little friend Franky is a real rubber-necking old
woman!”
It was a spacious dusky cavern under the eaves, the room where
they were to stay the night. The pitcher on the black walnut
washstand was stippled in gold, riotous with nameless buds. Elmer
stood glaring, his big forearms bare and dripping, shaking his fingers
over the carpet before he reached for the towel.
“I am not a ‘rubber-neck,’ and you know it, Gantry. But you’re the
preacher here, and it’s our duty, for the effect on others, to avoid
even the appearance of evil.”
“Evil to him that evil thinks. Maybe you’ve heard that, too!”
“Oh, yes, Elmer, I think perhaps I have!”
“Suspicious, dirty-minded Puritan, that’s what you are, seeing evil
where there ain’t any meant.”
“People don’t hate Puritans because they suspect unjustly, but
because they suspect only too darned justly. Look here now, Elmer. I
don’t want to be disagreeable—”
“Well, you are!”
“—but Miss Bains—she looks sort of cuddlesome and flirtatious,
but I’m dead certain she’s straight as can be, and I’m not going to
stand back and watch you try to, uh, to make love to her.”
“Well, smarty, suppose I wanted to marry her?”
“Do you?”
“You know so blame’ much, you ought to know without asking!”
“Do you?”
“I haven’t said I didn’t.”
“Your rhetoric is too complicated for me. I’ll take it that you do
mean to. That’s fine! I’ll announce your intentions to Deacon Bains.”
“You will like hell! Now you look here, Shallard! I’m not going to
have you poking your long nose into my business, and that’s all
there is to it, see?”
“Yes, it would be if you were a layman and I had no official
connection with this outfit. I don’t believe too much in going around
being moral for other people. But you’re the preacher here—you’re
an ordained minister—and I’m responsible with you for the welfare of
this church, and I’m damned if I’m going to watch you seducing the
first girl you get your big sweaty hands on— Oh, don’t go doubling
up your fists. Of course you could lick me. But you won’t. Especially
here in the deacon’s house. Ruin you in the ministry. . . . Great God,
and you’re the kind we affably let into the Baptist ministry! I was
saying: I don’t propose to see you trying to seduce—”
“Now, by God, if you think I’m going to stand— Let me tell you
right now, you’ve got the filthiest mind I ever heard of, Shallard! Why
you should think I intend for one single second to be anything but
friendly and open and aboveboard with Lulu—with Miss Bains—Why,
you fool, I was in there listening about how she was in love with a
fellow and he’s gone off to Chicago and chucked her, and that was
all, and why you should think—”
“Oh, don’t be so fat-headed, Gantry! You can’t get away with
sitting in my room at the Sem boasting, you and Zenz boasting about
how many affairs you’ve had—”
“Well, it’s the last time I’ll sit in your damned room!”
“Splendid!”
“Think what you want to. And go to the devil! And be sure and run
tattling to Pop Trosper and the rest of the faculty!”
“Well, that’s a good come-back, Gantry. I may do just that. But
this evening I’ll just watch Lulu—watch Miss Bains and you. Poor
sweet kid that she is! Nice eyes!”
“Uh-huh, young Shallard, so you’ve been smelling around, too!”
“My God, Gantry, what a perfect specimen you are!”

VI
Deacon and Mrs. Bains—an angry-faced, generous, grasping,
horsy, black-mustached man he was, and she a dumpling—
managed to treat Frank and Elmer simultaneously as professors of
the sacred mysteries and as two hungry boys who were starved at
Mizpah and who were going to catch up tonight. Fried chicken,
creamed chipped beef, homemade sausages, pickles, and mince pie
in which Elmer suspected, and gratefully suspected, the presence of
unrighteous brandy, were only part of the stout trencher-work
required of the young prophets. Mr. Bains roared every three
minutes at the swollen and suffering Frank, “Nonsense, nonsense,
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like