Applying mathematics to digital image processing using a spreadsheet

Similar documents
INTRODUCTION TO COMPUTER GRAPHICS

Digital Imaging - Photoshop

IMAGE SIZING AND RESOLUTION. MyGraphicsLab: Adobe Photoshop CS6 ACA Certification Preparation for Visual Communication

Understanding Image Formats And When to Use Them

Developing Multimedia Assets using Fireworks and Flash

LECTURE 03 BITMAP IMAGE FORMATS

ADOBE PHOTOSHOP CS 3 QUICK REFERENCE

The next table shows the suitability of each format to particular applications.

Copyright Notice. Trademarks

Managing images with NewZapp

Bitmap Image Formats

Raster (Bitmap) Graphic File Formats & Standards

Images and Graphics. 4. Images and Graphics - Copyright Denis Hamelin - Ryerson University

Digital Imaging and Image Editing

Digital photo sizes and file formats

Mullingar Camera Club Basic introduction to Digital Printing using Photoshop CC.

By Washan Najat Nawi

CS 200 Assignment 3 Pixel Graphics Due Tuesday September 27th 2016, 9:00 am. Readings and Resources

Adobe Photoshop Notes. Adobe Photoshop CS3

Photoshop: Save for Web and Devices

Graphics for Web. Desain Web Sistem Informasi PTIIK UB

GXCapture 8.1 Instruction Manual

CHAPTER1: QUICK START...3 CAMERA INSTALLATION... 3 SOFTWARE AND DRIVER INSTALLATION... 3 START TCAPTURE...4 TCAPTURE PARAMETER SETTINGS... 5 CHAPTER2:

Introduction to Photoshop: Basic Editing & Prepare Images for the Web

2. Advanced Image editing

Image Optimization for Print and Web

Chapter 3 Graphics and Image Data Representations

Photoshop CS6. Table of Contents. Image Formats! 3. GIF (Graphics Interchange Format)! 3. JPEG or JPG (Joint Photographic Experts Group)!

Sampling Rate = Resolution Quantization Level = Color Depth = Bit Depth = Number of Colors

Specific structure or arrangement of data code stored as a computer file.

Epson Scanner (Expressions Photo) Basic Directions:

Vector VS Pixels Introduction to Adobe Photoshop

Using Adobe Photoshop to enhance the image quality. Assistant course web site:

2. Advanced Image Editing

CONTENTS. Chapter I Introduction Package Includes Appearance System Requirements... 1

Excel Tool: Plots of Data Sets

Using Adobe Photoshop

Adobe Photoshop. Levels

Guidance on Using Scanning Software: Part 5. Epson Scan

Preparing Images for Digital Projection

GETTING STARTED. 0 P a g e B a s i c s o f A d o b e P h o t o s h o p A g a P r i v a t e I n s t i t u t e f o r c o m p u t e r s c i e n c e

Digital Portable Overhead Document Camera LV-1010

Adobe Fireworks CS4 Kalamazoo Valley Community College February 25, 2010

Preparing Images For Print

Adobe Photoshop CS2 Workshop

Adobe Illustrator CS6

PhotoFiltre DEPARTMENT OF EDUCATION

inphoto ID PS Automatic ID photography With Canon PowerShot camera User Guide

ITP 140 Mobile App Technologies. Images

Digital Imaging & Photoshop

ID Photo Processor. Batch photo processing. User Guide

Adobe Photoshop PS2, Part 3

PB Works e-portfolio Optimizing Photographs using Paintshop Pro 9

SAQA. How to Submit an Online Entry. Art by Mary Kay Fosnacht

HTTP transaction with Graphics HTML file + two graphics files

User Guide. Version 1.2. Copyright Favor Software. Revised:

How To Resize & Crop Images to 1024 x 768 Pixels For Projection

Making Professional Quality Scientific Figures: Part II Advanced Image Editing

User Guide. Version 1.4. Copyright Favor Software. Revised:

Excel Lab 2: Plots of Data Sets

Dr. Shahanawaj Ahamad. Dr. S.Ahamad, SWE-423, Unit-06

ImagesPlus Basic Interface Operation

CHAPTER 3 I M A G E S

