Image representation methods. Bitmap graphic method of a black-and-white image.

Slides:



Advertisements
Similar presentations
Pixels and Digital Images Yrd. Doc. Dr. Ahmet Sayar Kocaeli Universitesi Bilgisayar Muhendisligi Ileri Bilgisayar Grafikleri.
Advertisements

L.Ghadah R. Hadba CT1514-L1.  Computer Graphics :refers to processing of creating a new image from Geometry, Lighting parameters, Materials and Textures.Using.
CSE Lecture 6 – Complex Numbers & Images
Bit Depth and Spatial Resolution SIMG-201 Survey of Imaging Science © 2002 CIS/RIT.
Buffers Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Image Representation and Manipulation CS302 Data Structures Prof. George Bebis
CS430 © 2006 Ray S. Babcock CS430 – Image Processing Image Representation.
First Bytes - LabVIEW. Today’s Session Introduction to LabVIEW Colors and computers Lab to create a color picker Lab to manipulate an image Visual ProgrammingImage.
We have seen the notation “p=&a; ” used to set the pointer “p” to the address of another variable. For arrays and strings, the technique for setting the.
Image and Sound Editing Raed S. Rasheed Image Image. Digital image. – Raster images. – Vector Images. – Stereo Images. – Image File Formats Lossless.
Two-week ISTE workshop on Effective teaching/learning of computer programming Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal.
1 Internet Graphics. 2 Representing Images  Raster Image: Images consist of “dots” of color, not lines  Pixel: Picture element-tiny rectangle  Resolution:
Prepared by George Holt Digital Photography BITMAP GRAPHIC ESSENTIALS.
Filtering (I) Dr. Chang Shu COMP 4900C Winter 2008.
Faculty of Sciences and Social Sciences HOPE Website Development Graphics Stewart Blakeway FML 213
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
Lab #5-6 Follow-Up: More Python; Images Images ● A signal (e.g. sound, temperature infrared sensor reading) is a single (one- dimensional) quantity that.
Objective Understand concepts used to create digital graphics. Course Weight : 15% Part Three : Concepts of Digital Graphics.
Graphics/Image Data Types
COSC 1P02 Intro. to Computer Science 6.1 Cosc 1P02 Week 6 Lecture slides "To succeed, jump as quickly at opportunities as you do at conclusions." --Benjamin.
Foundations of Web Design I Photoshop CS5 Michael Daniel
1 Computer Graphics Part 2: Images. 2 What is an image?  An image is the graphical and visual representation of some information that can be displayed.
© 1999 Rochester Institute of Technology Introduction to Digital Imaging.
L. Akshay Masare Piyush Awasthi IMAGE PROCESSING AND OPENCV.
September 21, COMPUTER VISION WEB PAGE IS UP !! OR Simply go to computer science homepage.
Image Representation. Objectives  Bitmaps: resolution, colour depth and simple bitmap file calculations.  Vector graphics: drawing list – objects and.
Color and Resolution Introduction to Digital Imaging.
Two –Dimensional Arrays Mrs. C. Furman Java Programming November 19, 2008.
Structured data types An elegant way to deal with the rgb image is to employ structured data types. A Java class is a generalization of a C struct. A structure.
CS- 375 Graphics and Human Computer Interaction Lecture 1: 12/4/1435 Fundamental Techniques in Graphics Lecturer: Kawther Abas.
Image Representation. Digital Cameras Scanned Film & Photographs Digitized TV Signals Computer Graphics Radar & Sonar Medical Imaging Devices (X-Ray,
File IO and command line input CSE 2451 Rong Shi.
ADOBE PHOTOSHOP VECTOR VS RASTER. Pixel A pixel is the fundamental unit of an image in Photoshop. It is a small square block of color. An image often.
Digital Media Lecture 4.1: Image Encoding Practice Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Multimedia Basics (1) Hongli Luo CEIT, IPFW. Topics r Image data type r Color Model : m RGB, CMY, CMYK, YUV, YIQ, YCbCr r Analog Video – NTSC, PAL r Digital.
Introduction to Raytracing Raytracing Introduction (from Wikipedia) In computer graphics, ray tracing is a technique for generating an image by tracing.
Memory Layout, File I/O Bryce Boe 2013/06/27 CS24, Summer 2013 C.
Images. Digital Images Rectangular arrays of pixel data Pixel - picture element, smallest addressable part of the frame buffer. Color depth - the depth.
Buffers Computer Graphics I, Fall 2010.
Image File Formats By Dr. Rajeev Srivastava 1. Image File Formats Header and Image data. A typical image file format contains two fields namely Dr. Rajeev.
Buffers. 2 Objectives Introduce additional OpenGL buffers Learn to read and write buffers Learn to use blending.
CS 1704 Introduction to Data Structures and Software Engineering.
Multi-dimensional Arrays and other Array Oddities Rudra Dutta CSC Spring 2007, Section 001.
Chapter 3 Color Objectives Identify the color systems and resolution Clarify category of colors.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Digital Media Lecture 4.2: Image Encoding Practice Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Direct-Access Color Graphics Chapter 11. Graphics modes C++ provides a different combination of graphics characteristics. These characteristics include.
Information in Computers. Remember Computers Execute algorithms Need to be told what to do And to whom to do it.
Image Representation and Read/Write CS479/679 – Prof. Bebis.
Representation of image data
Data Representation Images.
Sampling, Quantization, Color Models & Indexed Color
Image Processing CS177.
Chapter 3 Graphics and Image Data Representations
Reading Netpbm Images.
Raster Images CPSC 1030.
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Programming in C Input / Output.
CS320n –Visual Programming
Outline Image formats and basic operations Image representation
6th Lecture – Rectangles and Regions, and intro to Bitmap Images
Representing Images 2.6 – Data Representation.
sscanf()- string scan function
Nuts and Bolts of Digital Imaging
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Line at a time I/O with fgets() and fputs()
Basic Concepts of Digital Imaging
Block I/O fread and fwrite functions are the most efficient way to read or write large amounts of data. fread() – reads a specified number of bytes from.
"Digital Media Primer" Yue-Ling Wong, Copyright (c)2013 by Pearson Education, Inc. All rights reserved.
PGM Format CS474/674 – Prof. Bebis.
Presentation transcript:

Image representation methods

Bitmap graphic method of a black-and-white image

Representation of color pixels

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 an uncompressed data file. The.ppm file can be viewed with a number of tools, including xv and gimp. Other well-known image formats include JPEG (.jpg), TIFF (.tif), and PNG (.png)

Types of Images We will use.ppm files to represent two types of images A.ppm image file contains the representation of an image (like a.jpg or.gif file) and can be in one of several different formats for an image. The PPM (Portable PixMap) format is used to represent images that contain color. A PGM (Portable GrayMap) format is used for grayscale images. The format of the file can be determined by the first two bytes. The code “P5” indicates that this is a PGM file, the code “P6” indicates this is a PPM file.

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.

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.

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

PPM file structure A ppm file consists of two components: – ppm header – packed image data

PPM file structure Example of a.ppm header for a color image P6 # This is a comment – 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.

PPM file structure The image data – The red component of the upper left pixel must immediately follow the new line. – For the image described earlier, there must be a total of 3 x 600 x 400 = 72,000 bytes of data.

As we have seen, the header of a.ppm file contains mixed input data. While scanf() provides a handy way to process input files consisting of only numeric data, the handling of mixed input can be more difficult. Processing Heterogeneous Input Files

The following is an example of the header for a PGM file: P5 # CREATOR: XV Version 3.10a Rev: 12/29/94 (PNG patch 1.2) # This is another comment # So is this 255 Items of useful information in this header include: P - this is a.ppm file 5 - this is a.ppm file containing a grayscale PGM (as opposed to color “P6”) image the number of columns of pixels in each row of the image the number of rows of pixels in the image the maximum brightness value for a pixel Processing Heterogeneous Input Files

Comment lines Lines beginning with # are comments. Any number (including 0) of comment lines may be present. It is possible for all the useful values to appear on one line: P Or they could be specified as follows: P Or they could be specified as follows: P5 # 1024 # This is a comment Processing Heterogeneous Input Files

Unfortunately life is rarely nice and simple and this program won't work if the.ppm header looks like P6 # comment 768 # another Reading.ppm headers with fgets() and sscanf()

Because of the arbitrary location and number of comment lines there is no good way to read the data using scanf(). A better approach is to use a combination of fgets() and the sscanf() function. The sscanf() function operates in a manner similar to fscanf() but instead of consuming data from a file it will consume data from a memory resident buffer. Like fscanf() it returns the number of items it successfully consumed from the buffer. Reading.ppm headers with fgets() and sscanf()

So if the.ppm header is nice and simple like: P the following program would suffice to read it: 13 int main() 14 { 15 char id[3] = {0, 0, 0}; /* Will hold P5 or P6*/ 16 long vals[5]; /* The 3 ints */ 17 int count = 0; /* # of vals so far */ 19 char *buf = malloc(256); /* the line buffer */ fgets(buf, 256, stdin); 22 id[0] = buf[0]; 23 id[1] = buf[1]; 24 count = sscanf(buf + 2, “%d %d %d”, 25 &vals[0], &vals[1], &vals[2]); 27 printf(“Got %d vals \n”, count); 28 printf(“%4d %4d %4d\n”, vals[0], vals[1],vals[2]); 29 } Reading.ppm headers with fgets() and sscanf()

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 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);

