0% found this document useful (0 votes)
1K views5 pages

Direct Coding

The document discusses image representation using lookup tables. It explains that lookup tables allow for lower storage requirements while still supporting a reasonable number of colors. Pixel values serve as indices into the table to retrieve the corresponding color value. A common 8-bit format uses a 256-entry lookup table with 24-bit RGB color values, allowing 256 colors from 16.7 million possibilities and requiring 1 million bytes of storage for a 1000x1000 image. Direct coding represents each pixel's color directly without a lookup table, commonly using 24 bits (8 for each RGB value) for over 16 million colors but requiring higher storage.

Uploaded by

Aliyu Sani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views5 pages

Direct Coding

The document discusses image representation using lookup tables. It explains that lookup tables allow for lower storage requirements while still supporting a reasonable number of colors. Pixel values serve as indices into the table to retrieve the corresponding color value. A common 8-bit format uses a 256-entry lookup table with 24-bit RGB color values, allowing 256 colors from 16.7 million possibilities and requiring 1 million bytes of storage for a 1000x1000 image. Direct coding represents each pixel's color directly without a lookup table, commonly using 24 bits (8 for each RGB value) for over 16 million colors but requiring higher storage.

Uploaded by

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

LOOKUP TABLE

Image representation using a lookup table can be viewed as a compromise between


our desire to have a lower storage requirement and our need to support a
reasonably sufficient number of simultaneous colors. In this approach pixel values do
not code colors directly. Instead, they are addresses or indices into a table of color
values. The color of a particular pixel is determined by the color value in the table
entry that the value of the pixel references.
Figure 1.1 shows a lookup table with 256 entries. The entries have addresses 0
through 255. Each entry contains a 24-bit RGB color value. Pixel values are now 1-
byte, or 8-bit, quantities. The color of a pixel whose value is i, where 0 ≤i≤ 255, is
determined by the color value in the table entry whose address is i. This 24-bit 256-
entry lookup table representation is often referred to as the 8-bit format. It reduces
the storage requirement of a 1000 x 1000 image to one million bytes plus 768 bytes
for the color values in the lookup table. It allows 256 simultaneous colors that are
chosen from 16.7 million possible colors.

Fig 1.1: A 24-bit 256-entry lookup


table

It is important to remember that,


using the lookup table
representation, an image is
defined not only by its pixel
values but also by the color
values in the corresponding
lookup table. Those color values
form a color map for the image.

DIRECT CODING
Image representation is essentially the
representation of pixel colors. Using
direct coding we allocate a certain amount of storage space for each pixel to code its color. For
example, we may allocate 3 bits for each pixel, with one bit for each primary color (see Fig. 1.2). This
3-bit representation allows each primary to vary independently between two intensity levels: 0 (off)
or 1 (on). Hence each pixel can take on one of the eight colors that correspond to the corners of the
RGB color cube.
bit 1: r bit 2: g bit 3: b Color name
0 0 0 black
0 0 1 blue
0 1 0 green
0 1 1 cyan
1 0 0 red
1 0 1 magenta
1 1 0 yellow
1 1 1 white

Fig. 1.2: Direct coding of colors using 3 bits

A widely accepted industry standard uses 3 bytes, or 24 bits, per pixel, with one byte for each
primary color. This way we allow each primary color to have 256 different intensity levels,
corresponding to binary values from 00000000 to 11111111. Thus, a pixel can take on a color from
256 x 256 x 256 or 16.7 million possible choices. This 24-bit format is commonly referred to as the
true color representation, for the difference between two colors that differ by one intensity level in
one or more of the primaries is virtually undetectable under normal viewing conditions. Hence a
more precise representation involving more bits is of little use in terms of perceived color accuracy.

A notable special case of direct coding is the representation of black-and-white (bilevel) and gray-
scale images, where the three primaries always have the same value and hence need not be coded
separately. A black-and-white image requires only one bit per pixel, with bit value 0 representing
black and 1 representing white. A gray-scale image is typically coded with 8 bits per pixel to allow a
total of 256 intensity or gray levels.

Although this direct coding method features simplicity and has supported a variety of applications,
we can see a relatively high demand for storage space when it comes to the 24-bit standard. For
example, a 1000 x 1000 true color image would take up to three million bytes.

Dithering
A technique called dithering can be used to approximate halftones without reducing spatial
resolution. Halftones are reproductions of photographs or other images in which various tones of
grey or color are produced by variously sized dots of ink. Spatial resolution, on the other hand,
is a measure of the smallest object that can be resolved by the sensor, or the ground area
imaged for the instantaneous field of view (IFOV) of the sensor, or the linear dimension on
the ground represented by each pixel

In this approach, the dither matrix is treated very much like a floor tile that can be repeatedly
positioned one copy next to another to cover the entire floor, Le., the image. A pixel at (x, y) is
intensified if the intensity level of the image at that position is greater than the corresponding value
in the dither matrix.

Mathematically, if Dn, stands for an n x n dither matrix, the element Dn(i, j) that corresponds to pixel
position (x, y) can be found by i=x mod n and j= y mod n. For example, if we use the 3 x 3 matrix