Software Reference. FlexColor 4.0 for Camera Backs. by Hasselblad Imacon

Computer Programming

PENGENALAN TEKNIK TELEKOMUNIKASI CLO

Bitmap Vs Vector Graphics Web-safe Colours Image compression Web graphics formats Anti-aliasing Dithering & Banding Image issues for the Web

INSTRUCTION MANUAL MM-A209

SECTION I - CHAPTER 2 DIGITAL IMAGING PROCESSING CONCEPTS

Astronomy and Image Processing. Many thanks to Professor Kate Whitaker in the physics department for her help

Black & White and colouring with GIMP

Note: These directions are for Paint on WindowsXp and Vista. At the end of this tutorial are features of Paint for Windows 7.

Fundamentals of Multimedia

PHOTOSHOP. pixel based image editing software (pixel=picture element) several small dots or pixels make up an image.

ISCapture User Guide. advanced CCD imaging. Opticstar

B.Digital graphics. Color Models. Image Data. RGB (the additive color model) CYMK (the subtractive color model)

Digital Files File Format Storage Color Temperature

CATEGORY SKILL SET REF. TASK ITEM

Coreldraw Crash Course

1 Li & Drew c Prentice Hall Li & Drew c Prentice Hall 2003

Aperture. The lens opening that allows more, or less light onto the sensor formed by a diaphragm inside the actual lens.

digitization station DIGITAL SCRAPBOOKING 120 West 14th Street

TEST INFORMATION: 40 questions 50 minutes 70% minimum required to pass. Score is based on a 1000 pt system so passing will be a 700.

Optika ISview. Image acquisition and processing software. Instruction Manual

Océ Colour Copy 7.0. User Manual

How to generate different file formats

Glossary Unit 1: Hardware/Software & Storage Media

Introduction to Photography

6. Graphics MULTIMEDIA & GRAPHICS 10/12/2016 CHAPTER. Graphics covers wide range of pictorial representations. Uses for computer graphics include:

Basic Image Editing Tutorial

Factors to Consider When Choosing a File Type

inphoto ID SLR Automatic ID photography With Canon SLR camera User Guide

Contents Foreword 1 Feedback 2 Legal information 3 Getting started 4 Installing the correct Capture One version 4 Changing the version type 5 Getting

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

Introduction. Basic Image Formatting. Word 2010 Formatting Pictures. To Crop an Image: Page 1

2. Advanced Image Editing

3.1 Graphics/Image age Data Types. 3.2 Popular File Formats

Machinery HDR Effects 3

COMPSCI 111 / 111G Mastering Cyberspace: An introduction to practical computing. Digital Images Vector Graphics

User s Guide. For PhotoShop. Wide Format Scanning Plug-in for Photoshop on Macintosh & Windows Edition

Transcription:

Jeff Waldock Applying mathematics to digital image processing using a spreadsheet Jeff Waldock Department of Engineering and Mathematics Sheffield Hallam University j.waldock@shu.ac.uk Introduction When presenting a particular mathematical topic to a group of students, it can help their understanding if a familiar illustrative example can be provided. There is a surprisingly wide range of mathematics involved in manipulating digital images, from simple arithmetic (e.g. increasing or decreasing the image brightness), to matrix algebra (applying a filter) to numerical PDEs (image sharpening) to more complex processes such as pattern recognition. Students are familiar with digital images, most likely because of their mobile phone camera, and many are also familiar with the post-processing possibilities - either using in-camera tools or through tools such as Photoshop. Many students have a good working knowledge of spreadsheets - particularly Microsoft Excel - as they are widely used as a support tool in their course. This paper describes a tool developed to allow students to make use of their spreadsheet skills in applying the mathematical techniques necessary to implement a variety of image modifications. It is an Excel add-in which decomposes the image to its red, green and blue parts, putting each into a separate worksheet. It can also recompile a JPG image from the data in these worksheets. This tool has been used with final year students on the BSc Mathematics degree at Sheffield Hallam University taking a mandatory 20 credit module Advanced Case Studies. The image processing case study is one of four in the year and lasts six weeks, with class contact of 3 hours per week. Although used here with final year degree students, it could equally well be used with students studying mathematics at many levels from high school level to postgraduate. The important difference will be the examples tackled. Digital images All digital images are made up of an array of pixels, each of which can be displayed on a computer monitor using a variety of levels of the three primary colours red, green and blue. For accurate colour reproduction, the computer s display adapter should be configured for true colour, also known as 24-bit colour since it is made up of three 8-bit bytes, one for each of the primary colours. The 8-bit binary numbers can each represent 256 levels of red, green and blue, making a possible 16.7 million colours altogether. 11

