KEMBAR78
Introduction To Dr. Ghulam Gilanie Janjua: o o o o o o | PDF | Computing | Computer Data
0% found this document useful (0 votes)
531 views47 pages

Introduction To Dr. Ghulam Gilanie Janjua: o o o o o o

The document provides an introduction to Dr. Ghulam Gilanie Janjua who holds several academic and professional positions including Professor at the Islamia University of Bahawalpur, Managing Director of Innovative Research and Development Group, and Principal Scientist at RoboLogix Bahawalpur. It lists his educational background and previous work experience in computer programming for the Government of Pakistan and Punjab. The document appears to provide an introduction to Dr. Janjua's qualifications and expertise.

Uploaded by

Maria Mansab
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)
531 views47 pages

Introduction To Dr. Ghulam Gilanie Janjua: o o o o o o

The document provides an introduction to Dr. Ghulam Gilanie Janjua who holds several academic and professional positions including Professor at the Islamia University of Bahawalpur, Managing Director of Innovative Research and Development Group, and Principal Scientist at RoboLogix Bahawalpur. It lists his educational background and previous work experience in computer programming for the Government of Pakistan and Punjab. The document appears to provide an introduction to Dr. Janjua's qualifications and expertise.

Uploaded by

Maria Mansab
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/ 47

Introduction to Dr.

Ghulam Gilanie Janjua

o Professor (Assistant)
The Islamia University of Bahawalpur
o Managing Director & CEO
Innovative Research and Development Group, Bahawalpur
o Principal Scientist
RoboLogix Bahawalpur
o Ex-Computer Programmer, Government of Pakistan
National Highways and Motorway Police
o Ex-Assistant Professor, Government of Punjab
Department of Higher Education
o Ex-Computer Programmer, Government of Punjab
Department of Health
Fundamentals of Computer Imaging
& Matlab (Matrix Laboratory)

Gonzalez R. C., Woods R. E., Eddins S. L., Digital


Image Processing Using Matlab, Pearson Education,
2nd edition, 2009. (Ch. 1)
Digital Image
An image may be defined as a two-dimensional function,
f(x, y), where x and y are spatial (plane) coordinates, and
the amplitude of f at any pair of coordinates (x, y) is called
the intensity or gray level of the image at that point.
Image Formats
1. BMP (Microsoft Windows Bitmap)
2. GIF (Graphics Interchange Files)
3. HDF (Hierarchical Data Format)
4. JPEG (Joint Photographic Experts Group)
5. PCX (Paintbrush)
6. PNG (Portable Network Graphics)
7. TIFF (Tagged Image File Format)
8. XWD (X Window Dump)

➢Lossless compression ❖Raster format


➢Lossy compression ❖Vector format
For further info.: http://en.wikipedia.org/wiki/Image_formats
Through command: >doc imwrite
Displaying Images
File -> Set path: Select path
where images are available

>> f = imread('rose.tif');
>> imshow(f)
>> g = imread('xray.tif');
>> figure, imshow(g)
>> imshow(f), figure, imshow(g)
>> doc imshow
>> whos
>> save habib
>> clc
>> clear all
>> load habib

Warning: When copy any code from these slides to Matlab editor, use apostrophe
“ ' “ instead of “ ‘ “ or “ ’ “.
Displaying Images
>> g = imread('xray.tif');
>> imshow(g)
>> imshow(g, [10 100])
>> imshow(g, [ ])
Displaying Images Info.

>> f = imread('rose.tif');
>> imshow(f)

>> size(f)
ans =
1024 1024

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

>> whos f
Name Size Bytes Class Attributes

f 1024x1024 1048576 uint8