given earlier for a bilevel reproduction and the pixel of the image at position (2, 19) has intensity
level 5, then the corresponding matrix element is D 3(2, 1) = 3, and hence a dot should be printed or
displayed at that location.

It should be noted that, for image areas that have constant intensity, the results of dithering are
exactly the same as the results of halftone approximation. Reproduction differences between these
two methods occur only when intensity varies.

Error Diffusion

Another technique for continuous-tone reproduction without sacrificing spatial resolution is called
the Floyd-Steinberg error diffusion. Here, a pixel is printed using the closest intensity the device can
deliver. The error term, i.e., the difference between the exact pixel value and the approximated
value in the reproduction, is then propagated to several yet-to-be-processed neighboring pixels for
compensation. More specifically, let S be the source image that is processed in a left-to-right and
top-to-bottom pixel order, S(x, y) be the pixel value at location (x, y), and e be S(x, y) minus the
approximated value. We update the value of the pixel's four neighbors (one to its right and three in
the next scan line) as follows:

a. S(x+1, y) = S(x+1, y) + ae
b. S(x-1, y-1) = S(x-1, y-1) + be
c. S(x, y − 1) = S(x, y − 1) + ce
d. S(x + 1, y − 1) = S(x+1, y − 1) + de

7 3 5 ,∧1
where parameters a through d often take values , , respectively. These
16 16 16 16
modifications are for the purpose of using the neighboring pixels to offset the reproduction error at
the current pixel location. They are not permanent changes made to the original image.

Consider, for example, the reproduction of a grayscale image (0: black, 255: white) on a bilevel
device (level 0: black, level 1: white), if a pixel whose current value is 96 has just been mapped to
level 0, we have e = 96 for this pixel location. The value of the pixel to its right is now increased by
7
96 x =42 in order to determine the appropriate reproduction level. This increment tends to
16
cause such neighboring pixels to be reproduced at a higher intensity level, partially compensating
the discrepancy brought on by mapping value 96 to level 0 (which is lower than the actual pixel
value) at the current location. The other three neighboring pixels (one below and to the left, one
immediately below, and one below and to the right) receive 18, 30, and 6 as their share of the
reproduction error at the current location, respectively.

Results produced by this error diffusion algorithm are generally satisfactory, with the occasional
introduction of slight echoing of certain image parts. Improved performance can sometimes be
obtained by alternating scanning direction between left-to-right and right-to-left (minor
modifications need to be made to the above formulas).

Questions and answers


1. If we want to resize a 1024 x 768 image to one that is 640 pixels wide with the same aspect
ratio, what would be the height of the resized image?

SOLUTION

Height = 640 x 768/1024 = 480

2. If we want to cut a 512 x 512 sub-image out from the center of an 800 x 600 image, what are
the coordinates of the pixel in the large image that is at the lower left corner of the small
image?

SOLUTION

[(800-512)/2, (600-512)/2] = (144, 44).

3. Sometimes the pixel at the upper left corner of an image is considered to be at the origin of
the pixel coordinate system (a left-handed system). How to convert the coordinates of a
pixel at (x, y) in this coordinate system into its coordinates (x, y) in the lower-left-corner-as-
origin coordinate system (a right-handed system)?

SOLUTION

x ' , y ' =( x , m− y−1)where m is the number of pixels in the vertical direction.


4. Find the CMY coordinates of a color at (0.2, 1,0.5) in the RGB space.

SOLUTION

(1 - 0.2, 1- 1, 1 - 0.5) = (0.8, 0, 0.5).

5. Find the RGB coordinates of a color at (0.15, 0.75, 0) in the CMY space.

SOLUTION

(1 - 0.15, 1 - 0.75, 1 - 0) (0.85, 0.25, 1).

6. What are the error propagation formulas for a top-to-bottom and right-to-left scanning
order in the Floyd Steinberg error diffusion algorithm?

SOLUTION

a. S(x+1, y) = S(x+1, y) + ae
b. S(x-1, y-1) = S(x-1, y-1) + be
c. S(x, y − 1) = S(x, y − 1) + ce
d. S(x + 1, y − 1) = S(x+1, y − 1) + de

7 3 5 ,∧1
where parameters a through d often take values , , respectively.
16 16 16 16
7. What is RLE?

SOLUTION

RLE stands for run-length encoding, a technique for image data compression.
8. Develop a pseudo-code segment to swap the red and green components of all colors in a
256-entry lookup table.

SOLUTION

int i, x, rgb[3];

for (i=0, i<256, i++) {

getEntry(i, rgb);

x = rgb[0];

rgb[0] = rgb[1];

rgb[1] =x;

setEntry (i, rgb);

9. Develop a pseudo-code segment to draw a rectangular area of w x h (in a number of pixels)


that starts at (x, y) using color rgb.

SOLUTION

Int i, j;

for (j=y, j< y + h; j++)

for (i= x; i< x + w; i++) setPixel(i, j):

You might also like