Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 9 Grey Level & Colour Enhancement TK3813 Dr. Masri Ayob.

Similar presentations

Presentation on theme: "Lecture 9 Grey Level & Colour Enhancement TK3813 Dr. Masri Ayob."— Presentation transcript:

1 Lecture 9 Grey Level & Colour Enhancement TK3813 Dr. Masri Ayob

2 2 Point Processing Operations Point processing involves the transformation of individual pixels independently of other pixels in the image. These simple operations are typically used to correct for defects in image acquisition hardware. For example, to compensate for under/over exposed images. The process of modifying pixel grey level and colour are sometimes referred to as ‘point processing operation’.

3 3 The common operations involve the adjustment of brightness, contrast or colour in an image. A common reason for manipulating these attribute is the need to compensate for difficulties in image acquisition. E.g. Image where an object of interest is backlit (illuminated from behind). Without the aid of image processing, we might need to reacquire the image several time. With image processing, we can reveal enough detail to allow proper interpretation. Point Processing Operations

4 4 We can adjust the overall brightness of a grayscale simply by adding a constant bias, b, to pixel values: g(x,y) = f(x,y) + b If b > 0 the image is made brighter else the image is darkened. b is known as “bias” Linear Mapping (6.1)

5 5 Linear Mapping We can adjust contrast in a greyscale image through multiplication of pixel values by a constant gain, a: g(x,y) = a * f(x,y) If a > 1 the image is made brighter else the image is darkened. a is known as “gain” (6.2)

6 6 Examples

7 7 Examples

8 8 Examples gain = +1.5gain = -2.0

9 9 Linear Mapping These mappings can be combined to yield a linear mapping of f to g given as: g(x,y) = a*f(x,y) + b Typically don’t want to specify gain and bias but think in terms of mapping a range of values [f1..f2] onto a different range of values [g1, g2]. The following equation shows how to represent the linear mapping using range information only: General expression for brightness and contrast (6.3) (6.4)

10 10 Linear Mapping

11 11 Examples Linear Mapping G1 = 0, G2 = 255, F1 = 75, F2 = 185 Gain = 2.3, Bias =

12 12 Examples Inverse mapping G1 = 255, G2 = 0, F1 = 0, F2 = 255 Gain = -1, Bias = 255

13 13 Examples Bilevel Threshold Mapping G1 = 0, G2 = 255, F1 = 127, F2 = 128 Gain = 255, Bias =

14 14 Linear Contrast Stretching A linear mapping that enhances the contrast of an image without removing any detail. Spreads the visual information available across a greater range of gray scale intensities

15 15 Linear Contrast Stretching Example Notice that the left image appears washed-out (most of the intensities are in a narrow band due to poor contrast). The right image maps those values to the full available dynamic range.

16 16 Linear Contrast Stretching Implement equation 6.3 Implement equation 6.4

17 17 Java Code Interface BufferedImageOp All Known Implementing Classes: AffineTransformOp, ColorConvertOp, ConvolveOp, LookupOp, RescaleOp public interface BufferedImageOp This interface describes single-input/single-output operations performed on BufferedImage objects. It is implemented by AffineTransformOp, ConvolveOp, ColorConvertOp, RescaleOp, and LookupOp. These objects can be passed into a BufferedImageFilter to operate on a BufferedImage in the ImageProducer-ImageFilter-ImageConsumer paradigm. Classes that implement this interface must specify whether or not they allow in-place filtering- filter operations where the source object is equal to the destination object. This interface cannot be used to describe more sophisticated operations such as those that take multiple sources. Note that this restriction also means that the values of the destination pixels prior to the operation are not used as input to the filter operation. BufferedImageOpWithWritableVirtualR asterSamplesType_USHORT_RGBA??

18 18 Java Code public static BufferedImage rescale(BufferedImage image, float gain, float bias) { RescaleOp rescaleOp = new RescaleOp(gain, bias, null); return rescaleOp.filter(image, null); } Constructor Summary RescaleOp(float[] scaleFactors, float[] offsets, RenderingHints hints) Constructs a new RescaleOp with the desired scale factors and offsets. Assumes a color image with differing gain and bias values for each band. RescaleOp(float scaleFactor, float offset, RenderingHints hints) Constructs a new RescaleOp with the desired scale factor and offset.

19 19 Java Code public static BufferedImage rescale(BufferedImage image, float gain, float bias) { RescaleOp rescaleOp = new RescaleOp(gain, bias, null); return rescaleOp.filter(image, null); } public final BufferedImage filter(BufferedImage src, BufferedImage dst) Rescales the source BufferedImage. If the color model in the source image is not the same as that in the destination image, the pixels will be converted in the destination. If the destination image is null, a BufferedImage will be created with the source ColorModel. An IllegalArgumentException may be thrown if the number of scaling factors/offsets in this object does not meet the restrictions stated in the class comments above, or if the source image has an IndexColorModel. Specified by: filter in interface BufferedImageOp Parameters: src - the BufferedImage to be filtered dst - the destination for the filtering operation or null. If src = dst then the algorithm performs in- place. Returns: the filtered BufferedImage.

20 20 Non-Linear Mapping A grayscale image f(x,y) can be transformed into image g(x,y) using various non-linear mappings. Require any mapping to be true a function. For any pixel f(x,y), T(x,y) results in a unique deterministic value. Common non-linear gray-scale mappings include log compression: enhances the contrast of darker areas exponential mapping: enhances the contrast of brighter areas

