+ All Categories
Home > Documents > Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Date post: 02-Jan-2016
Category:
Upload: magnus-reynolds
View: 221 times
Download: 3 times
Share this document with a friend
33
Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY
Transcript
Page 1: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Pixels, Images and

Image Files

1By Dr. HANY ELSALAMONY

Page 2: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Image files (in particular, the BMP file format)

How to save your OpenGL images to a fileHow to view image files within your OpenGL

programHow to manipulate pixel data from an image

2By Dr. HANY ELSALAMONY

Page 3: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

A raster image file is a file that stores the mapping of pixel coordinates to color values. That is, the file saves the color at each pixel coordinate of the image.

The saved image files can then be used for various purposes such as printing, editing, etc.

Some commonly used image file types are: BMP, TIFF, GIF, and PEG files.

3By Dr. HANY ELSALAMONY

Page 4: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

A raster file contains graphical information about the colors of the pixels. It also contains information about the image itself, such as its width and height, format, etc.

Let us look into the details of a commonly used raster file format called BMP.

4By Dr. HANY ELSALAMONY

Page 5: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The BMP file format is the most common graphics format used on the Windows platform. The motivation behind creating the BMP format was to store raster image data in a format independent of the color scheme used on any particular hardware system.

The data in BMP files is stored sequentially in a binary format and is sometimes compressed. Table (1) shows the basic format of the bmp file which consists of either 3 or 4 parts.

5By Dr. HANY ELSALAMONY

Page 6: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

6By Dr. HANY ELSALAMONY

Table (1): Parts of the BMP file

Page 7: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The first part of the file is the header. The header contains information about the type of image (BM, for BMP), its size, and the position of the actual image data with respect to the start of the file.

The second part of the BMP file is the image information section. Information such as the image width and height, type of compression and the number of colors is contained in the information header.

7By Dr. HANY ELSALAMONY

Page 8: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The fields of most interest are the image width and height, the number of bits per pixel (which should be 1, 4, 8 or 24), and the compression type.

Compressions are techniques applied to files

to reduce their size. Compression techniques are especially useful in the case of raster image files, which tend to be huge.

8By Dr. HANY ELSALAMONY

Page 9: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The compression types supported by BMP are listed below:

0: no compression1: 8 bit run length encoding2: 4 bit run length encoding3: RGB bitmap with mask

9By Dr. HANY ELSALAMONY

Page 10: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The pixel data is stored by rows, left to right within each row. The rows are stored from bottom to top. The bits of each pixel are packed into bytes, and each scan line is padded with zeros to be aligned with a 32-bit boundary.

Since the bitmap image format is so simple, reading bitmap files is also very simple. The simplest data to read is 24-bit true color images.

10By Dr. HANY ELSALAMONY

Page 11: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

