SlideShare a Scribd company logo
Introduction to MATLAB and
image processing
Amin Allalou
amin@cb.uu.se
Centre for Image Analysis
Uppsala University
Computer Assisted Image Analysis
April 4 2008
MATLAB and images
• The help in MATLAB is very good, use it!
• An image in MATLAB is treated as a matrix
• Every pixel is a matrix element
• All the operators in MATLAB defined on
matrices can be used on images: +, -, *, /, ^, sqrt, sin, cos etc.
Images in MATLAB
• MATLAB can import/export
several image formats
– BMP (Microsoft Windows Bitmap)
– GIF (Graphics Interchange Files)
– HDF (Hierarchical Data Format)
– JPEG (Joint Photographic Experts
Group)
– PCX (Paintbrush)
– PNG (Portable Network Graphics)
– TIFF (Tagged Image File Format)
– XWD (X Window Dump)
– MATLAB can also load raw-data or
other types of image data
• Data types in MATLAB
– Double (64-bit double-precision
floating point)
– Single (32-bit single-precision
floating point)
– Int32 (32-bit signed integer)
– Int16 (16-bit signed integer)
– Int8 (8-bit signed integer)
– Uint32 (32-bit unsigned integer)
– Uint16 (16-bit unsigned integer)
– Uint8 (8-bit unsigned integer)
Images in MATLAB
• Binary images : {0,1}
• Intensity images : [0,1] or uint8, double etc.
• RGB images : m-by-n-by-3
• Indexed images : m-by-3 color map
• Multidimensional images m-by-n-by-p (p is the number of layers)
Image import and export
• Read and write images in Matlab
>> I=imread('cells.jpg');
>> imshow(I)
>> size(I)
ans = 479 600 3 (RGB image)
>> Igrey=rgb2gray(I);
>> imshow(Igrey)
>> imwrite(lgrey, 'cell_gray.tif', 'tiff')
Alternatives to imshow
>>imagesc(I)
>>imtool(I)
>>image(I)
Images and Matrices
• How to build a matrix (or image)?
>> A = [ 1 2 3; 4 5 6; 7 8 9 ];
A = 1 2 3
4 5 6
7 8 9
>> B = zeros(3,3)
B = 0 0 0
0 0 0
0 0 0
>> C = ones(3,3)
C = 1 1 1
1 1 1
1 1 1
>>imshow(A) (imshow(A,[]) to get automatic pixel range)
Images and Matrices
• Accesing image elements (row, column)
>> A(2,1)
ans = 4
• : can be used to extract a whole column or
row
>> A(:,2)
ans =
2
5
8
• or a part of a column or row
>> A(1:2,2)
ans =
2
5
X
Y
A =
12 3
45 6
7 8 9
Image Arithmetic
• Arithmetic operations such as addition, subtraction, multiplication and
division can be applied to images in MATLAB
– +, -, *, / performs matrix operations
>> A+A
ans = 2 4 6
8 10 12
14 16 18
>> A*A
ans = 30 36 42
66 81 96
102 126 150
• To perform an elementwise operation use . (.*, ./, .*, .^ etc)
>> A.*A
ans = 1 4 9
16 25 36
49 64 81
A =
12 3
45 6
7 8 9
Logical Conditions
• equal (==) , less than and greater than (< and >), not equal (~=) and not (~)
• find(‘condition’) - Returns indexes of A’s elements that satisfies the
condition.
>> [row col]=find(A==7)
row = 3
col = 1
>> [row col]=find(A>7)
row = 3
3
col = 2
3
>> Indx=find(A<5)
Indx = 1
2
4
7
A =
12 3
45 6
7 8 9
Flow Control
• Flow control in MATLAB
- if, else and elseif statements
(row=1,2,3 col=1,2,3)
if row==col
A(row, col)=1;
elseif abs(row-col)==1
A(row, col)=2;
else
A(row, col)=0;
end
A =
1 2 0
2 1 2
0 2 1
Flow Control
• Flow control in MATLAB
- for loops
for row=1:3
for col=1:3
if row==col
A(row, col)=1;
elseif abs(row-col)==1
A(row, col)=2;
else
A(row, col)=0;
end
end
end
A =
1 2 0
2 1 2
0 2 1
Flow Control
• while, expression, statements, end
Indx=1;
while A(Indx)<6
A(Indx)=0;
Indx=Indx+1;
end
A =
12 3
45 6
7 8 9
A =
0 2 3
0 5 6
7 8 9
Working with M-Files
• M-files can be scripts that simply execute a series of MATLAB statements,
or they can be functions that also accept input arguments and produce
output.
• MATLAB functions:
– Are useful for extending the MATLAB language for your application.
– Can accept input arguments and return output arguments.
– Store variables in a workspace internal to the function.
Working with M-Files
• Create a new empty m-file
function B=test(I)
[row col]=size(I)
for r=1:row
for c=1:col
if r==c
A(r, c)=1;
elseif abs(r-c)==1
A(r, c)=2;
else
A(r, c)=0;
end
end
end
B=A;

