Introduction to Computer
Vision
Lecture 2
Dr. Roger S. Gaborski
RS Gaborski 2
Vector Indexing
 Row vector dimension is 1 x N
 Elements accessed using 1 dimension index,
if vector is v, access first element by v(1), etc.
 Create row vector by: v = [ 1 3 5 7 9]
or v = [ 1,3,5,7,9]
>>v(3)
>> ans = 5
RS Gaborski 3
Transpose Operator
 >> w = v’
w = 1
3
5
7
9
Convert row vector
to column vector
RS Gaborski 4
Access Blocks of Elements
 Colon notation
>> v(1:3)
>> ans = 1 3 5
>> v(4:5)
>> ans 7 9
>> v(3:end) Don’t need to know size of v
>> ans 5 7 9
>> v(end:-2:1)
>> ans 9 5 1
RS Gaborski 5
linspace
 Generate a row vector x of n elements
equally spaced between and including a
and b
X = linspace( a, b, n)
RS Gaborski 6
>> k=linspace(1, 5, 3)
k =
1 3 5
>> k=linspace(1, 5, 4)
RS Gaborski 7
>> k=linspace(1, 5, 3)
k =
1 3 5
>> k=linspace(1, 5, 4)
k =
1.0000 2.3333 3.6667 5.0000
>> k=linspace(-12, 5, 4)
k =
-12.0000 -6.3333 -0.6667 5.0000
RS Gaborski 8
Matrix Indexing
 A = [ 1 2 3; 4 5 6; 7 8 9]
A = 1 2 3
4 5 6
7 8 9
Note semicolon
>>A(3,2)
>> ans = 8
RS Gaborski 9
Matrix Indexing
 >> C3 = A(: , 3)
>> C3 = 3
6
9
>>R1 = A(1 , :)
>>R1 = 1 2 3
RS Gaborski 10
Matrix Indexing
>> A(1:2,2:3)
ans =
2 3
5 6
>> A(end,end-1)
ans =
8
RS Gaborski 11
Matrix Indexing
A( [ a b] , [c d] ) (rows,columns)
Recall [ ] is a vector
Picks out elements in A with coordinates
(row a, column c)
(row a, column d)
(row b, column c)
(row b, column d)
RS Gaborski 12
Matrix Indexing
>> A
A =
1 2 3
4 5 6
7 8 9
>> E = A([1 3], [2 3]) ????
RS Gaborski 13
Matrix Indexing
>> A
A =
1 2 3
4 5 6
7 8 9
>> E = A([1 3], [2 3])
E =
2 3
8 9
RS Gaborski 14
Matrix Storage
 MATLAB stores matrices as a column of