Displaying Images Info.
>> imfinfo bubbles.jpg
File size of original image?
ans = Compression ratio?
DPI?
Filename: 'bubble.jpg'
FileModDate: '14-Jan-2008 17:08:08'
Physical image size?
FileSize: 7904
Format: 'jpg'
FormatVersion: ‘' >> K = imfinfo('bubbles.jpg');
Width: 720 >> K.FileSize
Height: 688
BitDepth: 8 ans =
ColorType: 'grayscale'
FormatSignature: ‘'
NumberOfSamples: 1 7904
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
Displaying Images Info.
>> imfinfo bubbles.jpg

ans =

Filename: 'bubbles.jpg'
FileModDate: '14-Jan-2008 17:08:08'
FileSize: 7904
Format: 'jpg' File size of original image
FormatVersion: ‘'
Width: 720
= (Width x Height x BitDepth)/8
Height: 688 = 495360
BitDepth: 8 File size = 7904
ColorType: 'grayscale'
FormatSignature: ‘'
Compression ratio
NumberOfSamples: 1 = 495360/7904 = 62.67
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
Displaying Images Info.
>> imfinfo bubbles.jpg

ans =

Filename: 'bubbles.jpg'
FileModDate: '14-Jan-2008 17:08:08'
FileSize: 7904
Format: 'jpg' Display resolution: 1366 x 768
FormatVersion: ‘'
Width: 720 Display physical size in inches: 16 x 9
Height: 688 DPI = 1366/16  768/9  85.4
BitDepth: 8
ColorType: 'grayscale' Image width = 720/ 85.4 = 8.4 inches
FormatSignature: ‘'
NumberOfSamples: 1 Image height = 688/85.4 = 8 inches
CodingMethod: 'Huffman'
CodingProcess: 'Sequential' Try for
Comment: {}
>> imageinfo('rose.tif')
Exercise

Given digital picture moon.tif has following attributes:


File size: 252238, Width: 466, Height: 540, Bit Depth: 8
a. Find the compression ratio.
b. Find the physical size of moon.tif
i. if it is displayed on a monitor of size 16x9 on
resolution 1366x768.
ii. if it is printed on a laser printer of dpi 600.
Writing Images

b = imread('bubbles.tif');

>> imwrite(b,'bubbles.png')

>> imwrite(b,'bubbles.jpg')

>> imwrite(b,'bubbles', 'jpg')

>> imwrite(b,'bubbles.jpg','quality',50)
Writing Images: * -> tif

'compression': 'none'
'packbits'
'ccitt'
'resolution': dpi

>> ckt = imread('cktboard.jpg');


>> imwrite(ckt,'cktboard-1.tif','compression','none','resolution',[300 300])
>> imwrite(ckt,'cktboard-2.tif','compression','none','resolution',300)
>> imwrite(ckt,'cktboard-3.tif','compression','packbits')
>> imshow(ckt)
>> print
Data Classes
Converting Between
Data Classes

Syntax: B = data_class_name(A)

Example: Suppose

A is an array of class uint8


C is an array of class double

B = double(A)
D = uint8(C)
Image Types

1. Intensity images
2. Binary images
3. RGB images
4. Indexed images
Converting Between
Image Classes & Types
Converting Between
Image Classes & Types
Example: Consider the following 2 X 2 image f of class double:

>> f = [-0.5 0.5; 0.75 1.5] >> h = uint8(f)


f= h=
-0.5 0.5 0 1
0.75 1.5 1 2

>> g = im2uint8(f) >> i = im2uint8(uint8([25 50; 128 2000]))


g= i=
0 128 25 50
191 255 128 255
Converting Between
Image Classes & Types
Example: Conversion of arbitrary array of class double to an array
of class double scaled to the range [0,1]:

g = mat2gray(A, [Amin, Amax])

>> g = mat2gray(A); i.e., Amin = min(A(:)) & Amax = max(A(:))

Example: Formula: (x0, x1) => (y0, y1)