On a printer, images are usually drawn using three primary colour inks (cyan, magenta, yellow) at a given resolution (typically around 250-300 pixels per inch). A 6x4 snapshot at 250 ppi would therefore require 1500 x 1000 pixels a total of 1,500,000 pixels (so a 1.5 megapixel camera would be sufficient). The current generation of professional digital cameras have 24 megapixel sensors, delivering images with dimensions of around 6000 x 4000, and hence 24 x16 prints. Greater print sizes could of course be made, but would involve pixel interpolation and hence a reduction in quality. File formats Digital images tend to be stored on a computer in one of several formats: GIF (Graphics Interchange Format): this format can only store 256 colours, and so is best for cartoon-type graphics and lineart. Different levels of optimisations are possible to reduce file size at the expense of quality. One of the most useful features of this format is its ability to store multiple images and display them in sequence, with a user-definable interval. JPG (or JPEG): the Joint Photographic Experts Group format is the most widely used format for the storage of digital photographs. Jpeg images can contain the full 24-bit range of colours, but it is a lossy format, compressed using an algorithm that looks for similar colours, and can be very efficient. Digital cameras often provide basic, normal and fine settings, representing different optimisation settings of the JPG algorithm and allowing the user to choose a different balance between quality and file size. The TIFF (Tagged Image File Format) image format is primarily used for best quality images and for the storage and transfer of images in high-quality photographic applications when no loss of quality is permitted. The file sizes are correspondingly huge. BMP format is sometimes used for graphics, but has no compression, so the files tend to be too large for practical use with photographic images. The PNG (Portable Network Graphics) format allows lossless compression and variable transparency, but it has not gained wide acceptance for photographic use. All of these image formats use binary coding for efficiency, so the pixel values cannot be viewed directly in a simple editor. Digital image editors, such as Photoshop, allow the correction of many deficiencies in digital images very easily images that were too dark could be brightened, flat pictures could be improved by increasing the image contrast and defects could be directly erased. A wide variety of more complex effects are also available. and size of the image as well as dozens of other useful data elements stored, such as a 160-pixel thumbnail of the image. The part of the file that contains all of these data is called the EXIF section. For more information, see http://www.exif.org/. Some cameras can also use the IPTC format for storing image data (http://www.iptc.org). The Image Analysis Excel add-in A custom-designed add-in for Excel has been written to provide tools necessary to decode the JPG file into Excel and to re-code it as a JPG after the pixel values have been modified. This add-in also has several other features which are designed to help focus on the mathematics involved rather than the computing. The first step is to obtain the add-in and install it. These instructions relate to Office 2007, although the process should be broadly similar in other versions of Excel. Create a folder somewhere on the computer and give it a suitable name. Get a copy of image_analysis.zip from the website, at http://maths.shu.ac.uk/msor/digitalimages/ Download the file Image_Analysis.zip and save it to the folder created above. Unzip the file into the same folder. There should be three files: 1 images.xlam (the add-in, in Office 2007 format) 2 ImageAnalysis.chm (the associated help file) 3 _ISource40.dll (a library of functions used by the add-in). The add-in needs to have access to this last file. Ideally the library file should be copied to the Windows system folder; otherwise make sure the spreadsheet to be used is saved to the same folder as the library file. Open Excel, and click the Office button at the top left. Select 'Excel Options' choose the 'Add-ins' category and click 'Go'. Image data Camera and image information can be stored in the file along with the picture itself. This includes the date, time 12 Fig 1 The Excel add-ins dialog

