0% found this document useful (0 votes)
77 views

Fundamentals in MATLAB

The document discusses fundamentals of digital image processing in MATLAB. It covers basic concepts like reading, displaying and writing images using functions like imread, imshow and imwrite. It also discusses image data types, classes, arithmetic and logical operations on images.

Uploaded by

bilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Fundamentals in MATLAB

The document discusses fundamentals of digital image processing in MATLAB. It covers basic concepts like reading, displaying and writing images using functions like imread, imshow and imwrite. It also discusses image data types, classes, arithmetic and logical operations on images.

Uploaded by

bilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

LAPORAN PRAKTIKUM PENGOLAH CITRA DIGITAL

FUNDAMENTALS IN MATLAB

Dosen Pengampu :
Dr. Yohanes Baptista Gunawan S,ST.,MT.
Dianthika Puteri Andini, SST., M.Sc.

Oleh :
Nama : Moch Bilal Zaenal Asyikin
NIM : 161354019

PROGRAM STUDI D4 TEKNIK ELEKTRONIKA


JURUSAN TEKNIK ELEKTRO
POLITEKNIK NEGERI BANDUNG
2019
I. Purpose:
• To introduce the basic concepts of Digital Image Processing (DIP).
• To implement Image Processing Toolbox (IPT) pada MATLAB for DIP.

II. Tools:
- 1 set Personal Computer (PC) or Laptop
- MATLAB Software

III. Basic Theory

Coordinate Conventions

Fundamentals in Matlab | I-2


Images as Matrices

Fundamentals in Matlab | I-3


MATLAB is a very simple software for coding. All data variable in MATLAB are
thought a matrix and matrix operations are used for analyzing them. MATLAB has the
different toolboxes according to application areas. In this section, MATLAB Image
Processing Toolbox is presented and the use of its basic functions for digital image is
explained.

Read, write, and show image


