




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































Computational
Colour Science
using MATLAB
Copyright u 2004 John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England Telephone (+44) 1243 779777
E-mail (for orders and customer service enquiries): [email protected] Visit our Home Page on www.wileyeurope.com or www.wiley.com
All Rights Reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except under the terms of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London W1T 4LP, UK, without the permission in writing of the Publisher. Requests to the Publisher should be addressed to the Permissions Department, John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex PO19 8SQ, England, or emailed to [email protected], or faxed to (+44) 1243 770620.
This publication is designed to provide accurate and authoritative information with regard to the subject matter covered. It is sold on the understanding that the Publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought.
Other Wiley Editorial Offices John Wiley & Sons Inc., 111 River Street, Hoboken, NJ 07030, USA Jossey-Bass, 989 Market Street, San Francisco, CA 94103-1741, USA Wiley-VCH Verlag GmbH, Boschstr. 12, D-69469 Weinheim, Germany John Wiley & Sons Australia Ltd, 33 Park Road, Milton, Queensland 4064, Australia John Wiley & Sons (Asia) Pte Ltd, 2 Clementi Loop #02-01, Jin Xing Distripark, Singapore 129809 John Wiley & Sons Canada Ltd, 22 Worcester Road, Etobicoke, Ontario, Canada M9W 1L
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
Library of Congress Cataloging-in-Publication Data Westland, Stephen. Computational colour science using MATLAB / Stephen Westland, Caterina Ripamonti. p. cm. Includes bibliographical references and index. ISBN 0-470-84562-7 (Cloth : alk. paper)
British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library
ISBN 0 470 84562 7 hardback
Typeset in 10½/13pt Times by Dobbie Typesetting Ltd, Tavistock, Devon Printed and bound in Great Britain by Antony Rowe Ltd, Chippenham, Wilts This book is printed on acid-free paper responsibly manufactured from sustainable forestry in which at least two trees are planted for each one used for paper production.
The growing importance of colour science in manufacturing industry has resulted in the availability of many excellent textbooks: existing texts or review papers describe the history and development of the Commission Internationale de l’Eclairage (CIE) system (Wyszecki and Stiles, 1982; Hunt, 1998), the prediction of colour difference (McDonald, 1997a; Berns, 2000; Luo, 2002a) and colour appearance (Fairchild, 1998), the relationship of the CIE system to the human visual system (Wandell, 1995; Kaiser and Boynton, 1996), and applications of colour science in technology (Green and MacDonald, 2002). However, the field of colour science is becoming ever more technical and although practitioners need to understand the theory and practice of colour science they also need guidance on how to actually compute the various metrics, indices and coordinates that are useful to the practising colour scientist. The purpose of this book is to describe methods and algorithms for actually computing colorimetric parameters and for carrying out applications such as device characterization, transformations between colour spaces and computation of various indices such as colour differences. A reasonable understanding of the main principles of the CIE system is therefore assumed, although a revision aid is provided in Section 1.3 in the form of a brief review of the CIE system of colorimetry. The reader who wishes to explore the theoretical and historical backgrounds of the topics covered by this book is encouraged to review the alternative texts mentioned above and referred to within this text. We anticipate that computer programmers, colour-image engineers and students of colour science will find this book and the associated MATLAB code useful, but hope that anyone with an interest in colour science will find the book enjoyable and informative.
Computational Colour Science Using MATLAB. By Stephen Westland and Caterina Ripamonti. & 2004 John Wiley & Sons, Ltd: ISBN 0 470 84562 7
and demonstrated with clarity and accuracy. Moreover, the computation of many colorimetric terms is ideally suited to a language that expresses variables in terms of matrices and vectors. Some procedures are best explained or implemented using loops, however, and for these situations MATLAB provides for and while looping structures. The second strength of MATLAB is that it includes an encyclopaedic collection of subprograms, called M-files, for the solution of nearly any numerical problem. Although this book is not principally concerned with generic numerical analysis, but rather with particular colorimetric algorithms, the M- files that are available with MATLAB are useful for many computations in colour science. MATLAB provides many functions (such as those with the ability to invert matrices) and if it was necessary to spend time explaining these in detail or writing code to implement them it would detract from the main focus of this book, which is colour science. The reader may wish to refer to other textbooks (e.g. Press et al., 1993) that address implementations of numerical analysis in programming languages such as C if they wish to convert the code in this book into other programming languages. MATLAB’s most spectacular feature is its capability to display graphics. Two- or three-dimensional graphs are easily constructed by even a novice MATLAB user. Thus
x = [1 2 3 4 5]; y = [3 5 7 9 11]; plot(x,y)
is sufficient code to plot a graph of the five values in the vector y against those in the vector x. Experienced programmers will find it trivial to construct sophisticated and informative graphs, and the ability to almost effortlessly visualize data is one of main advantages of using MATLAB in a research environment. MATLAB allows the user to answer complex ‘what if?’ questions with just a handful of code lines. MATLAB can be confusing, however, for new users who do not have a reasonable understanding of linear algebra. For this reason, Chapter 3 provides a gentle introduction to MATLAB and Chapter 2 provides a basic introduction to linear algebra and the notation that is used throughout this book. Where possible the code that is presented has been written for clarity rather than for efficiency or speed of computation to allow the reader to understand the computational principles involved and to be able to implement them in a wide variety of programming languages. In general, special MATLAB commands have been avoided, even though their use may have made the code more efficient, to reduce the effort that would be required to translate the code into a language such as C or C++. One exception, however, is the backslash operator, which is described in Chapter 3.
WHY BASE THIS BOOK UPON MATLAB? 3
Programmers who wish to use languages other than MATLAB may wish to create their own version of the backslash operator in order to easily translate the code within this book. All the MATLAB code contained within this book can be downloaded from http://www.colourware.co.uk/compute/ and from http://www.mathworks.com/matlabcentral/.
Light is a term that we use to describe that range of wavelengths (approximately 380–780 nm) of electromagnetic radiation to which the human visual system is sensitive. When we observe the light reflected from surfaces in a scene, or when we look directly at the light emitted by light sources, we experience the sensation of colour. Colour is just one attribute of a complex and not fully understood set of properties that define the appearance of the world. Surfaces interact with light in a complex and varied way that includes the processes of absorption, scattering, refraction and diffraction, but it is the light that is reflected by the surfaces in a scene that we use to identify those surfaces by their colour. The reflectance properties of surfaces can be defined by the spectral reflectance factors that are normally measured at regular intervals in the visible spectrum of radiation. Typical reflectance spectrophotometers are able to measure the reflectance factors at intervals of 10 nm in the range 400–700 nm (though some instruments extend their measurement to shorter or longer wavelengths). Reflectance factors are normally in the range 0–1 and represent the proportional amount of light reflected in each wavelength interval. The light that we see when we look at a point in a scene clearly depends upon the spectral power distribution of the illuminating source and the reflectance properties of the surface at that point. Our visual systems detect the reflected light using the light-sensitive sense organs or retinas that form the inner lining of the back of the eyeball. Light enters the eye through the pupil and is focused onto the retina by the lens. The human retina consists of a mosaic of specialized cells called rods and cones that contain pigments that respond to light. The chemical changes that take place when the visual pigments in the rods and cones absorb light initiate electrical impulses that are subsequently processed by a neural network of brain cells and which eventually lead to the excitation of cells in various specialized areas of the outer region of the brain known as the cortex. It is still unknown where in the brain colour perception actually occurs, if indeed it occurs in any localized area, but activity in the visual cortex at the back of the brain is strongly implicated. The properties of the visual system have been reviewed elsewhere (e.g. Roberts,
4 INTRODUCTION
and B, then it is possible to write an equation to denote the matching condition:
S R½R þ G½G þ B½B: ð 1 : 1 Þ
In this equation the symbol means ‘is matched by’ and the stimulus is denoted by S. If the tristimulus values are measured separately for each wavelength in the visible spectrum, then we obtain the tristimulus values as functions of the wavelength l: R(l), G(l) and B(l). These three functions of wavelength are called colour-matching functions. The additivity and linearity of colour matches allow an important property: if a stimulus S 1 is matched by R 1 , G 1 and B 1 and a stimulus S 2 is matched by R 2 , G 2 and B 2 , then it is possible to predict in advance the tristimulus values that define a match to the stimulus defined by the additive mixture S 1 +S 2. Thus we can simply write
S 1 þ S 2 ðR 1 þ R 2 Þ½R þ ðG 1 þ G 2 Þ½G þ ðB 1 þ B 2 Þ½B: ð 1 : 2 Þ
Since any real stimulus can be considered to be the sum of energy at many different wavelengths, it is possible to predict the tristimulus values for any stimulus in a similar way (without having to resort to physically determining a visual match for that stimulus using a bipartite colorimeter) given that the colour-matching functions are known. In fact, experiments were carried out prior to the publication of the CIE system by two groups of workers, headed by Wright in 1929 and Guild in 1931, to determine colour-matching functions. The two groups of workers used different primaries and consequently the two sets of colour-matching functions were different. This raises an interesting question: Are the colour-matching functions arbitrary, given that there is a very wide choice in the selection of the primaries? Certainly, the actual tristimulus values obtained for a given stimulus are arbitrary in that they would be different if a different set of primaries was chosen. However, the matching condition is valid no matter which primaries are selected subject to some simple criteria (for example, the primaries must be independent; in other words, it must not be possible to match one of the primaries using an additive mixture of the other two, etc.). This means that if two stimuli are a visual match and are specified by the same tristimulus values under Guild’s system, then they would also be a match under Wright’s system. Furthermore, the two stimuli would be a match under a system defined by any other set of three primaries. It is possible to convert tristimulus values from one system to another by a simple linear transform (see Chapter 2). It is also possible to compute the colour- matching functions for a set of known primaries given the colour-matching functions of another set of primaries. Thus, in 1931 the CIE transformed the two sets of colour-matching functions obtained from experiments carried out by Wright and Guild into a single set of colour-matching functions and reassuringly found good agreement between the two sets of data. The CIE system as we know
6 INTRODUCTION
it today is based upon a transformation of the original colour-matching functions averaged from Guild and Wright to a set of primaries known as X, Y and Z. The colour-matching functions are known for each wavelength and are therefore represented by x(l), y(l) and z(l). The CIE also defined standard illuminants – tables of spectral power distributions – that can be used to compute the colour signal for a surface given the spectral reflectance factors of the surface. The introduction of tables of illuminants allowed the computation of tristimulus values for surface colours as well as for self-luminous colours. A practical formula for computing the CIE 1931 tristimulus values for a surface with spectral reflectance P(l) under an illuminant of relative spectral power E(l) is
X ¼ kSEðlÞPðlÞxðlÞ, Y ¼ kSEðlÞPðlÞyðlÞ, Z ¼ kSEðlÞPðlÞzðlÞ,
ð 1 : 3 Þ
where k is 100/[S yðlÞEðlÞ. At each wavelength interval the product E(l)P(l) gives the amount of energy in the stimulus at wavelength l and the amount of the primary required to match this is given by multiplying this product by the colour-matching function at that wavelength. In order to arrive at the amount of the primary required to match the stimulus it is only necessary to sum across all wavelengths [Equation (1.3)]. Note that the implication of the normalizing factor k is that the absolute spectral power distribution for the illuminant is not required so that, for surface colours at least, Y ¼ 100 for a perfect white surface [for which P(l) ¼ 1 for all l]. Furthermore, note that a perfect white surface will give Y ¼ 100 for any illuminant E. This normalisation is reasonable given the processes of adaptation that take place in our everyday vision. In order to appreciate these processes, imagine a piece of white paper with reflectance of 1 at all wavelengths and a piece of black coal with reflectance 0.01 at all wavelengths. Now consider viewing these two surfaces indoors (under an equal-energy light source with 100 units of light at each wavelength) and outdoors (under an equal-energy light source with 10 000 units of light at each wavelength). When viewed indoors the paper reflects 100 units of light at each wavelength whereas the coal reflects only 1 unit of light at each wavelength, but the amount of light reflected outdoors is 10 000 and 100 for the paper and coal, respectively. Even though the paper reflects 100 times as much light outdoors as it does indoors, the colour appearance of the paper remains approximately constant under the two light sources. More surprisingly, the coal reflects as much light outdoors as the paper does indoors and yet the coal is veridically seen as black. This remarkable property of colour constancy is central to our whole visual experience. The normalizing factor k in the CIE system ensures that for a perfectly white surface the Y tristimulus value will always be 100 irrespective of the quantity and quality of the illuminant. One
A BRIEF REVIEW OF THE CIE SYSTEM OF COLORIMETRY 7