PPM Images - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

PPM Images

Description:

Images (e.g. digital photos) consist of a rectanglular array of discrete picture ... An image consisting of 200 pixels rows of 300 pixels per row contains 200 x 300 ... – PowerPoint PPT presentation

Number of Views:131
Avg rating:3.0/5.0
Slides: 18
Provided by: rlo60
Category:
Tags: ppm | images

less

Transcript and Presenter's Notes

Title: PPM Images


1
PPM Images
2
Image representation methods
3
Bitmap graphic method of a black-and-white image
4
Representation of color pixels
5
Representation of image data
  • Images (e.g. digital photos) consist of a
    rectanglular array of discrete picture elements
    called pixels.
  • An image consisting of 200 pixels rows of 300
    pixels per row contains 200 x 300 60,000
    individual pixels.
  • The Portable PixMap (.ppm) format is a
    particularly simple way used to encode a
    rectangular image (picture) as uncompressed data
    file.
  • The .ppm file can be viewed with a number of
    tools, including xv and gimp.
  • Other well-known formats include JPEG (.jpg),
    TIFF (.tif), and PNG (.png)

6
Types of Images
  • We will use .ppm to represent two types of images
  • Grayscale images
  • correspond to black / white photographs
  • each pixel consists of 1 byte which should be
    represented as unsigned char
  • a value of 0 is solid black
  • a value of 255 is bright white
  • intermediate are "gray" values of increasing
    brightness.

7
Types of Images
  • Color images
  • correspond to color photographs
  • each pixel consists of 3 bytes with each byte
    represented as an unsigned char
  • this format is called RGB. three bytes represent
    the
  • red component
  • green component
  • blue component
  • when red green blue a grayscale "color" is
    produced.
  • (255, 255, 255) is bright white.

8
Images
  • Colors are additive
  • (255, 255, 0) red green bright yellow
  • (255, 0, 255) red blue magenta (purple)
  • (0, 255, 255) green blue cyan (turquoise)
  • (255, 255, 255) red green blue white

9
PPM file structure
  • ppm header
  • packed image data
  • The .ppm header
  • P6
  • This is a comment
  • 600 400 255

10
PPM file structure
  • The .ppm header
  • P6
  • This is a comment
  • 600 400 255
  • The P6 indicates this is a color image (P5 means
    grayscale)
  • The width of the image is 600 pixels
  • The height of the image is 400 pixels
  • The 255 is the maximum value of a pixel
  • Following the 255 is a \n (0x0a) character.

11
PPM file structure
  • The image data
  • The red component of the upper left pixel must
    immediately follow the new line.
  • There must be a total of 3 x 600 x 400 72,000
    bytes of data.

12
Buliding a .ppm file
  • / image1.c /
  • / Construct a solid color image of the
    specified color /
  • / Input arguments
    /
  • / width in pixels
    /
  • / height in pixels
    /
  • / red value
    /
  • / green value
    /
  • / blue value
    /
  • include ltstdio.hgt
  • void make_ppm_header(int width, int len)
  • void make_pixel (unsigned char r, unsigned char
    g, unsigned char b)
  • void make_ppm_image(int width, int height,
    unsigned char r, unsigned char g, unsigned char
    b)
  • int main()
  • int width
  • int height

13
Buliding a .ppm file
  • unsigned int red
  • unsigned int green
  • unsigned int blue
  • fscanf(stdin, "d", width)
  • fscanf(stdin, "d", height)
  • fscanf(stdin, "d", red)
  • fscanf(stdin, "d", green)
  • fscanf(stdin, "d", blue)
  • make_ppm_header(width, height)
  • make_ppm_image(width, height, red, green,
    blue)
  • return 0

14
Buliding a .ppm file
  • / create the ppm image
  • void make_ppm_image(int width, int height,
    unsigned char r, unsigned char g, unsigned char
    b)
  • int count 0
  • int size width height
  • while (count lt size)
  • make_pixel(r, g, b)
  • count count 1

15
Buliding a .ppm file
  • / print
  • void make_pixel(int r, int g, int b)
  • fprintf(stdout, ccc, r, g, b)
  • / print the ppm header /
  • void make_ppm_header(int width, int height)
  • fprintf(stdout, P6\n)
  • fprintf(stdout, d d d\n, width,
    height, 255)

16
The .ppm file
  • You can view the details of the file with the ls
    -l command.
  • lowerm_at_shadow7102 ls -l pic1.ppm
  • -rw------- 1 lowerm faculty 90015 Sep 14 2035
    pic1.ppm
  • size of file is 90015
  • 15 (header length)
  • 3 x 200 x 150 90000 (image data)
  • 90015

17
The image
Write a Comment
User Comments (0)
About PowerShow.com