Buliding a.ppm file int main() { int width; int height; int count = 0; 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; }

Building 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 < size) { make_pixel(r, g, b); count = count + 1; }

Buliding a.ppm file /* print void make_pixel(int r, int g, int b) { fprintf(stdout, “%c%c%c”, 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); }

The.ppm file You can view the details of the file with the ls -l command. ls -l pic1.ppm -rw rlowe faculty Sep 14 20:35 pic1.ppm Note: size of file is (header length) 3 x 200 x 150 = (image data) 90015

The image

Example 2 /* CPSC 2100: redgreen.c This program creates a ppm file for a 600x400 box, that is red in the left half and green in the right half. The ppm image is written to the file specified on the command line, e.g. the program is initiated as:./redgreen output-filename which would create the PPM image file specified by output-filename */

Example 2 #include #include "rgb.h" int main(int argc, char *argv[]) { pixel_t *img; /* image array */ pixel_t *pixaddr = NULL; /* address of current pixel */ int rowNdx, colNdx; /* Row and column indices */ FILE *imageFP; /* PPM output file */

Example 2 /* Open the PPM output file */ if (argc != 2) { fprintf(stderr, "Usage:./redgreen output-filename\n"); exit(1); } imageFP = fopen(argv[1], "w"); assert(imageFP != NULL); img = (pixel_t *) malloc(sizeof(pixel_t) * 600 * 400); if(img == NULL) { fprintf(stderr, "Could not malloc memory for img. Exiting\n"); exit(2); }

Example 2 pixaddr = img; /* Write the ppm header */ fprintf(imageFP, "P \n"); /* Write the pixel data */ for (rowNdx = 0; rowNdx < 400; rowNdx++) { for (colNdx = 0; colNdx < 600; colNdx++) { pixaddr->blue = 0; /* No blue in image */ if (colNdx < 300 ) { /* Left half of image */ pixaddr->red = 255; pixaddr->green = 0; } else { /* Right half of image */ pixaddr->red = 0; pixaddr->green = 255; } pixaddr++; }

Example 2 /* Write out the pixel */ fwrite(img, sizeof(pixel_t), 600 * 400, imageFP); /* release allocated memory */ free(img); return 0; } The code produces the following red-green image

The image