In this case the image data follows immediately after the information header. It consists of three bytes per pixel in BGR (yes, it's in reverse) order.

Each byte gives the intensity for that color component-0 for no color and 255 for fully saturated

11By Dr. HANY ELSALAMONY

Page 12: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Logical operations are performed between two data bits (except for the NOT operation, which is performed on one). Bits can be either 1 or 0 (sometimes referred to as TRUE and FALSE).

The most basic logical operators that can be performed on these bits are: AND, OR, XOR, and INVERTINOT. These operators are essential to performing digital math operations.

12By Dr. HANY ELSALAMONY

Page 13: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Since pixels are nothing more than a series of bits in a buffer, they can be combined using bitwise logical operations (that is, we apply the logical operations to each corresponding bit).

The operations are applied between the incoming pixel values (source) and those currently into the frame buffer (destination).

13By Dr. HANY ELSALAMONY

Page 14: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The resultant pixel values are saved back in the frame buffer.

For true color pixels, the operations are performed on the corresponding bits of the two pixel values, yielding the final pixel value.

14By Dr. HANY ELSALAMONY

Page 15: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The following figure show the OR operator applied to two monochrome (single bit) pixel values.

The bits with value 1 are shown in a white color, and those with value 0 are shown in black.

15By Dr. HANY ELSALAMONY

Page 16: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

An AND operator uses the source as a mask to select pixels in the destination and clears out the rest, as shown in Figure.

Image compositing, where two images are combined in some manner to create a third resultant image, make use of these two operations heavily.

16By Dr. HANY ELSALAMONY

Page 17: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

XORing the source over the destination guarantees that the source stands out.

This technique is used very often in rubber-banding, where a line or a rectangle is dragged around by the user on top of a background image.

17By Dr. HANY ELSALAMONY

Rubber-banding: XOR of a line with the background image

Page 18: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The neat thing about an XOR operation is that two XORs generates the same values back again. That is,

(A XOR B) XOR A = B.This operation is often used to erase a

previously drawn image.

If you have ever tried selecting a number of programs on the Windows desktop, now you know that it's done are using the XOR operator.

18By Dr. HANY ELSALAMONY

Page 19: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

19By Dr. HANY ELSALAMONY

XORing twice

Page 20: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

we can use the XOR operation to first draw the smiley face and then XOR once again to erase only the portion we drew into.

This technique tends to be a much faster operation than redrawing the entire background and is therefore used extensively in gaming.

20By Dr. HANY ELSALAMONY

Page 21: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

This approach works best for constant color images, since the colors do get flipped on the first XOR.

For multicolor images, the XOR operation may result in psychedelic colors being produced. As a result, XOR should be used only when the image colors are designed to work for it.

21By Dr. HANY ELSALAMONY

Page 22: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The real value of saving images on the computer is image processing - what can be done to the image once it is resident on the computer.

Effects like blending, compositing, and cleaning up pixel values are used routinely in productions.

The idea behind image processing is simple: manipulate the pixel information of the given image using some mathematical functions and save the result in a new image file.

We discuss two techniques in this section, namely, compositing and red-eye removal.

22By Dr. HANY ELSALAMONY

Page 23: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Compositing is the most widely used operation in the post-production of films, commercials, and even TV broadcasts.

The basic operation in image compositing is to overlay one (usually nonrectangular) image on top of the other.

23By Dr. HANY ELSALAMONY

Page 24: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Various techniques are used for compositing images. One popular technique is the blue screen process.

First, the subject is photographed in front of an evenly lit, bright, pure blue background. Then the compositing process, whether photographic or electronic, replaces all the blue in the picture with the background image, known as the background plate.

24By Dr. HANY ELSALAMONY

Page 25: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

In reality, any color can be used for the background, but blue has been favored since it is the complementary color to flesh tone.

The source and destination images can come from live action images or be computer generated.

Jurassic Park employed compositing extensively to composite CG-generated dinosaurs in front of real live shots.

25By Dr. HANY ELSALAMONY

Page 26: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The essential compositing algorithm is as shown below. It designates Blue or the desired color as transparent. The source image is copied on top of a defined destination image as follows:

26By Dr. HANY ELSALAMONY

Page 27: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

The only problem, of course, is that "transparent" color can't be used in the source image.

By Dr. HANY ELSALAMONY 27

Page 28: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Another technique for compositing, being used more frequently now makes use of a mask or stencil. This technique uses logical operations as follows:

Create a mask of the image. Many production houses create the mask as part of the alpha channel of the image. The mask essentially identifies the desired areas of the source image.

AND the source with the mask (not always required).AND the background with NOT of maskOR the results to produce the final composite.

By Dr. HANY ELSALAMONY 28

Page 29: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

By Dr. HANY ELSALAMONY 29

Image Composition using masks

Page 30: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

Image enhancements are possible because we have access to the actual pixel information of the image.

we can target specific pixels based on some criteria and then change their values. You may have used a very common feature in image processing tools-red-eye removal.

we load in a smiley face with red eyes. The eyes are made up of pixels with a color value of (255,0,0). We will target pixels with this color and change them to blue.

By Dr. HANY ELSALAMONY 30

Page 31: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

To do this, we first determine the length of each row. Using the length, we can point to any desired row in the pixmap as the pixel-row variable.

Then we loop through the columns of pixel values in this row.

If we determine the pixel value in any column has a red color, we change it to blue.

By Dr. HANY ELSALAMONY 31

Page 32: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

By Dr. HANY ELSALAMONY 32

Page 33: Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.

When you run this code, the display will show a blue-eyed smiley face! You can save the result to a file to verify that we did indeed perform red-eye removal.

This is an oversimplification of the actual mechanics behind red eye reduction, but you get the idea.

Now when you use a processing tool to get rid of the reds, you will know what kind of technology is working in the background.

By Dr. HANY ELSALAMONY 33


Recommended