80 likes | 193 Vues
This document serves as an introductory guide to image processing, focusing on the Portable Gray Map (PGM) file format. It covers the essentials of preparing for practical exercises using Linux Ubuntu, including editors such as vi and gcc compiler for C programming. Users will learn about the structure of PGM files, file headers, and how to read and write pixel values. Practical exercises are included to display images and pixel values for enhanced understanding. Aimed at beginners, this guide provides the foundation for further exploration in image processing.
E N D
14 Januari 2011 Pengantar Image Processing- Pendahuluan - Dr. Anto Satriyo Nugroho Center for Information & Communication Technology, Agency for the Assessment & Application of Technology (PTIK-BPPT) Email: asnugroho@gmail.com URL: http://asnugroho.net
Persiapan Praktikum • OS: Linux Ubuntu • Editor: vi, emacs, gedit • C Compiler: gcc • imagemagick • display • convert • xgraph
Portable Gray Map • Isi sebuah PGM file adalah sbb. • A "magic number" for identifying the file type. A pgm image's magic number is the two characters "P5". • Whitespace (blanks, TABs, CRs, LFs). • A width, formatted as ASCII characters in decimal. • Whitespace. • A height, again in ASCII decimal. • Whitespace. • The maximum gray value (Maxval), again in ASCII decimal. Must be less than 65536, and more than zero. • A single whitespace character (usually a newline). • A raster of Height rows, in order from top to bottom. Each row consistsof Width gray values, in order from left to right. Each gray value is anumber from 0 through Maxval, with 0 being black and Maxval beingwhite. Each gray value is represented in pure binary by either 1 or 2 bytes. If the Maxval is less than 256, it is 1 byte. Otherwise, it is 2 bytes.The most significant byte is first. http://netpbm.sourceforge.net/doc/pgm.html
Contoh: PGM file • Sebuah citra memiliki ukuran 4 kolom x 3 baris • Header (area yang berwarna hijau): terdiri dari 3 baris yang tertulis dalam plain text ASCII. Masing-masing adalah magick number (P5), lebar tinggi, dan nilai maksimum intensitas • Raster (area yang berwarna kuning): berisi data nilai intensitas masing-masing pixel dalam format BINARY. Dimulai dari pixel paling kiri atas menuju ke kanan bawah. “0” adalah hitam, sedangkan “255” adalah putih. P5 4 3 255 0 0 255 0 255 255 0 128 0 0 255 0
Contoh membuat sebuah citra #include <stdio.h> #include <stdlib.h> main() { FILE *fp; int height=3, width=4; unsigned char putih=255, hitam=0, abu=128; fp=fopen(“contoh-1.pgm”,”w”); fprintf(fp,”P5\n%d %d\n255\n“,width,height); fwrite(&hitam,sizeof(unsigned char),1,fp); fwrite(&hitam,sizeof(unsigned char),1,fp); fwrite(&putih,sizeof(unsigned char),1,fp); fwrite(&hitam,sizeof(unsigned char),1,fp); fwrite(&putih,sizeof(unsigned char),1,fp); fwrite(&putih,sizeof(unsigned char),1,fp); fwrite(&hitam,sizeof(unsigned char),1,fp); fwrite(&abu,sizeof(unsigned char),1,fp); fwrite(&hitam,sizeof(unsigned char),1,fp); fwrite(&hitam,sizeof(unsigned char),1,fp); fwrite(&putih,sizeof(unsigned char),1,fp); fwrite(&hitam,sizeof(unsigned char),1,fp); fclose(fp); }
Bagaimana membaca sebuah citra ? #include <stdio.h> #include <stdlib.h> main() { FILE *fp; int i,j, height=3, width=4; char line[100]; unsigned char pixel_value; fp=fopen(“contoh-1.pgm”,”r”); fgets(line,100,fp); fgets(line,100,fp); fgets(line,100,fp); for(j=0;j<height;j++) for(i=0;i<width;i++) { fread(&pixel_value,sizeof(unsigned char),1,fp); printf(“baris ke %d kolom ke %d nilai pixel=%d\n”,j,i,pixel_value); } fclose(fp); }
Latihan-1 Buatlah program untuk menampilkan citra: radius 25 tinggi 75 Lebar 100
Latihan-2 Buatlah program untuk menampilkan nilai tiap pixel pada citra berikut (ukuran citra: 512x512)