More Related Content

What's hot

MATRIX HASHING WITH TWO LEVEL OF COLLISION RESOLUTION
MATRIX HASHING WITH TWO LEVEL OF COLLISION RESOLUTIONMATRIX HASHING WITH TWO LEVEL OF COLLISION RESOLUTION
MATRIX HASHING WITH TWO LEVEL OF COLLISION RESOLUTION
Nvk Chaitanya
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
Ameen San
 
Aaa ped-Data-8- manipulation: Plotting and Visualization
Aaa ped-Data-8- manipulation: Plotting and VisualizationAaa ped-Data-8- manipulation: Plotting and Visualization
Aaa ped-Data-8- manipulation: Plotting and Visualization
AminaRepo
 
Queue
QueueQueue
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
Ismail Seyrik
 
Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
SHAKOOR AB
 
Matlab Nn Intro
Matlab Nn IntroMatlab Nn Intro
Matlab Nn Intro
Imthias Ahamed
 
Matlab on basic mathematics
Matlab on basic mathematicsMatlab on basic mathematics
Matlab on basic mathematics
monauweralam1
 
Dip 5 mathematical preliminaries
Dip 5 mathematical preliminariesDip 5 mathematical preliminaries
Dip 5 mathematical preliminaries
Manas Mantri
 
Aaa ped-4- Data manipulation: Numpy
Aaa ped-4- Data manipulation: Numpy Aaa ped-4- Data manipulation: Numpy
Aaa ped-4- Data manipulation: Numpy
AminaRepo
 
Tomato Classification using Computer Vision
Tomato Classification using Computer VisionTomato Classification using Computer Vision
Tomato Classification using Computer Vision
Raman Pandey
 
Matlab
MatlabMatlab
Chapter 7.3
Chapter 7.3Chapter 7.3
Chapter 7.3
sotlsoc
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
Devashish Kumar
 
2-D array
2-D array2-D array
DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1
Malikireddy Bramhananda Reddy
 
Dip digital image 3
Dip digital image 3Dip digital image 3
Dip digital image 3
Shajun Nisha
 
Arrays in Data
Arrays in DataArrays in Data
Arrays in Data
Afzal Badshah
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
SHAKOOR AB
 
Algorithms 101 for Data Scientists
Algorithms 101 for Data ScientistsAlgorithms 101 for Data Scientists
Algorithms 101 for Data Scientists
Christopher Conlan
 

What's hot (20)

MATRIX HASHING WITH TWO LEVEL OF COLLISION RESOLUTION
MATRIX HASHING WITH TWO LEVEL OF COLLISION RESOLUTIONMATRIX HASHING WITH TWO LEVEL OF COLLISION RESOLUTION
MATRIX HASHING WITH TWO LEVEL OF COLLISION RESOLUTION
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
Aaa ped-Data-8- manipulation: Plotting and Visualization
Aaa ped-Data-8- manipulation: Plotting and VisualizationAaa ped-Data-8- manipulation: Plotting and Visualization
Aaa ped-Data-8- manipulation: Plotting and Visualization
 
Queue
QueueQueue
Queue
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 
Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
 
Matlab Nn Intro
Matlab Nn IntroMatlab Nn Intro
Matlab Nn Intro
 
Matlab on basic mathematics
Matlab on basic mathematicsMatlab on basic mathematics
Matlab on basic mathematics
 