values (columns of original matrix appended
end to end. For matrix A:
1
4
7
2
5
8
3
6
9
Accessing A with a single subscript indexes
Directly into the column, so A(3) accesses the 3rd value
In the column, A(8) accesses the 8th value
>> A(8)
ans =
6
RS Gaborski 15
Matrix Operations
 True Matrix Multiply
1 2
3 4
5 6
7 8
*
=1*5+2*7 = 19
=1*6+2*8 = 22
Etc
19 22
43 50
=
RS Gaborski 16
Matrix Operations
 Point by Point Matrix Multiply
1 2
3 4
5 6
7 8
.*
=1*5 = 5
=2 * 6 = 12
Etc.
5 12
21 32
=
RS Gaborski 17
Another Example
f * g vs f .* g
>> f=[1 2;3 4]; g=[1 2; 2 1];
>> f .* g
ans =
1 4
6 4
>> f=[1 2;3 4]; g=[1 2; 2 1];
>> f * g
ans =
5 4
11 10
Element by Element True Matrix Multiply
RS Gaborski 18
Additional Matrix Operations
RS Gaborski 19
RS Gaborski 20
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 21
Max Operation
A =
1 2
4 5
>> max(A)
ans =
4 5
>> max(A(:))
ans =
5
RS Gaborski 22
Simple Image Operations
f is a 1024 x 1024 intensity image
Flip the image: fp = f( end : -1 : 1, : )
Take a section out of the image: fc = f( 257:768, 257:768 )
Subsample an image: fs = f( 1:2:end, 1:2:end)
Plot the values of a horizontal line through the image:
plot( f( 512, :) )
RS Gaborski 23
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 24
Data Classes
 Eight numeric data classes
 One character class
 One logical class
 All numeric operations in MATLAB are
done using double quantities
 Class uint8 are common in reading data
from devices
RS Gaborski 25
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 26
Converting Between Data
Classes
 B = data_class_name(A) where
data_class_name is from first column of
Table 2.2
 If A is an array of class uint8. Can generate
a double precision array B by command:
B = double(A);
RS Gaborski 27
Converting Between Data Classes
 B = data_class_name(A)
 data_class_name is from first column of
Table 2.2
 If A is an array of class double can
generate a logical array B by command:
B = logical(A);
RS Gaborski 28
Recall MATLAB expects operands in numeric
expressions to be double precision, floating
point numbers
 B = data_class_name(A) where
data_class_name is from first column of
Table 2.2
 If A is an array of class uint8 can generate
a double precision array B by command:
B = double(A);
RS Gaborski 29
Logical Conversion
>> a = [ 0 1; 1 0];
whos a
Name Size Bytes Class
a 2x2 32 double array
Grand total is 4 elements using 32 bytes
>> b = logical (a)
b =
0 1
1 0
>> whos b
Name Size Bytes Class
b 2x2 4 logical array
Grand total is 4 elements using 4 bytes
RS Gaborski 30
Logical Conversion
>> c= [ -17.5 21.5; 13.95 311.05]
c =
-17.5000 21.5000
13.9500 311.0500
>> E = logical (c)
????????????????????
RS Gaborski 31
Logical Conversion
>> c= [ -17.5 21.5; 13.95 311.05]
c =
-17.5000 21.5000
13.9500 311.0500
>> E = logical (c)
Warning: Values other than 0 or 1 converted to logical 1
E =
1 1
1 1
Even though E(1,1) less than zero
RS Gaborski 32
>> whos
Name Size Bytes Class
E 2x2 4 logical array
c 2x2 32 double array
>> G = c>0
G =
0 1
1 1
>> whos
Name Size Bytes Class
E 2x2 4 logical array
G 2x2 4 logical array
c 2x2 32 double array
RS Gaborski 33
 If C is an array of class double in which
all values in the range [0, 255] can be
converted to uint8 with the following
command:
D = uint8(C)
RS Gaborski 34
c =
17.5000 21.5000
13.9500 11.0500
>> D= uint8(c)
D =
18 22
14 11
c =
-17.5000 21.5000
13.9500 311.0500
>> D= uint8(c)
What is D in this case?
RS Gaborski 35
c =
17.5000 21.5000
13.9500 11.0500
>> D= uint8(c)
D =
18 22
14 11
c =
-17.5000 21.5000
13.9500 311.0500
>> D= uint8(c)
D =
0 22
14 255
RS Gaborski 36
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
mat2gray
 Converts arbitrary array of class double to
array of class double scaled to the range
[0,1]
g = mat2gray(A, [Amin, Amax])
range of g: [0,1]
values less than Amin become 0
values greater than Amax become 1
g = mat2gray(A) set Amin and Amax to the
actual minimum and maximum values
RS Gaborski 38
im2double
 Converts input to class double
 If input is of class uint8, uint16 or
logical, convert to class double in the
range [0,1]
 If input is already double there is no
change
RS Gaborski 39
im2double
d =
0 22
14 255
>> whos d
Name Size Bytes Class
d 2x2 4 uint8 array
Grand total is 4 elements using 4 bytes
>> im2double(d)
ans =
0 0.0863
0.0549 1.0000
RS Gaborski 40
im2double
c =
-17.5000 21.5000
13.9500 311.0500
>> whos c
Name Size Bytes Class
c 2x2 32 double array
Grand total is 4 elements using 32 bytes
>> im2double(c)
RS Gaborski 41
im2double
c =
-17.5000 21.5000
13.9500 311.0500
>> whos c
Name Size Bytes Class
c 2x2 32 double array
Grand total is 4 elements using 32 bytes
>> im2double(c)
ans =
-17.5000 21.5000
13.9500 311.0500
RS Gaborski 42
Displaying Images [0, 255]
 Consider we would like to display a gray level
image that has a possible range of values 0-
255
 When we display the image we can arrange
for each gray level value to be displayed as a
different light level on the display
 Black would map to the gray level 0, white
would map to the gray level 255.
 Gray level values between 0 and 255 would
map to shades of gray.
RS Gaborski 43
Displaying Images [0,1]
 The gray level of images can also be
represented by real value numbers
between 0 and 1.
 0 represents pixels that are black, 1
represents pixels that are white.
 Values between 0 and 1 represent gray
level values.
RS Gaborski 44
Range of Gray Level Values
 The maximum range of values is [0,1] or
[0,255] (for 8 bit images)
 It is possible for images to use the maximum
range of gray level values, or some subset
 An image may only contain values between 0 and
.6, or .3 and .9
 In general, gray_min and gray_max, where
gray_min and gray_max may not be 0 and 1
RS Gaborski 45
Displaying Images
 imshow( f, G )
 f is image array
 G is number of intensity levels used to display. If G is
omitted, 256 is the default
 imshow( f, [ low high ] )
 Displays as black values less than low
 Displays as white all values equal or greater than high
 imshow( f, [ ] )
 Sets variable low to lowest value in f
 Sets variable high to highest value in f
RS Gaborski 46
Intensity Image Display Demo
%imshowDemo
%Create intensity image - values between 0 and 1
%f= (rand([30 30])/5);
f= (rand([30 30]));
%Display image
figure, subplot(1,3,1), imshow(f), title('imshow(f)')
subplot(1,3,2),
imshow(f, [.25 .75]), title('imshow(f, [.25 .75]')
subplot(1,3,3),
imshow(f, [ ] ), title('imshow(f, [ ] )')
RS Gaborski 47
Results - 1
RS Gaborski 48
Results - 2
Low contrast image
RS Gaborski 49
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 50
IMPORTANT POINT
 In the previous slides the data values
for each image didn’t change, but how
they were displayed did change.
RS Gaborski 51
Writing Images to Disk-
Syntax
 Syntax:
 imwrite( f, ‘filename’ ) string filename
must contain file format extension
imwrite( f, ‘xray1.tif’)
OR, third input argument can specify format
 imwrite( f, ‘xray1’, ‘tif’)
RS Gaborski 52
Writing Images to Disk-
Parameters
 imwrite(f, ‘filename.jpg’, ‘quality’, q)
 jpg (jpeg) are compressed images
 There is a trade off between file size
(degree of compression) and image quality
 Highly compressed images have small file
sizes, but poorer image quality
 q is an integer between 0 and 100
 Smaller numbers result in more compression
RS Gaborski 53
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 54
Image Types
 Intensity images
 When elements are class uint8 or uint16 they have
integer values in the range [0 255] or [0 65535]
 When elements are class double values are
floating point numbers. Valued are scaled in the
range [0 1] by convention
 Binary images
 RGB images
 Indexed images
RS Gaborski 55
Image Types
 Intensity images
 Binary images
 A logical array of 0s and 1s
 An array of 0s and 1s that are of type uint8 is NOT
a binary image
 If A is a numeric array of 0s and 1s can create a
logical array B using statement:
B = logical(A) (all non zero values converted to
logical 1s, entries with value 0 converted to
logical 0s
 RGB images
 Indexed images
RS Gaborski 56
Image Types
 Intensity images
 Binary images
 RGB images
 RGB color image is an MxNx3 array of color pixels
 Each pixel is a triplet corresponds to the red,
green and blue components at a specific spatial
location
 Can be interpreted as 3 planes of gray scale
images fed into red, green and blue inputs of a
color monitor
 Class double, range of values [0,1]
 Class uint8 or uint16 ranges are [0 255], [0
65535]
 Indexed images
RS Gaborski 57
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 58
Image Types
 Intensity images
 Binary images
 RGB images
 Indexed images
 Two components: data matrix of integers, X, and
a color map matrix, map
 Matrix map is an mx3 array of class double
floating point numbers in the range [0,1]
 m is the number of colors defined for the image
 Each row of m specifies the r,g and b components
of a single color
RS Gaborski 59
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 60
Functions
 M files
 Scripts : series of statements
 Functions : can accept arguments and
can have one or more outputs
function [ outputs ] = name( inputs )
RS Gaborski 61
Functions
 Find the element by element product of two
matrices and find the max and min of the
product
function [p, pmax, pmin]=improd( f, g )
%input images can be uint8, unit16 or double
fd=double(f);
gd=double(g);
p=fd .* gd;
pmax=max(p(:));
pmin = min(p(:));
RS Gaborski 62
Function
>> f=[1 2;3 4]; g=[1 2; 2 1];
>>[p, pmax, pmin] = improd(f, g)
p =
1 4
6 4
pmax = 6
pmin = 1
RS Gaborski 63
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 64
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 65
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 66
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 67
Chapter 2 – Fundamentals
www.prenhall.com/gonzalezwoodseddins
RS Gaborski 68
>> I = imread('boxster5.jpg');
>> figure, imshow(I)
RS Gaborski 69
>> subplot(3,1,1), imshow(I(:,:,1)), title('Red Plane')
>> subplot(3,1,2), imshow(I(:,:,2)), title('Green Plane')
>> subplot(3,1,3), imshow(I(:,:,3)), title('Blue Plane')
Notice bright grass region
Blue highlight
White (contains r,g,b)
RS Gaborski 70
>> Region = I(120:170,30:80,1:3);
>> figure, imshow(Region)
>> size(Region)
ans =
51 51 3
Copy and Paste
RS Gaborski 71
imwrite(Region, 'Region.jpg');
RS Gaborski 72
>> R=rand([100,100]);
>> figure, imshow(R)
RS Gaborski 73
>> r=rand([100,100]);
>> g=rand([100,100]);
>> b=rand([100,100]);
>> image(:,:,1)=r;
>> image(:,:,2)=g;
>> image(:,:,3)=b;
>> figure, imshow(image)
Synthetic Color Image
RS Gaborski 74
>> S = R>.75;
>> figure, imshow(S)

More Related Content

PPTX
Image Processing Using MATLAB
PDF
Image processing using matlab
PDF
Matlab dip
PDF
MATLAB
PPTX
Image processing in MATLAB
PDF
Introduction to Digital Image Processing Using MATLAB
PDF
Matlab intro
PDF
Image processing with matlab
Image Processing Using MATLAB
Image processing using matlab
Matlab dip
MATLAB
Image processing in MATLAB
Introduction to Digital Image Processing Using MATLAB
Matlab intro
Image processing with matlab

Similar to CV2005_3Lec02.ppt (20)

PDF
Image processing basics using matlab
PPTX
Fundamentals of Image Processing & Computer Vision with MATLAB
PPT
Matlab introduction
PDF
Vision systems_Image processing tool box in MATLAB
PPT
lec1_matlab.ppt basic all operations matlab operations
PPTX
MATLAB & Image Processing
PPT
mathematics laboratory lecture 1_matlab.ppt
PDF
An Introduction to MATLAB with Worked Examples
PPTX
Lines and planes in space
PDF
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
PPTX
Basic MATLAB-Presentation.pptx
PDF
Lecture1_computer vision-2023.pdf
PDF
Programming in matlab lesson5
PPT
Introduction of MatLab
PDF
Basics of Image Processing using MATLAB
PPTX
Dip day1&2
PPTX
Images in matlab
PPTX
Introduction to Matlab and application.pptx
PDF
Matlab intro notes
PPT
INTRODUCTION TO MATLAB for PG students.ppt
Image processing basics using matlab
Fundamentals of Image Processing & Computer Vision with MATLAB
Matlab introduction
Vision systems_Image processing tool box in MATLAB
lec1_matlab.ppt basic all operations matlab operations
MATLAB & Image Processing
mathematics laboratory lecture 1_matlab.ppt
An Introduction to MATLAB with Worked Examples
Lines and planes in space
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
Basic MATLAB-Presentation.pptx
Lecture1_computer vision-2023.pdf
Programming in matlab lesson5
Introduction of MatLab
Basics of Image Processing using MATLAB
Dip day1&2
Images in matlab
Introduction to Matlab and application.pptx
Matlab intro notes
INTRODUCTION TO MATLAB for PG students.ppt
Ad

Recently uploaded (20)

PDF
semiconductor packaging in vlsi design fab
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
advance database management system book.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
semiconductor packaging in vlsi design fab
FORM 1 BIOLOGY MIND MAPS and their schemes
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Introduction to pro and eukaryotes and differences.pptx
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Virtual and Augmented Reality in Current Scenario
advance database management system book.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
Environmental Education MCQ BD2EE - Share Source.pdf
Race Reva University – Shaping Future Leaders in Artificial Intelligence
Core Concepts of Personalized Learning and Virtual Learning Environments
Hazard Identification & Risk Assessment .pdf
Share_Module_2_Power_conflict_and_negotiation.pptx
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 2).pdf
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Ad

CV2005_3Lec02.ppt

  • 1. Introduction to Computer Vision Lecture 2 Dr. Roger S. Gaborski
  • 2. RS Gaborski 2 Vector Indexing  Row vector dimension is 1 x N  Elements accessed using 1 dimension index, if vector is v, access first element by v(1), etc.  Create row vector by: v = [ 1 3 5 7 9] or v = [ 1,3,5,7,9] >>v(3) >> ans = 5
  • 3. RS Gaborski 3 Transpose Operator  >> w = v’ w = 1 3 5 7 9 Convert row vector to column vector
  • 4. RS Gaborski 4 Access Blocks of Elements  Colon notation >> v(1:3) >> ans = 1 3 5 >> v(4:5) >> ans 7 9 >> v(3:end) Don’t need to know size of v >> ans 5 7 9 >> v(end:-2:1) >> ans 9 5 1
  • 5. RS Gaborski 5 linspace  Generate a row vector x of n elements equally spaced between and including a and b X = linspace( a, b, n)
  • 6. RS Gaborski 6 >> k=linspace(1, 5, 3) k = 1 3 5 >> k=linspace(1, 5, 4)
  • 7. RS Gaborski 7 >> k=linspace(1, 5, 3) k = 1 3 5 >> k=linspace(1, 5, 4) k = 1.0000 2.3333 3.6667 5.0000 >> k=linspace(-12, 5, 4) k = -12.0000 -6.3333 -0.6667 5.0000
  • 8. RS Gaborski 8 Matrix Indexing  A = [ 1 2 3; 4 5 6; 7 8 9] A = 1 2 3 4 5 6 7 8 9 Note semicolon >>A(3,2) >> ans = 8
  • 9. RS Gaborski 9 Matrix Indexing  >> C3 = A(: , 3) >> C3 = 3 6 9 >>R1 = A(1 , :) >>R1 = 1 2 3
  • 10. RS Gaborski 10 Matrix Indexing >> A(1:2,2:3) ans = 2 3 5 6 >> A(end,end-1) ans = 8
  • 11. RS Gaborski 11 Matrix Indexing A( [ a b] , [c d] ) (rows,columns) Recall [ ] is a vector Picks out elements in A with coordinates (row a, column c) (row a, column d) (row b, column c) (row b, column d)
  • 12. RS Gaborski 12 Matrix Indexing >> A A = 1 2 3 4 5 6 7 8 9 >> E = A([1 3], [2 3]) ????
  • 13. RS Gaborski 13 Matrix Indexing >> A A = 1 2 3 4 5 6 7 8 9 >> E = A([1 3], [2 3]) E = 2 3 8 9
  • 14. RS Gaborski 14 Matrix Storage  MATLAB stores matrices as a column of values (columns of original matrix appended end to end. For matrix A: 1 4 7 2 5 8 3 6 9 Accessing A with a single subscript indexes Directly into the column, so A(3) accesses the 3rd value In the column, A(8) accesses the 8th value >> A(8) ans = 6
  • 15. RS Gaborski 15 Matrix Operations  True Matrix Multiply 1 2 3 4 5 6 7 8 * =1*5+2*7 = 19 =1*6+2*8 = 22 Etc 19 22 43 50 =
  • 16. RS Gaborski 16 Matrix Operations  Point by Point Matrix Multiply 1 2 3 4 5 6 7 8 .* =1*5 = 5 =2 * 6 = 12 Etc. 5 12 21 32 =
  • 17. RS Gaborski 17 Another Example f * g vs f .* g >> f=[1 2;3 4]; g=[1 2; 2 1]; >> f .* g ans = 1 4 6 4 >> f=[1 2;3 4]; g=[1 2; 2 1]; >> f * g ans = 5 4 11 10 Element by Element True Matrix Multiply
  • 18. RS Gaborski 18 Additional Matrix Operations
  • 20. RS Gaborski 20 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 21. RS Gaborski 21 Max Operation A = 1 2 4 5 >> max(A) ans = 4 5 >> max(A(:)) ans = 5
  • 22. RS Gaborski 22 Simple Image Operations f is a 1024 x 1024 intensity image Flip the image: fp = f( end : -1 : 1, : ) Take a section out of the image: fc = f( 257:768, 257:768 ) Subsample an image: fs = f( 1:2:end, 1:2:end) Plot the values of a horizontal line through the image: plot( f( 512, :) )
  • 23. RS Gaborski 23 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 24. RS Gaborski 24 Data Classes  Eight numeric data classes  One character class  One logical class  All numeric operations in MATLAB are done using double quantities  Class uint8 are common in reading data from devices
  • 25. RS Gaborski 25 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 26. RS Gaborski 26 Converting Between Data Classes  B = data_class_name(A) where data_class_name is from first column of Table 2.2  If A is an array of class uint8. Can generate a double precision array B by command: B = double(A);
  • 27. RS Gaborski 27 Converting Between Data Classes  B = data_class_name(A)  data_class_name is from first column of Table 2.2  If A is an array of class double can generate a logical array B by command: B = logical(A);
  • 28. RS Gaborski 28 Recall MATLAB expects operands in numeric expressions to be double precision, floating point numbers  B = data_class_name(A) where data_class_name is from first column of Table 2.2  If A is an array of class uint8 can generate a double precision array B by command: B = double(A);
  • 29. RS Gaborski 29 Logical Conversion >> a = [ 0 1; 1 0]; whos a Name Size Bytes Class a 2x2 32 double array Grand total is 4 elements using 32 bytes >> b = logical (a) b = 0 1 1 0 >> whos b Name Size Bytes Class b 2x2 4 logical array Grand total is 4 elements using 4 bytes
  • 30. RS Gaborski 30 Logical Conversion >> c= [ -17.5 21.5; 13.95 311.05] c = -17.5000 21.5000 13.9500 311.0500 >> E = logical (c) ????????????????????
  • 31. RS Gaborski 31 Logical Conversion >> c= [ -17.5 21.5; 13.95 311.05] c = -17.5000 21.5000 13.9500 311.0500 >> E = logical (c) Warning: Values other than 0 or 1 converted to logical 1 E = 1 1 1 1 Even though E(1,1) less than zero
  • 32. RS Gaborski 32 >> whos Name Size Bytes Class E 2x2 4 logical array c 2x2 32 double array >> G = c>0 G = 0 1 1 1 >> whos Name Size Bytes Class E 2x2 4 logical array G 2x2 4 logical array c 2x2 32 double array
  • 33. RS Gaborski 33  If C is an array of class double in which all values in the range [0, 255] can be converted to uint8 with the following command: D = uint8(C)
  • 34. RS Gaborski 34 c = 17.5000 21.5000 13.9500 11.0500 >> D= uint8(c) D = 18 22 14 11 c = -17.5000 21.5000 13.9500 311.0500 >> D= uint8(c) What is D in this case?
  • 35. RS Gaborski 35 c = 17.5000 21.5000 13.9500 11.0500 >> D= uint8(c) D = 18 22 14 11 c = -17.5000 21.5000 13.9500 311.0500 >> D= uint8(c) D = 0 22 14 255
  • 36. RS Gaborski 36 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 37. mat2gray  Converts arbitrary array of class double to array of class double scaled to the range [0,1] g = mat2gray(A, [Amin, Amax]) range of g: [0,1] values less than Amin become 0 values greater than Amax become 1 g = mat2gray(A) set Amin and Amax to the actual minimum and maximum values
  • 38. RS Gaborski 38 im2double  Converts input to class double  If input is of class uint8, uint16 or logical, convert to class double in the range [0,1]  If input is already double there is no change
  • 39. RS Gaborski 39 im2double d = 0 22 14 255 >> whos d Name Size Bytes Class d 2x2 4 uint8 array Grand total is 4 elements using 4 bytes >> im2double(d) ans = 0 0.0863 0.0549 1.0000
  • 40. RS Gaborski 40 im2double c = -17.5000 21.5000 13.9500 311.0500 >> whos c Name Size Bytes Class c 2x2 32 double array Grand total is 4 elements using 32 bytes >> im2double(c)
  • 41. RS Gaborski 41 im2double c = -17.5000 21.5000 13.9500 311.0500 >> whos c Name Size Bytes Class c 2x2 32 double array Grand total is 4 elements using 32 bytes >> im2double(c) ans = -17.5000 21.5000 13.9500 311.0500
  • 42. RS Gaborski 42 Displaying Images [0, 255]  Consider we would like to display a gray level image that has a possible range of values 0- 255  When we display the image we can arrange for each gray level value to be displayed as a different light level on the display  Black would map to the gray level 0, white would map to the gray level 255.  Gray level values between 0 and 255 would map to shades of gray.
  • 43. RS Gaborski 43 Displaying Images [0,1]  The gray level of images can also be represented by real value numbers between 0 and 1.  0 represents pixels that are black, 1 represents pixels that are white.  Values between 0 and 1 represent gray level values.
  • 44. RS Gaborski 44 Range of Gray Level Values  The maximum range of values is [0,1] or [0,255] (for 8 bit images)  It is possible for images to use the maximum range of gray level values, or some subset  An image may only contain values between 0 and .6, or .3 and .9  In general, gray_min and gray_max, where gray_min and gray_max may not be 0 and 1
  • 45. RS Gaborski 45 Displaying Images  imshow( f, G )  f is image array  G is number of intensity levels used to display. If G is omitted, 256 is the default  imshow( f, [ low high ] )  Displays as black values less than low  Displays as white all values equal or greater than high  imshow( f, [ ] )  Sets variable low to lowest value in f  Sets variable high to highest value in f
  • 46. RS Gaborski 46 Intensity Image Display Demo %imshowDemo %Create intensity image - values between 0 and 1 %f= (rand([30 30])/5); f= (rand([30 30])); %Display image figure, subplot(1,3,1), imshow(f), title('imshow(f)') subplot(1,3,2), imshow(f, [.25 .75]), title('imshow(f, [.25 .75]') subplot(1,3,3), imshow(f, [ ] ), title('imshow(f, [ ] )')
  • 48. RS Gaborski 48 Results - 2 Low contrast image
  • 49. RS Gaborski 49 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 50. RS Gaborski 50 IMPORTANT POINT  In the previous slides the data values for each image didn’t change, but how they were displayed did change.
  • 51. RS Gaborski 51 Writing Images to Disk- Syntax  Syntax:  imwrite( f, ‘filename’ ) string filename must contain file format extension imwrite( f, ‘xray1.tif’) OR, third input argument can specify format  imwrite( f, ‘xray1’, ‘tif’)
  • 52. RS Gaborski 52 Writing Images to Disk- Parameters  imwrite(f, ‘filename.jpg’, ‘quality’, q)  jpg (jpeg) are compressed images  There is a trade off between file size (degree of compression) and image quality  Highly compressed images have small file sizes, but poorer image quality  q is an integer between 0 and 100  Smaller numbers result in more compression
  • 53. RS Gaborski 53 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 54. RS Gaborski 54 Image Types  Intensity images  When elements are class uint8 or uint16 they have integer values in the range [0 255] or [0 65535]  When elements are class double values are floating point numbers. Valued are scaled in the range [0 1] by convention  Binary images  RGB images  Indexed images
  • 55. RS Gaborski 55 Image Types  Intensity images  Binary images  A logical array of 0s and 1s  An array of 0s and 1s that are of type uint8 is NOT a binary image  If A is a numeric array of 0s and 1s can create a logical array B using statement: B = logical(A) (all non zero values converted to logical 1s, entries with value 0 converted to logical 0s  RGB images  Indexed images
  • 56. RS Gaborski 56 Image Types  Intensity images  Binary images  RGB images  RGB color image is an MxNx3 array of color pixels  Each pixel is a triplet corresponds to the red, green and blue components at a specific spatial location  Can be interpreted as 3 planes of gray scale images fed into red, green and blue inputs of a color monitor  Class double, range of values [0,1]  Class uint8 or uint16 ranges are [0 255], [0 65535]  Indexed images
  • 57. RS Gaborski 57 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 58. RS Gaborski 58 Image Types  Intensity images  Binary images  RGB images  Indexed images  Two components: data matrix of integers, X, and a color map matrix, map  Matrix map is an mx3 array of class double floating point numbers in the range [0,1]  m is the number of colors defined for the image  Each row of m specifies the r,g and b components of a single color
  • 59. RS Gaborski 59 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 60. RS Gaborski 60 Functions  M files  Scripts : series of statements  Functions : can accept arguments and can have one or more outputs function [ outputs ] = name( inputs )
  • 61. RS Gaborski 61 Functions  Find the element by element product of two matrices and find the max and min of the product function [p, pmax, pmin]=improd( f, g ) %input images can be uint8, unit16 or double fd=double(f); gd=double(g); p=fd .* gd; pmax=max(p(:)); pmin = min(p(:));
  • 62. RS Gaborski 62 Function >> f=[1 2;3 4]; g=[1 2; 2 1]; >>[p, pmax, pmin] = improd(f, g) p = 1 4 6 4 pmax = 6 pmin = 1
  • 63. RS Gaborski 63 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 64. RS Gaborski 64 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 65. RS Gaborski 65 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 66. RS Gaborski 66 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 67. RS Gaborski 67 Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins
  • 68. RS Gaborski 68 >> I = imread('boxster5.jpg'); >> figure, imshow(I)
  • 69. RS Gaborski 69 >> subplot(3,1,1), imshow(I(:,:,1)), title('Red Plane') >> subplot(3,1,2), imshow(I(:,:,2)), title('Green Plane') >> subplot(3,1,3), imshow(I(:,:,3)), title('Blue Plane') Notice bright grass region Blue highlight White (contains r,g,b)
  • 70. RS Gaborski 70 >> Region = I(120:170,30:80,1:3); >> figure, imshow(Region) >> size(Region) ans = 51 51 3 Copy and Paste
  • 72. RS Gaborski 72 >> R=rand([100,100]); >> figure, imshow(R)
  • 73. RS Gaborski 73 >> r=rand([100,100]); >> g=rand([100,100]); >> b=rand([100,100]); >> image(:,:,1)=r; >> image(:,:,2)=g; >> image(:,:,3)=b; >> figure, imshow(image) Synthetic Color Image
  • 74. RS Gaborski 74 >> S = R>.75; >> figure, imshow(S)