Click Browse, find images.xlam and select it. Click OK. The add-in will now appear in the above dialog (labelled Image Analysis ), and will be selected. Click OK to accept this. A new 'Add-ins' tab appears at the top of the worksheet, containing a new menu item called Image Analysis. This new menu is shown in Fig 2: been reduced to 250x187 pixels. Prior to Excel 2007, only 256 columns were available in a worksheet, so the add-in needed to reduce the size of each image so that the image width is no greater than this. I have chosen to make the width 250. With Excel 2007, more columns are allowed, however importing and manipulating full-size images in this way is quite slow and cumbersome, so the add-in still reduces the image size to have a width of 250 pixels. (NB a version that retains the full image size is also available from the above website). Fig 2 The Image Analysis menu As long as the add-in is checked in the add-ins dialog, this menu will be available. Now copy the digital images to be processed into the folder created above. Save the new Excel workbook to that same folder. This is important the add-in assumes that the image files to be processed are located in the same folder as the workbook. Remember also that with Office 2007, the file must be saved using the.xlsm extension so the built-in macros are not lost. Using the Image Analysis add-in Firstly, select Import Image Data from the Image Analysis menu: The data can now be imported directly to the worksheets, or to separate disk files. If you choose Save data to disk, the add-in will create three files rval.txt, gval.txt and bval.txt each of which gives the red, green and blue components respectively of the image, organised into rows and columns. Choose Import direct to worksheets. The program will first check to see if the workbook is correctly set-up (there needs to be the right worksheets inserted and formatted). If it is not, it will create these automatically (after requesting confirmation). Fig 4 The Reconfigure Workbook dialog Click OK. The data are now imported to several sheets of the workbook. This may take a few seconds if the file is large, so be patient! If the Also import to ALL sheet checkbox is selected, the cells of the ALL sheet will be coloured according to the pixel values - so the image can be seen. Be warned, however, that in Office 2007 - since it can display all 16.7 million colours - this can be very slow! The add-in has created five worksheets: Fig 3 The Import Image data dialog You may notice the original file size (1280x960 pixels check the Show image details box to confirm this) has R, G and B, each containing an array of integers, representing the respective colour value of each pixel, in the range 0-255. ALL a workbook which combines the colour values by assigning them as the background colour of each cell. 13

This is only useful in that it shows that the data are in fact for the correct image zoom down to 20% or so to see the whole of the image. LUT a worksheet providing the information that the LUT tool uses to apply a Look-Up-Table to modify the pixel values. The colour value in column A is replaced by that in columns B, C and D for the red, green and blue colour channels, respectively. For more information, see the section Applying Look-Up Tables. The data in the worksheets can now be processed to implement the desired effect(s). Saving the new data as a JPG and viewing the results From the menu, choose Export Image Data. In the Output Filename text box, enter the filename desired, then click Save File. Once saved, click Display Image to view the modified JPG image: This dialog displays the progress of the application of LUTs - it can be dismissed when complete by clicking OK. The image can then be exported as before. Remember ALL files should be kept in the same folder. The add-in expects to find files in the same folder as the workbook, and all files generated will go to that same folder. The built-in help file Fig 7 The Apply Look-Up Table dialog The ImageAnalysis.chm file is a compiled help file written to accompany the add-in. It contains much the same information as contained here, but it can be useful to access the information directly from within Excel, using the help menu item, or F1. Here, pixels from A1 to Z20 in both the red and green worksheets have been set to zero. Applying Look-Up Tables Fig 5 The Save and Show Image dialog As well as being able to edit the numerical colour values of individual pixels directly, via the worksheet cells, another quite powerful technique is available, in the form of a Look Up Table (LUT). When the workbook is set up, either manually via the menu or when running the Import Image menu item, a LUT worksheet is created: Fig 8 The help file screen The menu also provides two further links one which will open the Case Study web page in the default browser, and one which will open a new e-mail window, pre-addressed to me, in the default email client. Student tasks Fig 6 The Look-Up Table (LUT) It is very simple to use just set the integer values to replace 0-255 within each of the R, G and B worksheets. These numbers can either be entered directly or worksheet formulae can be used this allows some quite powerful transformations to be carried out. Once the LUT table is ready, it is applied by means of the Apply the Look Up Table menu item. Students are asked to attempt all of the Group 1 and 2 tasks and at least three of each of the Group 3 and 4 tasks. They are also encouraged to research and implement other effects, and are awarded credit for doing so. Group 1: Add a black or coloured border to the image Try removing the red, green and/or blue component of a part of the image 'Flip' the image, so that is upside down 14

