Image Representation and Read/Write CS479/679 – Prof. Bebis.

Slides:



Advertisements
Similar presentations
Web Design Vocab 3 PNG, JPG, GIF, MP3, MPEG.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Introduction to MATLAB and image processing. MATLAB and images The help in MATLAB is very good, use it! An image in MATLAB is treated as a matrix Every.
Buffers Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Buffers Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
CPSC 231 D.H. C++ File Processing 1 Learning Objectives §C++ I/O streams. §Reading and writing sequential files. §Reading and writing random access files.
CSE 803 Using images in C++ Computing with images Applications & Methods 2D arrays in C++ Programming project 4.
Programming Assignment 2 CS308 Fall Goals Improve your skills with using templates. Learn how to compile your code when using templates. Learn more.
Image Representation and Manipulation CS302 Data Structures Prof. George Bebis
Introduction to Image Processing CS474/674 – Prof. Bebis.
Image Formation Fundamentals CS491E/791E. How are images represented in the computer?
Images and MATLAB Source of images: Science&subcategory=Digital Image Processing&isbn=
Image representation methods. Bitmap graphic method of a black-and-white image.
Goals of Computer Vision To make useful decisions based on sensed images To construct 3D structure from 2D images.
WEB GRAPHICS. The Pixel Computer displays are comprised of rows and columns of pixels. Pixels are indivisible. Some common screen resolutions are:, 600.
Filtering (I) Dr. Chang Shu COMP 4900C Winter 2008.
Module Code: CU0001NI Technical Information on Digital Images Week -2.
Image Storage Bitmapped Graphics – in which an image is represented as a collection of dots Vector Graphics – in which an image is represented as a set.
Digital Image: Representation & Processing (2/2) Lecture-3
1 Lesson 3 Power Techniques HTML and JavaScript BASICS, 4 th Edition Barksdale / Turner.
September 21, COMPUTER VISION WEB PAGE IS UP !! OR Simply go to computer science homepage.
ITEC 320 C++ Examples.
C++ Streams Lecture-2.
Image formats. Basic terminologies… Pixels: Pixels are the building blocks of every digital image. a pixel is a single point in a graphic image. Resolutions:
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,
1 © 2010 Cengage Learning Engineering. All Rights Reserved. 1 Introduction to Digital Image Processing with MATLAB ® Asia Edition McAndrew ‧ Wang ‧ Tseng.
Bitmap Graphics. Bitmap Basics Bitmap Graphic Bitmap Graphic Paint Software Paint Software.
Multimedia File FormatsGraphics JPG, GIF, TIF, PSD, WMF, BMP, PNG, RAW.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Stack/Queue - File Processing Lecture 10 March 29, 2005.
Graphics and Images Graphics and images are both non-textual information, that can be displayed and printed. These images may appear on screen as well.
C++ Streams Lecture-2. C++ Streams Stream  A transfer of information in the form of a sequence of bytes I/O Operations:  Input stream: A stream that.
Graphics & Images What File Format Do I Use?. Graphics & Images …..are visual images presented on some form of media (drawings, print, web, digital video)
FILE I/O IN C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
Raster Graphics 2.01 Investigate graphic image design.
Digital Image Editing Presented by John Hohn. File Formats JPEG – Joint Photographic Experts Group PNP – Portable Network Graphics GIF – Graphic Interchange.
Buffers Computer Graphics I, Fall 2010.
Introduction to Image Processing Representasi Citra Tahap-Tahap Kunci pada Image Processing Aplikasi dan Topik Penelitian pada Image Processing.
Digital File Formats By Ali Aslam. JPEG JPEG Stands for Joint Photographic Experts Group. JPEG uses a lossy compression routine. Lossy compression means.
Introduction to Image Processing. What is Image Processing? Manipulation of digital images by computer. Image processing focuses on two major tasks: –Improvement.
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.
Instructor: Mircea Nicolescu Lecture 4 CS 485 / 685 Computer Vision.
HTTP transaction with Graphics HTML file + two graphics files.
Lecture 27: Image Processing
File Processing Files are used for data persistance-permanent retention of large amounts of data. Computer store files on secondary storage devices,such.
Buffers. 2 Objectives Introduce additional OpenGL buffers Learn to read and write buffers Learn to use blending.
CSCI 333 Data Structures I/O with C++ 20 October, 2003.
Lecture 14 Arguments, Classes and Files. Arguments.
Binary Files. Text Files vs. Binary Files Text files: A way to store data in a secondary storage device using Text representation (e.g., ASCII characters)
File I/O in C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
13/15/2016CS150 Introduction to Computer Science 1 Summary  Assignment due on Wednesday, October 29,  Tutor will be in the lab on Tuesday evening,
C++ ReviewEECE 3521 EECS 352 Data Structures and Algorithms José M. Vidal Office: 3A47.
Programming II I/O Streams and Data Files 1(c) Asma AlOsaimi.
Representation of image data
Introduction to raster graphics
What is a File? A file is a collection on information, usually stored on a computer’s disk. Information can be saved to files and then later reused.
2.01 Investigate graphic image design.
A computer display is made up of small squares, called pixels.
Saving Images from Fireworks
Outline Image formats and basic operations Image representation
Image Formation Fundamentals
2.01 Investigate graphic image design.
COMS 161 Introduction to Computing
CS150 Introduction to Computer Science 1
Multimedia Graphics.
2.01 Investigate graphic image design.
"Digital Media Primer" Yue-Ling Wong, Copyright (c)2013 by Pearson Education, Inc. All rights reserved.
Lesson 6 File Types.
PGM Format CS474/674 – Prof. Bebis.
Presentation transcript:

Image Representation and Read/Write CS479/679 – Prof. Bebis

How are images represented in the computer?

Color images

Image file formats Many image formats adhere to the following simple model: –Header –Data

Image file formats (cont.) Header contains at least: –A signature or “magic number” (i.e., a short sequence of bytes for identifying the file format). –The width and height of the image.

Common image file formats PGM (Portable Gray Map) PNG (Portable Network Graphics) GIF (Graphic Interchange Format) JPEG (Joint Photographic Experts Group) TIFF (Tagged Image File Format) FITS (Flexible Image Transport System)

PGM format A popular format for grayscale images (8 bits/pixel) Closely-related formats are: –PBM (Portable Bitmap), for binary images (1 bit/pixel) –PPM (Portable Pixelmap), for color images (24 bits/pixel) ASCII or binary (raw) storage ASCII raw

Image Class - PGM class ImageType { public: ImageType(); // constructor ~ImageType(); // destructor void getImageInfo(int&, int&, int&); void setImageInfo(int, int, int); void setVal(int, int, int); void getVal(int, int, int&); // more functions... private: int N, M, Q; //N: # rows, M: # columns int **pixelValue; };

Input / Output Functions C++ routine to read the header of a PGM image: ReadImageHeader.cpp C++ routine to read a PGM image: ReadImage.cpp C++ routine to write a PGM image: WriteImage.cpp

An example - Threshold.cpp void readImageHeader(char[], int&, int&, int&, bool&); void readImage(char[], ImageType&); void writeImage(char[], ImageType&); void main(int argc, char *argv[]) { int i, j, M, N, Q; bool type; int val, thresh; // read image header readImageHeader(argv[1], N, M, Q, type); // allocate memory for the image array ImageType image(N, M, Q);

Threshold.cpp (cont’d) // read image readImage(argv[1], image); cout << "Enter threshold: "; cin >> thresh; // threshold image for(i=0; i<N; i++) for(j=0; j<M; j++) { image.getVal(i, j, val); if(val < thresh) image.setVal(i, j, 0); else image.setVal(i, j, 255); } // write image writeImage(argv[2], image); }

Reading/Writing PGM images (1D array of unsigned char) (2D array of int) Use “write” Use “read”

Writing a PGM image to a file void writeImage(char fname[], ImageType& image) int N, M, Q; unsigned char *charImage; ofstream ofp; image.getImageInfo(N, M, Q); charImage = (unsigned char *) new unsigned char [M*N]; // convert integer values to unsigned char int val; for(i=0; i<N; i++) for(j=0; j<M; j++) image.getVal(i, j, val); charImage[i*M+j]=(unsigned char)val; }

Writing a PGM image... (cont’d) ofp.open(fname, ios::out | ios::binary); if (!ofp) { cout << "Can't open file: " << fname << endl; exit(1); } ofp << "P5" << endl; ofp << M << " " << N << endl; ofp << Q << endl; ofp.write( reinterpret_cast (charImage), (M*N)*sizeof(unsigned char)); if (ofp.fail()) { cout << "Can't write image " << fname << endl; exit(0); } ofp.close(); }

Reading a PGM image from a file void readImage(char fname[], ImageType& image) { int i, j; int N, M, Q; unsigned char *charImage; char header [100], *ptr; ifstream ifp; ifp.open(fname, ios::in | ios::binary); if (!ifp) { cout << "Can't read image: " << fname << endl; exit(1); }

Reading a PGM image from a file // read header ifp.getline(header,100,'\n'); if ( (header[0]!=80) || // 'P' (header[1]!=53) ) { // '5' cout << "Image " << fname << " is not PGM" << endl; exit(1); } ifp.getline(header,100,'\n'); // skip comments while(header[0]=='#') ifp.getline(header,100,'\n'); M=strtol(header,&ptr,0); // read M, N N=atoi(ptr);

Reading a PGM image …. (cont’d) ifp.getline(header,100,'\n'); // read Q Q=strtol(header,&ptr,0); charImage = (unsigned char *) new unsigned char [M*N]; ifp.read( reinterpret_cast (charImage), (M*N)*sizeof(unsigned char)); if (ifp.fail()) { cout << "Image " << fname << " has wrong size" << endl; exit(1); } ifp.close();

Reading a PGM image…(cont’d) // Convert unsigned characters to integers int val; for(i=0; i<N; i++) for(j=0; j<M; j++) { val = (int)charImage[i*M+j]; image.setVal(i, j, val); }

Color Images struct RGB { RGB(int, int, int); RGB& operator=(RGB); int r, g, b; } RGB;

Image Class – PPM class ImageType { public: ImageType(); // constructor ~ImageType(); // destructor void getImageInfo(int&, int&, int&); void setImageInfo(int, int, int); void setVal(int, int, RGB); void getVal(int, int, RGB&); // more functions... private: int N, M, Q; //N: # rows, M: # columns RGB **pixelValue; };

ReadImage - PPM charImage = (unsigned char *) new unsigned char [3*N*M]; ifp.read( reinterpret_cast (charImage), (3*M*N)*sizeof(unsigned char)); RGB val; for(i=0; i < N; i++) for(j=0; j < 3*M; j+=3) { val.r = (int)charImage[i*3*M+j]; val.g = (int)charImage[i*3*M+j+1]; val.b = (int)charImage[i*3*M+j+2]; image.setPixelVal(i, j/3, val); }

WriteImage - PPM charImage = (unsigned char *) new unsigned char [3*M*N]; for(i=0; i<N; i++) for(j=0; j<3*M; j+=3) { image.getPixelVal(i, j/3, val); charImage[i*3*M+j]=(unsigned char)val.r; charImage[i*3*M+j+1]=(unsigned char)val.g; charImage[i*3*M+j+2]=(unsigned char)val.b; } ofp.write( reinterpret_cast (charImage), (3*M*N)*sizeof(unsigned char));

How do I “see” images on my computer? Unix/Linux: xv, gimp Windows: Photoshop Irfanview

How do I convert an image from one format to another? Use “Save As” option