y = y0 + {(y1-y0)/(x1-x0)}(x-x0)
>> f = [1 2; 3 4]; e.g., (x0, x1) = (1, 4)
(y0, y1) = (0, 1)
>> g = mat2gray(f) y = 0 + {(1-0)/(4-1)}(x-1)
g= = (x-1)/3
0 0.3333 for x = 1, y = 0
0.6667 1.0000 x = 2, y = 1/3, and so on…
Converting Between
Image Classes & Types
Conversion between binary and intensity image types:
Syntax:
g = im2bw(f, T) where T has a range [0, 1]
g = im2bw(f, T) T = 0.5 by default

Reading: Example 2.4


Array Indexing
Example:
>> w = v.'
>> v = [1 3 5 7 9] w=
v= 1
1 3 5 7 9 3
>> v(2) 5
ans = 7
3 9
>> v(2:4)
ans =
3 5 7

Guess the output of: v(3:end) v(1:2:end) v(end:-2:1) v([1 4 5])


Matrix Indexing
Example:

>> A = [1 2 3; 4 5 6; 7 8 9] >> A(2:end, end:-2:1)


A= ans =
1 2 3 6 4
4 5 6
7 8 9
9 7

>> A(2, 3) >> C3 = A(:, 3)


ans = C3 =
6 3
6
>> R2 = A(2, :) 9
R2 =
4 5 6
Guess the output of: A(1:2, 1:3) A(end, end-2) A(:, 3) = 0
Matrix Indexing
Matrix Indexing
a.
1024 X 1024 intensity image f of
class uint8
b.
>> fp = f(end:-1:1, :);
c.
>> fc = f(257:768, 257:768);
d.
>> fs = f(1:2:end, 1:2:end);
e.
>> plot(f(512, :))
>> plot(f(size(f, 1)/2, :))
Standard Arrays
>> A = 5*ones(3, 3)
A=
5 5 5
5 5 5
5 5 5
>> magic(3)
ans =
8 1 6
3 5 7
4 9 2
>> B = rand(2, 4)
B=
0.2311 0.4860 0.7621 0.0185
0.6068 0.8913 0.4565 0.8214
M-Function Programming
Components
1. The function definition line: function [outputs] = name(inputs)
2. The H1 line
3. Help text
4. The function body
5. Comments
M-Function Programming
function [p, pmax, pmin, pn] = improd(f, g)
%IMPROD Computes the product of two images.
% [P, PMAX, PMIN, PN] = IMPROD(F, G)
>> f = [1 2; 3 4];
fd = double(f); >> g = [1 2; 2 1];
gd = double(g); >> [p, pmax, pmin, pn] = improd(f, g)
p = fd.*gd; p=
pmax = max(p(:)); 1 4
pmin = min(p(:)); 6 4
pn = mat2gray(p); % Scaled to [0, 1] pmax =
6
% The End pmin =
1
>> help improd pn =
IMPROD Computes the product of two images. 0 0.6000
[P, PMAX, PMIN, PN] = IMPROD(F, G) 1.0000 0.6000
Operators
Example: >> A = [1 2 3; 4 5 6; 7 8 9]
A=
1 2 3
f= 4 5 6
1 2 7 8 9
3 4
>> A(2:end, end:-2:1)
ans =
>> v = f(:) 6 4
9 7
v= >> C3 = A(:, 3)
1 C3 =
3 3
6
2 9
4
Arithmetic Operations

Example:
>> imshow(imcomplement(f))
Relational Operators

Example:

>> A = [1 2; 3 4]
A=
1 2
3 4

>> B = [0 2; 3 5]
B=
0 2
3 5

>> A>=B
ans =
1 1
1 0
Logical Operators and Functions
Functions Returning 1 or 0
Variables & Constants
Flow Control Statements
Code Optimization
1. Vectorizing loops
2. Preallocating arrays
Example 1: Suppose we want to generate a 1-D
function:

f(x) = A sin(x/2) for x = 0, 1, 2,…, M-1


>> A=2; M=4;
Method 1: for x = 1:M
>> x=0:M-1
f(x) = A*sin((x-1)/(2*pi)); x=
end 0 1 2 3