Obtain a mirror reflection of the image (left-right flip) Rotate the image by 90, either left or right (this will only work if the height is less than 256, or it will not fit on the worksheet) Group 2: Adjust the brightness of the image (increase and/or decrease it) Adjust the contrast of the image (increase and/or decrease it) Alter the colour balance Create a monochrome version of the image Obtain a negative image Obtain a sepia-tinted version of the image. Change the image gamma Example 1: Brightness Raising the brightness of an image is achieved simply by increasing the colour value of each pixel. To retain the colour balance it is strictly speaking necessary to increase each colour component in proportion, but for demonstrating the process it is sufficient to just add, say, 20 to each colour value. It is helpful to represent the transformation by means of a simple graph: Group 3: Soften (i.e. blur) the image Increase the sharpness of the image Distort the image by applying a shear or a stretch Add noise to the image Add a drop-shadow Group 4: Overlay one image on another Display the differences between images Apply the above idea using one image with a shifted version of itself, to create a bas-relief effect. Apply a ripple or wave effect Take two images and generate a morph effect by interpolating between them Obtain a histogram of the colour values contained in the image Take a simple image and identify patterns, e.g. edges, in it Student comments I found the digital image spreadsheet add-in easy (and interesting) to use. I think it is an enjoyable way of implementing mathematical algorithms, plus you can easily see the results of the implemented algorithms, which is good. The manipulation of digital images case study was the most interesting as I enjoyed playing around with my own personal images and finding out how it is practically possible to create the same image alterations as my camera does for me. Fig 9 Showing the relationship between the input and output pixel colour values for increasing and decreasing brightness (by 40 in each case) The pixel values cannot go above 255 or below 0, so we must truncate them. To apply this transformation use the LUT tab: In cell F2 type: Brightness Offset: In cell H2 type: 20 In cell B4 type: =max(0,min(255,$a4+$h$2)). The $ symbol fixes the row or column so it doesn t change when copying. The min function makes sure the values do not rise above 255; the max ensures they do not drop below 0. Select cell B4, move the cursor to the bottom right hand corner, until it changes to a heavy cross symbol, then double left click the mouse. This copies the formula to all cells in that column. Copy the contents of B4 to cells C4 and D4, and copy the formulae to the bottom, as above. From the menu, apply the LUT, then export and view the image. 15

Example 2: Contrast To apply an increase or decrease in contrast, a similar process is carried out. This time, however, we want to compress or expand the range of colour values in the image, according to whether we want to decrease or increase contrast, respectively. The diagram below illustrates how we might do this, applying a linear function in which the centre value (127) is invariant. The formula for this is y = mx + 127(1 m), where m is the slope of the line. A line of no-change, y = x, would correspond to m = 1. For an increase in contrast we use a value of m > 1, for a decrease we use 0 m < 1. Fig 11 The PictureValues program. This program enables a dynamic view of the effects of changing the Look Up Table function Example 3: Creating a negative image To create a negative, it is necessary to replace each colour value by its inverse in this case: new colour value = 255 old colour value This is a particularly easy transformation to apply. The colour diagram would look like that in Fig 12.: Fig 10 Showing the relationship between the input and output pixel colour values for increasing and decreasing contrast. The slope of the line has been changed by 20% in each case Again the lines are truncated at 0 and 255. This uses a linear relationship; for more control over the contrast modification such as to emphasise mid-tones for example it would be necessary to use a curve instead. The modelling of such a curve would bring into play a lot more mathematics! Fig 12 Showing the relationship between the input and output pixel colour values necessary for producing a negative image An example like this can be tailored as required for the mathematical level of competence (and interest!) of the audience. Supporting program PictureValues An additional software tool is available to illustrate the idea of modifying brightness and contrast, and is called PictureValues. It may also help to clarify the concept of Look Up Tables. The program simply provides a diagrammatic illustration of how changes to the LUT function affect the contrast and brightness of an image. The program demonstrates this dynamically. It is available at http://maths.shu.ac.uk/msor/ DigitalImages/PictureValues.zip. 16