imread() function is used for reading image. If we run this function with requiring data,
image is converted to a two‐dimensional matrix (gray image is two‐dimensional, but,
color image is three‐dimensional) with rows and columns including gray value in the
each cell.
I = imread(‘path/filename.fileextension');

imread() function only needs an image file. If the result of imread() function is equal
to a variable, a matrix variable (I) is created. File name, extension, and directory path
that contains image must be written between two single quotes. If script and image file
are in the same folder, path is not necessary.
The matrix variable of image is showed using imshow() function. If many images show
with sequence on the different figure windows, we use “figure” function for opening
new window. imwrite() function is used to create an image. This function only requires
a new image file name with extension. If the new image is saved to a specific directory,
the path of directory is necessary.

IV. Preliminary Task


1. Please explain, what is the meaning of digital image processing?
2. Give the examples of fields using the application of digital image processing!
3. Explain what is the meaning of image represented as matrices?

Fundamentals in Matlab | I-4


V. Working Steps 1. Reading Images
Images are read into the MATLAB environment using fungsion “imread”.

Table 1.1 Image formats supported by imread

Here is how to use imread function.

→ give the row and column


dimensions of image →
automatically determine the size of an image

The whos function displays additional information about an array.

2. Displaying Images
Images are displayed on the MATLAB using function imshow.

Display the results and what are inside “displaying window” menu and explain
the those function.

Fundamentals in Matlab | I-5


“imtool” function is Image Tool in Image Processing Toolbox that can be used to
display images interactively, show the detail of information about pixel, and other
functions which are useful for image processing.

Tabel 1.2

Figure 2.2 Image Tool. Overview Window. Main Window, and Pixel Region.

3. Writing Images
Basic syntax in MATLAB for writing images is imwrite.

Fundamentals in Matlab | I-6


The information fields displayed by iminfo can be captured into a structure variable
that can be used for subsequent computations. Using the preceding image as an
example, and assigning the name K to the structure variable, we use the syntax.

4. Classes
Table 1.3 Data Classes

Fundamentals in Matlab | I-7


5. Images Types
Toolbox in MATLAB can support several image types, intensity images, binary
images, indexed images, and RGB images.
• Intensity Images

• Binary Images

6. Array Indexing
To illustrate basic indexing in one or two dimensions for example vector and matrix.

Fundamentals in Matlab | I-8


Vector Indexing Matrix Indexing

>> show rose original image

→ To flip vertically using this statement


→ To crop image
→ Subsampled image
→ Plot function

7 array-generating functions that are used in later chapter.

Fundamentals in Matlab | I-9


7. Matlab Operators
• M-files is created using a text editor and saved by a form name “filename.m”.
• MATLAB operators are grouped into 3 main categories
Arithmetic operators (numeric computations),
Relational operators (compare operands quantitatively), Logical
operators (perform the function AND, OR, NOT).

Table 1.4 Array and matrix arithmetic operator

Fundamentals in Matlab | I-10


Table 1.5 the image arithmetic functions supported by IPT

Fundamentals in Matlab | I-11


VI. Data Results
1. Pada percobaan pertama digunakan image monochrome dengan tipe tif seperti pada
Gambar 1.1

Gambar 1.1 a.tif


1.1 Reading Image
>> f = imread('E:\Mata Kuliah\SMT7 Pengolah Citra Digital\Praktikum\161354019_Moch
Bilal ZA_P1_Fundamentals in Matlab\a.tif');
>> size(f)

ans =

761 1153

>> [M, N]=size(f)

M=

761

Fundamentals in Matlab | I-12


N=

1153

>> whos f
Name Size Bytes Class Attributes

f 761x1153 877433 uint8

1.2 Displaying Image

>> [M, N]=size(f)

M=

761

N=

1153

>> whos f
Name Size Bytes Class Attributes

f 761x1153 877433 uint8

>> imshow(f)

Gambar 1.2 Hasil fungsi imshow()


Pada screen diatas terdapat banyak ilihan menu yang digunakan untuk scaling, saving,
exporting dan edit.

Fundamentals in Matlab | I-13


>> imtool (f)

Gambar 1.2 Hasil fungsi imtool()


Pada Gambar 1.2 diatas menampilkan informasi gambar lebih lengkap detil seperti
pixel gambar.

1.3 Writing Image


>> imwrite(f, 'a_iamwrite', 'tif')

Fundamentals in Matlab | I-14


Gambar 1.3 Hasil fungsi imwrite()
>> imfinfo a_iamwrite

ans =

Filename: [1x113 char]


FileModDate: '15-Sep-2019 09:31:03'
FileSize: 813276
Format: 'tif'
FormatVersion: []
Width: 1153
Height: 761
BitDepth: 8
ColorType: 'grayscale'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: 8
Compression: 'PackBits'
PhotometricInterpretation: 'BlackIsZero'
StripOffsets: [1x70 double]
SamplesPerPixel: 1
RowsPerStrip: 11
StripByteCounts: [1x70 double]
XResolution: 72
YResolution: 72
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1

Fundamentals in Matlab | I-15


FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 255
MinSampleValue: 0
Thresholding: 1
Offset: 812526

1.4 Data Classes


>> whos f
Name Size Bytes Class Attributes

f 761x1153 877433 uint8


Berdasarkan data diatas maka gambar a.tif masuk kedalam class uint8 yaitu unsigned 8-
bit integer dengan range [0,255] 1 byte per element.

2. Pada percobaan kedua digunakan binary image dengan tipe tif seperti pada Gambar 2.1

Gambar 2.1 a.tif


2.1 Reading Image
>> f = imread('E:\Mata Kuliah\SMT7 Pengolah Citra Digital\Praktikum\161354019_Moch
Bilal ZA_P1_Fundamentals in Matlab\b.tif');
>> size f

ans =

1 1

>> size(f)

ans =

269 221

Fundamentals in Matlab | I-16


>> whos f
Name Size Bytes Class Attributes

f 269x221 59449 logical

2.2 Displaying Image

>> imshow(f)

Gambar 2.2 Hasil fungsi imshow()


>> imtool (f)

Gambar 2.2 Hasil fungsi imtool()


Pada Gambar 2.2 diatas menampilkan informasi gambar lebih lengkap detil seperti
pixel gambar.

2.3 Writing Image

Fundamentals in Matlab | I-17


>> imwrite(f, 'b_imwrite.jpg', 'jpg')

Gambar 2.3 Hasil fungsi imwrite()


>> imfinfo b_imwrite.jpg

ans =

Filename: [1x116 char]


FileModDate: '15-Sep-2019 10:17:46'
FileSize: 4055
Format: 'jpg'
FormatVersion: ''
Width: 221
Height: 269
BitDepth: 8
ColorType: 'grayscale'
FormatSignature: ''
NumberOfSamples: 1
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
2.4 Data Classes
>> whos f
Name Size Bytes Class Attributes

f 269x221 59449 logical


Berdasarkan data diatas maka gambar a.tif masuk kedalam class logical yaitu bernilai
antara 0 dan 1 , hal ini dikarenakan gambar yang digunakan adalah jenis binary image.

Fundamentals in Matlab | I-18


3. Pada percobaan ketiga digunakan color image dengan tipe jpg seperti pada Gambar 3.1

Gambar 3.1 a.tif


3.1 Reading Image
>> f = imread('E:\Mata Kuliah\SMT7 Pengolah Citra Digital\Praktikum\161354019_Moch
Bilal ZA_P1_Fundamentals in Matlab\c.jpg');
>> size(f)

ans =

2250 4000 3

>> whos f
Name Size Bytes Class Attributes

f 2250x4000x3 27000000 uint8

3.2 Displaying Image

>> imshow(f)

Fundamentals in Matlab | I-19


Gambar 2.2 Hasil fungsi imshow()
>> imtool (f)

Gambar 3.2 Hasil fungsi imtool()


Pada Gambar 3.2 diatas menampilkan informasi gambar lebih lengkap detil seperti
pixel gambar.

3.3 Writing Image


>> imwrite(f, 'c_imwrite.png', 'png')

Fundamentals in Matlab | I-20


Gambar 2.3 Hasil fungsi imwrite()
>> imfinfo c_imwrite.png

ans =

Filename: [1x116 char]


FileModDate: '15-Sep-2019 10:30:31'
FileSize: 6939356
Format: 'png'
FormatVersion: []
Width: 4000
Height: 2250
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: [1x8 double]
Colormap: []
Histogram: []
InterlaceType: 'none'
Transparency: 'none'
SimpleTransparencyData: []
BackgroundColor: []
RenderingIntent: []
Chromaticities: []
Gamma: []
XResolution: []

Fundamentals in Matlab | I-21


YResolution: []
ResolutionUnit: []
XOffset: []
YOffset: []
OffsetUnit: []
SignificantBits: []
ImageModTime: [1x26 char]
Title: []
Author: []
Description: []
Copyright: []
CreationTime: []
Software: []
Disclaimer: []
Warning: []
Source: []
Comment: []
OtherText: []Data Classes

>> whos f
Name Size Bytes Class Attributes

f 2250x4000x3 27000000 uint8


Berdasarkan data diatas maka gambar a.tif masuk kedalam class uint8.

4. Array Indexing
>> fp = f(end:-1:1, :);
>> imshow(f)

Gambar 4 Fungsi flip


>> fc = f(1:700, 1:500);
>> imshow(fc)

Fundamentals in Matlab | I-22


Gambar 5 Fungsi crop
>> plot(f(300, :))

Gambar 6 Fungsi plot

5. Menu M-Files

Fundamentals in Matlab | I-23


Gambar 7 Windows editor M-File

6. Operator Matlab Function


a=

1 2
3 4

>> b

b=

1 2
3 4

>> plus(a,b)

ans =

2 4
6 8

>> minus(a,b)

Fundamentals in Matlab | I-24


ans =

0 0
0 0

>> times(a,b)

ans =

1 4
9 16

>> mtimes(a,b)

ans =

7 10
15 22

>> rdevide(a,b)
Undefined function 'rdevide' for input arguments of
type 'double'.

>> rdivide(a,b)

ans =

1 1
1 1

>> ldivide(a,b)

ans =

1 1
1 1

VII. Analysis
1. What are differences between reading and displaying images?
Reading adalah fungsi untuk membaca ukuran, byte dan class gambar sedangkan
displaying adalah fungsi menampilkan gambar.
2. What is the meaning of data classes from an image?
Data classes adalah tipe data pada setiap pixel gambar. Meskipun pada koordinat
Matlab digunakan integer, namun bukan berarti setiap pixel gambar bernilai integer.
3. What are differences from image types, intensity, binary, dan RGB?
Intensity menggunakan data classes uint8 atau uint16, sedangkan binary
menggunakan data classes logical yaitu bernilai antara 0 dan 1. Sedangkan RGB
sama dengan intensity namun setiap pixel terdiri atas R, G dan B.
4. How does the conceptualize of process in image processing works?

Fundamentals in Matlab | I-25


Setiap gambar akan dikonversikan kedalam array atau matriks sehingga data nilai
gambar terurai kedalam setiap pixel. Setelah konversi dilakukan barulah dilakukan
proses selanjutnya baik itu filter, scale, crop dan lain-lain.

VIII. Conclusion
Berdasarkan hasil percobaan, dengan bantuan Tools IPT pada Matlab, gambar dapat
dikonversikan kedalam bentuk matrik. Beberapa fungsi pada Matlab telah berhasil
dicoba seperti imread(), imwrite(), imshow(), imfinfo dan beberapa operasi
matematika. Sehingga dengan melakukan percobaan ini kita dapat menganalisa setiap
gambar yang dibaca.

Fundamentals in Matlab | I-26

You might also like