Method 2: x = 0:M-1; >> f = A*sin( x / (2*pi) )


f = A*sin(x/(2*pi)); f=
0 0.3170 0.6259 0.9191
Code Optimization
Example 2: Suppose we want to form a 2D Output is:
function
f(x, y) = x2 + y2, for x = 0, 1, 2 and y = 0, 1. f=
0 1
1 2
Method 1: for x = 1:3 4 5
C=
for y = 1:2 0 1
f(x, y) = (x-1)^2 + (y-1)^2; 0 1
end 0 1
end
R=
Method 2: r = [0 1 2]; 0 0
c = [0 1]; 1 1 Output is:
[C R] = meshgrid(c, r) 2 2
f=
f = R.^2 + C.^2
0 1
1 2
4 5
Code Optimization: Example 2.13
function [rt, f, g] = twodsin(A, u0, v0, M, N)
%TWODSIN Compares for loops vs. vectorization.
% The comparison is based on implementing the function
% f(x, y) = A sin(u0x + v0y) for x = 0, 1, 2,..., M-1 and y = 0, 1, 2,...,N-1
% The inputs to the function are M & N and the constants in the function.

% First implement using for loops.

tic % Start timing


for r = 1:M
u0x = u0*(r-1);
for c = 1:N
v0y = v0*(c-1);
f(r,c) = A*sin(u0x + v0y);
end
end
t1 = toc; % End timing.
Code Optimization: Example 2.13
>> R = 0 : 4
% Now implementing using vectorization. R=
% Call the image g. 0 1 2 3 4

>> C = 0 : 3
tic % Start timing C=
r = 0:M-1; 0 1 2 3
c = 0:N-1;
[C, R] = meshgrid(c, r); >> [C,R] = meshgrid(C,R)
C=
g = A*sin(u0*R + v0*C); 0 1 2 3
t2 = toc; % End timing. 0 1 2 3
0 1 2 3
% Compute the ratio of the two times. 0 1 2 3
0 1 2 3
R=
rt = t1/(t2+eps); % Use eps in case t2 is close to 0. 0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
Code Optimization: Example 2.13

>> [rt, f, g] = twodsin(1, 1/(4*pi), 1/(4*pi), 512, 512);


rt =
5.8061 function [rt, f, g] = twodsin(A, u0, v0, M, N)
>> imshow(f)
>> imshow(g)
Code Optimization
- Preallocating Arrays
e.g., f = zeros(1024);
g = zeros(1024);
Interactive I/O
>> t = input('Enter your data: ', 's')
Enter your data: 2 3 4
t=
>> t = input('Enter your data: ', 's')
234
Enter your data: 12.6, x2y, z
>> class(t)
t=
ans =
12.6, x2y, z
char
>> [a, b, c] = strread(t, '%f%q%q', 'delimiter', ',')
n = str2num(t)
a=
>> class(n)
12.6000
ans =
b=
double
'x2y'
>> n(2)
c=
ans =
'z'
3
>> doc strread
>> doc input
String Comparison
Function strcmp is used to compare strings.
Syntax: TF = strcmp('str1', 'str2')

Practice: Write an M-function g = imnorm(f, param)


that accepts an image, f, and a parameter param (either in
lower or upper case) that can have one of two forms:

‘norm1’: To be scaled to the range [0, 1] with output of


class double
‘norm255’: To be scaled to the range [0, 255] with output
of class uint8
M-Function Programming

Exercise:

Write a program iminfo.m that accepts tif, jpg, and png


files and display
1. Compression Ratio
2. Physical size of image
Test images of different formats and check results
Course Requirements
Class attendance is highly recommended
• Homework
– Problem sets
– Programming assignments
• Readings
– Lecture notes and textbooks
– Tutorials
• Grading
– 20% class participation (will be helpful if you make me know you)
– 80% exams (Mid-30% & Final-50%)
It will be easy to everyone to pass the exam, but Absolutely NO cheating

You might also like