Dip 5 mathematical preliminaries
Dip 5 mathematical preliminariesDip 5 mathematical preliminaries
Dip 5 mathematical preliminaries
 
Aaa ped-4- Data manipulation: Numpy
Aaa ped-4- Data manipulation: Numpy Aaa ped-4- Data manipulation: Numpy
Aaa ped-4- Data manipulation: Numpy
 
Tomato Classification using Computer Vision
Tomato Classification using Computer VisionTomato Classification using Computer Vision
Tomato Classification using Computer Vision
 
Matlab
MatlabMatlab
Matlab
 
Chapter 7.3
Chapter 7.3Chapter 7.3
Chapter 7.3
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
 
2-D array
2-D array2-D array
2-D array
 
DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1
 
Dip digital image 3
Dip digital image 3Dip digital image 3
Dip digital image 3
 
Arrays in Data
Arrays in DataArrays in Data
Arrays in Data
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
Algorithms 101 for Data Scientists
Algorithms 101 for Data ScientistsAlgorithms 101 for Data Scientists
Algorithms 101 for Data Scientists
 

Similar to Intro matlab

Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islam
Islam Alabbasy
 
Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdf
ssuserff72e4
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
Techbuddy Consulting Pvt. Ltd.
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
Ali Ghanbarzadeh
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
aboma2hawi
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
Arshit Rai
 
Basics of Image Processing using MATLAB
Basics of Image Processing using MATLABBasics of Image Processing using MATLAB
Basics of Image Processing using MATLAB
vkn13
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
Arshit Rai
 
4.ArraysInC.pdf
4.ArraysInC.pdf4.ArraysInC.pdf
4.ArraysInC.pdf
FarHanWasif1
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
Big_Data_Ukraine
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Dun Automation Academy
 
4413-lecture-09 Introduction Matlab lecture .ppt
4413-lecture-09 Introduction Matlab lecture .ppt4413-lecture-09 Introduction Matlab lecture .ppt
4413-lecture-09 Introduction Matlab lecture .ppt
aaaaboud1
 
Matlab intro
Matlab introMatlab intro
Matlab intro
Chaitanya Banoth
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
TUOS-Sam
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
TUOS-Sam
 
Image Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingImage Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image Processing
Ashok Kumar
 
Matlab intro
Matlab introMatlab intro
Matlab intro
fvijayami
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
محمدعبد الحى
 
Presentation: Plotting Systems in R
Presentation: Plotting Systems in RPresentation: Plotting Systems in R
Presentation: Plotting Systems in R
Ilya Zhbannikov
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
chestialtaff
 

Similar to Intro matlab (20)

Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islam
 
Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdf
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 
Basics of Image Processing using MATLAB
Basics of Image Processing using MATLABBasics of Image Processing using MATLAB
Basics of Image Processing using MATLAB
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 
4.ArraysInC.pdf
4.ArraysInC.pdf4.ArraysInC.pdf
4.ArraysInC.pdf
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
4413-lecture-09 Introduction Matlab lecture .ppt
4413-lecture-09 Introduction Matlab lecture .ppt4413-lecture-09 Introduction Matlab lecture .ppt
4413-lecture-09 Introduction Matlab lecture .ppt
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
 
Image Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image ProcessingImage Processing using Matlab . Useful for beginners to learn Image Processing
Image Processing using Matlab . Useful for beginners to learn Image Processing
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Presentation: Plotting Systems in R
Presentation: Plotting Systems in RPresentation: Plotting Systems in R
Presentation: Plotting Systems in R
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 

Recently uploaded

GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 

Recently uploaded (20)

GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 