21 21 Log Compression Log compression takes a range of values and “boosts” the lower end. Notice that the higher end is “compressed” into a small range of output values. Logarithmic mapping is useful if we wish to enhance detail in the darker regions of the image, at the expense of detail in the brighter regions.

22 22 Log Compression Example Notice how the darker areas appear brighter and contain more easily viewed details. The brighter areas loose some detail but remain largely unchanged.

23 23 Log Compression Example

24 24 Exponential Mapping Exponential Mapping takes a range of values and “boosts” the upper end. Notice that the lower range is “compressed” into a small range of output values. Exponential mapping is useful if we wish to enhance detail in the brighter regions of the image.

25 25 Exponential Mapping Example Notice how the brighter areas contain more detail in the filtered image. The darker areas loose some detail (are compressed) in this example.

26 26 Gamma Correction Computer monitors and TVs aren’t linear in the way they process signals A “doubling” of the control voltage on a CRT doesn’t usually result in a “doubling” of the intensity of the output color Monitors function according to a “power-law” function Uncorrected monitors may display images that don’t correspond to the original

27 27 Gamma Correction System Gamma

28 28 Gamma Correction Each CRT has its own  value that the manafacturer provides with CRT. Typically   [2,3]

29 29 Gamma correction Cathode ray tube (CRT) devices have an intensity- to-voltage response that is a power function, with  varying from 1.8 to 2.5 The picture will become darker. Gamma correction is done by preprocessing the image before inputting it to the monitor.

30 30 Gamma Correction

31 31 Gamma Correction

32 32 Gamma Example (TV Broadcast) Broadcast System

33 33 Gamma Example (Computer Monitor) Digital/Synthetic Image

34 34 Gamma Correction output = input 1/  Most video cards have a gamma correction setting

35 35 Gamma Correction  If a display is gamma corrected, the nonlinear relationship between pixel value (the number assigned to a particular color tone) and displayed intensity (the way it actually looks) has been adjusted for.  Most graphics cards/monitors have gamma settings  Values typically range from [usually 2.2]  PCs typically have higher gamma settings than Macs so images typically look darker on PCs than Macs

36 36 Gamma Correction If  = 1.0, the result is null transform. If 0    1.0, then the  creates exponential curves that dim an image. If   1.0, then the result is logarithmic curves that brighten an image. RGB monitors have gamma values of 1.4 to 2.8.

37 37 Gamma Chart

38 38 Gamma Correction (a)Gamma correction transformation with gamma = 0.45; (b)Gamma corrected image; (c)Gamma correction transformation with gamma = 2.2; (d)Gamma corrected image

39 39 Gamma Correction

40 40 Effect of decreasing gamma When the  is reduced too much, the image begins to reduce contrast to the point where the image started to have very slight “wash-out” look, especially in the background

41 41 Another example (a) image has a washed-out appearance, it needs a compression of gray levels  needs  > 1 (b) result after power-law transformation with  = 3.0 (suitable) (c) transformation with  = 4.0 (suitable) (d) transformation with  = 5.0 (high contrast, the image has areas that are too dark, some detail is lost) ab cd

42 42 Code Efficiency for Point Processing Operations The algorithm above invokes a square-root function (a relatively expensive operation) and a multiplication for each pixel in F. The algorithm is O(NM) where the input image is NxM. Can this performance be improved? Yes…use lookup-tables! algorithm squareRootFilter(F) INPUT: Gray-scale image F using b bits per pixel OUTPUT: Filtered image Let A be the scaling factor = squareRoot(2^b – 1) Let G be an “empty” image for all pixel coordinates X and Y of the input image G(X,Y) = a * squareRoot(F(X,Y)) return G

43 43 Java Is Fun and Easy! Java has a built-in lookup-table class named ByteLookupTable. Lookup tables can be used in conjunction with LookupOp objects to apply simple point processing operations to images. BufferedImage image; … byte[] table = new byte[256]; double factor = Math.sqrt(255); for(int i=0; i

44 44 Java Is Fun and Easy! java.awt.image Class ByteLookupTable public class ByteLookupTable extends LookupTable This class defines a lookup table object. The output of a lookup operation using an object of this class is interpreted as an unsigned byte quantity. The lookup table contains byte data arrays for one or more bands (or components) of an image, and it contains an offset which will be subtracted from the input values before indexing the arrays. This allows an array smaller than the native data size to be provided for a constrained input. If there is only one array in the lookup table, it will be applied to all bands.

45 45 Java Is Fun and Easy! LookupOp Class Description This class implements a lookup operation from the source to the destination. The LookupTable object may contain a single array or multiple arrays, subject to the restrictions below. For Rasters, the lookup operates on bands. The number of lookup arrays may be one, in which case the same array is applied to all bands, or it must equal the number of Source Raster bands. For BufferedImages, the lookup operates on color and alpha components. The number of lookup arrays may be one, in which case the same array is applied to all color (but not alpha) components. Otherwise, the number of lookup arrays may equal the number of Source color components, in which case no lookup of the alpha component (if present) is performed. If neither of these cases apply, the number of lookup arrays must equal the number of Source color components plus alpha components, in which case lookup is performed for all color and alpha components. This allows non-uniform rescaling of multi- band BufferedImages. ByteLookupTable squareRootTable = new ByteLookupTable(0, table); LookupOp squareRootOp = new LookupOp(squareRootTable, null); BufferedImage filteredImage = squareRootOp.filter(image, null);

46 46 Java Is Fun and Easy

47 47 Thank you Q & A

Download ppt "Lecture 9 Grey Level & Colour Enhancement TK3813 Dr. Masri Ayob."

Similar presentations

Ads by Google