Intro matlab

  • 1. Introduction to MATLAB and image processing Amin Allalou amin@cb.uu.se Centre for Image Analysis Uppsala University Computer Assisted Image Analysis April 4 2008
  • 2. MATLAB and images • The help in MATLAB is very good, use it! • An image in MATLAB is treated as a matrix • Every pixel is a matrix element • All the operators in MATLAB defined on matrices can be used on images: +, -, *, /, ^, sqrt, sin, cos etc.
  • 3. Images in MATLAB • MATLAB can import/export several image formats – BMP (Microsoft Windows Bitmap) – GIF (Graphics Interchange Files) – HDF (Hierarchical Data Format) – JPEG (Joint Photographic Experts Group) – PCX (Paintbrush) – PNG (Portable Network Graphics) – TIFF (Tagged Image File Format) – XWD (X Window Dump) – MATLAB can also load raw-data or other types of image data • Data types in MATLAB – Double (64-bit double-precision floating point) – Single (32-bit single-precision floating point) – Int32 (32-bit signed integer) – Int16 (16-bit signed integer) – Int8 (8-bit signed integer) – Uint32 (32-bit unsigned integer) – Uint16 (16-bit unsigned integer) – Uint8 (8-bit unsigned integer)
  • 4. Images in MATLAB • Binary images : {0,1} • Intensity images : [0,1] or uint8, double etc. • RGB images : m-by-n-by-3 • Indexed images : m-by-3 color map • Multidimensional images m-by-n-by-p (p is the number of layers)
  • 5. Image import and export • Read and write images in Matlab >> I=imread('cells.jpg'); >> imshow(I) >> size(I) ans = 479 600 3 (RGB image) >> Igrey=rgb2gray(I); >> imshow(Igrey) >> imwrite(lgrey, 'cell_gray.tif', 'tiff') Alternatives to imshow >>imagesc(I) >>imtool(I) >>image(I)
  • 6. Images and Matrices • How to build a matrix (or image)? >> A = [ 1 2 3; 4 5 6; 7 8 9 ]; A = 1 2 3 4 5 6 7 8 9 >> B = zeros(3,3) B = 0 0 0 0 0 0 0 0 0 >> C = ones(3,3) C = 1 1 1 1 1 1 1 1 1 >>imshow(A) (imshow(A,[]) to get automatic pixel range)
  • 7. Images and Matrices • Accesing image elements (row, column) >> A(2,1) ans = 4 • : can be used to extract a whole column or row >> A(:,2) ans = 2 5 8 • or a part of a column or row >> A(1:2,2) ans = 2 5 X Y A = 12 3 45 6 7 8 9
  • 8. Image Arithmetic • Arithmetic operations such as addition, subtraction, multiplication and division can be applied to images in MATLAB – +, -, *, / performs matrix operations >> A+A ans = 2 4 6 8 10 12 14 16 18 >> A*A ans = 30 36 42 66 81 96 102 126 150 • To perform an elementwise operation use . (.*, ./, .*, .^ etc) >> A.*A ans = 1 4 9 16 25 36 49 64 81 A = 12 3 45 6 7 8 9
  • 9. Logical Conditions • equal (==) , less than and greater than (< and >), not equal (~=) and not (~) • find(‘condition’) - Returns indexes of A’s elements that satisfies the condition. >> [row col]=find(A==7) row = 3 col = 1 >> [row col]=find(A>7) row = 3 3 col = 2 3 >> Indx=find(A<5) Indx = 1 2 4 7 A = 12 3 45 6 7 8 9
  • 10. Flow Control • Flow control in MATLAB - if, else and elseif statements (row=1,2,3 col=1,2,3) if row==col A(row, col)=1; elseif abs(row-col)==1 A(row, col)=2; else A(row, col)=0; end A = 1 2 0 2 1 2 0 2 1
  • 11. Flow Control • Flow control in MATLAB - for loops for row=1:3 for col=1:3 if row==col A(row, col)=1; elseif abs(row-col)==1 A(row, col)=2; else A(row, col)=0; end end end A = 1 2 0 2 1 2 0 2 1
  • 12. Flow Control • while, expression, statements, end Indx=1; while A(Indx)<6 A(Indx)=0; Indx=Indx+1; end A = 12 3 45 6 7 8 9 A = 0 2 3 0 5 6 7 8 9
  • 13. Working with M-Files • M-files can be scripts that simply execute a series of MATLAB statements, or they can be functions that also accept input arguments and produce output. • MATLAB functions: – Are useful for extending the MATLAB language for your application. – Can accept input arguments and return output arguments. – Store variables in a workspace internal to the function.
  • 14. Working with M-Files • Create a new empty m-file function B=test(I) [row col]=size(I) for r=1:row for c=1:col if r==c A(r, c)=1; elseif abs(r-c)==1 A(r, c)=2; else A(r, c)=0; end end end B=A;