SlideShare a Scribd company logo
Multimedia Technology in
MATLAB
By:
Mustafa N. Jaafar
Lecture 2:
Representation Images In MATLAB Graphics
OUTLINE
• What Is Image Data?
• Data Types in MATLAB
• Supported Image Formats
• Read image from graphics file
• Information about graphics file
• Write image to graphics file
• Convert RGB image or colormap to grayscale
• Image Histogram in MATLAB
• Resize image in MATLAB
• Image representation, sampling and quantization
• Sampling image in MATLAB
• quantization image in MATLAB
WHAT IS IMAGE DATA?
• The basic MATLAB data structure is the array, an ordered set of real or complex elements. An array is
naturally suited to the representation of images, real-valued, ordered sets of color or intensity data. (An
array is suited for complex-valued images.)
• In the MATLAB workspace, most images are represented as two-dimensional arrays (matrices), in which
each element of the matrix corresponds to a single pixel in the displayed image. For example, an image
composed of 200 rows and 300 columns of different colored dots stored as a 200-by-300 matrix. Some
images, such as RGB, require a three-dimensional array, where the first plane in the third dimension
represents the red pixel intensities, the second plane represents the green pixel intensities, and the third
plane represents the blue pixel intensities.
DATA TYPES IN MATLAB
• MATLAB math supports three different numeric classes for image display:
• double-precision floating-point (double)
• 16-bit unsigned integer (uint16)
• 8-bit unsigned integer (uint8)
SUPPORTED IMAGE FORMATS
• MATLAB commands read, write, and display several types of graphics file formats for images. As
with MATLAB generated images, once a graphics file format image is displayed, it becomes an
image object. MATLAB supports the following graphics file formats, along with others:
• 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)
READ IMAGE FROM GRAPHICS FILE
• Syntax
• A = imread(filename)
• Example 1 from Matlab :
• A = imread('ngc6543a.jpg');
• imshow(A)% Display the image.
• Example 2 by using File in a folder
• A = imread(C:myFoldermyImage.ext’)
• Example 3 by using File in a folder
• A = imread(C:myFoldermyImage.ext')
BIT DEPTH
• Bit depth is the number of bits used to represent each image pixel. Bit depth is
calculated by multiplying the bits-per-sample with the samples-per-pixel. Thus, a
format that uses 8 bits for each color component (or sample) and three samples
per pixel has a bit depth of 24. Sometimes the sample size associated with a bit
depth can be ambiguous. For example, does a 48-bit bit depth represent six 8-bit
samples, four 12-bit samples, or three 16-bit samples? See Algorithms for sample
size information to avoid this ambiguity.
INFORMATION ABOUT GRAPHICS FILE
• Syntax
• info = imfinfo(filename)
• Description imfinfo(filename) returns a structure whose fields contain
information about an image in a graphics file
• Example :
• info = imfinfo('ngc6543a.jpg');
WRITE IMAGE TO GRAPHICS FILE
• Syntax
• imwrite(A,filename)
• Description: imwrite(A,filename) writes image data A to the file specified by
filename, inferring the file format from the extension. imwrite creates the new file
in your current folder. The bit depth of the output image depends on the data
type of A and the file format.
• Example
• A = rand(50);
• imwrite(A,'myGray.png')
CONVERT RGB IMAGE OR COLORMAP TO GRAYSCALE
• Syntax
• I = rgb2gray(RGB)
• Description rgb2gray(RGB) converts the truecolor image RGB to the grayscale image
I. The rgb2gray function converts
• Examples
• RGB = imread('peppers.png’);
• subplot(121); imshow(RGB) ; title (‘color image’)
• gray = rgb2gray(RGB);
• subplot(122); imshow(gray) ; title(‘Gray image’)
CONVERT RGB IMAGE OR COLORMAP TO GRAYSCALE
IMAGE HISTOGRAM
• Description : the imhist function creates a histogram plot by defining n equally
spaced bins, each representing a range of data values, and then calculating the
number of pixels within each range
• Example
• I = imread('rice.png’);
• subplot(121) ; imshow(I) ; title (‘ Orginal image’)
• subplot(122) ; imhist(I) ; title (‘ histogram image’)
IMAGE HISTOGRAM
RESIZE IMAGE IN MATLAB
• Syntax
• B = imresize(A,scale)
• Description imresize(A,scale) returns image B that is scale times the size of image A. The input
image A can be a grayscale, RGB, binary, or categorical image.
• Example1
• I = imread('ngc6543a.jpg’);
• J = imresize(I, 0.5);
• Example2
• RGB = imread('peppers.png’);
• RGB2 = imresize(RGB,[64 64]);
IMAGE REPRESENTATION, SAMPLING AND
QUANTIZATION
• To create an image which is digital, we need to covert continuous data into digital form. there are two steps in which it is done: (sampling , quantization )
• Sampling : related to coordinates values (nyquist frequency)
• Quantization : related to intensity values
• Sampling is done on the x-axis while quantization is done on the y-axis
SAMPLING
• Sampling corresponds to a discretization of the space. That is, of the domain of
the function, into f : [1, . . . ,N] × [1, . . . , M] → R
SAMPLING
• clc;clear all;close all; n=2;
• img = rgb2gray( imread('Lenna.png’))
• for i=1:n:size(img,1)
• for j=1:n:size(img,2)
• for k=0:n-1
• for l=0:n-1
• im(i+k,j+l)=img(i,j);
• end end end end
• subplot(1,2,1);imshow(uint8(img));title('Original Image');
• subplot(1,2,2);imshow(uint8(im));title('Sampled Image');
SAMPLING
QUANTIZATION IMAGE
• Syntax
• quant_A = imquantize(A,levels)
• Description example quant_A = imquantize(A,levels) quantizes image A using
specified quantization values contained in the N element vector levels.
QUANTIZATION IMAGE
QUANTIZATION IMAGE
• clc;clear all; close all
• Image = imread('peppers.png');
• grayImage= rgb2gray(Image);
• subplot(2, 4, 1);imshow(grayImage, []); title('Original Gray Scale Image')
• for level =2:8
• thresh = multithresh(grayImage,level)
• quantizedImage = imquantize(grayImage, thresh);
• subplot(2, 4, level);imshow((quantizedImage),[]); title(['quantized with level '
num2str(level) ]);
• end
QUANTIZATION IMAGE
SUMMERY
Matalb function :
• imread() – reading an image with different postfixes
• imresize() – resizing an image to any given size
• figure – opening a new graphical window
• subplot(#of row, # of col, location) – showing different plots/images in one graphical window
• imshow() – displaying an image
• Imquantize- (A,levels) quantizes image
 We have looked at:
 What is sampling?
 What is spatial resolution?
 What is quantization?
 What is grey-level resolution
Thank you
For Listen

More Related Content

What's hot

Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
Azharo7
 
Digital Audio
Digital AudioDigital Audio
Digital Audio
kavitha muneeshwaran
 
Chapter 5 : ANIMATION
Chapter 5 : ANIMATIONChapter 5 : ANIMATION
Chapter 5 : ANIMATION
azira96
 
Animation and Video
Animation and VideoAnimation and Video
Animation and Video
Shubham Sharma
 
Presentation of Lossy compression
Presentation of Lossy compressionPresentation of Lossy compression
Presentation of Lossy compression
Omar Ghazi
 
Image processing on matlab presentation
Image processing on matlab presentationImage processing on matlab presentation
Image processing on matlab presentation
Naatchammai Ramanathan
 
Image & Graphics
Image & GraphicsImage & Graphics
Image & Graphics
Shafiqul Islam Tuhin
 
Green screen Technology
Green screen TechnologyGreen screen Technology
Green screen Technologyleahgreenbaum
 
Image processing
Image processing Image processing
Image processing
Madhushree Ghosh
 
Raster Vs. Vector Presentation1
Raster Vs. Vector Presentation1Raster Vs. Vector Presentation1
Raster Vs. Vector Presentation1cdoeberl
 
Multimedia And Animation
Multimedia And AnimationMultimedia And Animation
Multimedia And AnimationRam Dutt Shukla
 
Basic Concepts of Animation
Basic Concepts of AnimationBasic Concepts of Animation
Basic Concepts of Animation
jamalharun
 
Multimedia fundamental concepts in video
Multimedia fundamental concepts in videoMultimedia fundamental concepts in video
Multimedia fundamental concepts in video
Mazin Alwaaly
 
Color Models.pptx
Color Models.pptxColor Models.pptx
Color Models.pptx
ssuser9203ca
 
Audio file format in computer graphic
Audio file format in computer graphicAudio file format in computer graphic
Audio file format in computer graphic
Irfan Khan
 
Video Compression Basics
Video Compression BasicsVideo Compression Basics
Video Compression Basics
Sanjiv Malik
 
Multimedia tools(images)
Multimedia tools(images)Multimedia tools(images)
Multimedia tools(images)dhruv patel
 
Explain Animation & Types Of Animation In Computer Graphics
Explain Animation & Types Of Animation In Computer Graphics Explain Animation & Types Of Animation In Computer Graphics
Explain Animation & Types Of Animation In Computer Graphics
Vikashkumar2175
 
Color models
Color modelsColor models
Color models
Rakesh Pandey
 
Video Compression Techniques
Video Compression TechniquesVideo Compression Techniques
Video Compression Techniques
cnssources
 

What's hot (20)

Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 
Digital Audio
Digital AudioDigital Audio
Digital Audio
 
Chapter 5 : ANIMATION
Chapter 5 : ANIMATIONChapter 5 : ANIMATION
Chapter 5 : ANIMATION
 
Animation and Video
Animation and VideoAnimation and Video
Animation and Video
 
Presentation of Lossy compression
Presentation of Lossy compressionPresentation of Lossy compression
Presentation of Lossy compression
 
Image processing on matlab presentation
Image processing on matlab presentationImage processing on matlab presentation
Image processing on matlab presentation
 
Image & Graphics
Image & GraphicsImage & Graphics
Image & Graphics
 
Green screen Technology
Green screen TechnologyGreen screen Technology
Green screen Technology
 
Image processing
Image processing Image processing
Image processing
 
Raster Vs. Vector Presentation1
Raster Vs. Vector Presentation1Raster Vs. Vector Presentation1
Raster Vs. Vector Presentation1
 
Multimedia And Animation
Multimedia And AnimationMultimedia And Animation
Multimedia And Animation
 
Basic Concepts of Animation
Basic Concepts of AnimationBasic Concepts of Animation
Basic Concepts of Animation
 
Multimedia fundamental concepts in video
Multimedia fundamental concepts in videoMultimedia fundamental concepts in video
Multimedia fundamental concepts in video
 
Color Models.pptx
Color Models.pptxColor Models.pptx
Color Models.pptx
 
Audio file format in computer graphic
Audio file format in computer graphicAudio file format in computer graphic
Audio file format in computer graphic
 
Video Compression Basics
Video Compression BasicsVideo Compression Basics
Video Compression Basics
 
Multimedia tools(images)
Multimedia tools(images)Multimedia tools(images)
Multimedia tools(images)
 
Explain Animation & Types Of Animation In Computer Graphics
Explain Animation & Types Of Animation In Computer Graphics Explain Animation & Types Of Animation In Computer Graphics
Explain Animation & Types Of Animation In Computer Graphics
 
Color models
Color modelsColor models
Color models
 
Video Compression Techniques
Video Compression TechniquesVideo Compression Techniques
Video Compression Techniques
 

Similar to Working with images in matlab graphics

Image processing tool box.pptx
Image processing tool box.pptxImage processing tool box.pptx
Image processing tool box.pptx
AvinashJain66
 
ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)Hasitha Ediriweera
 
Dip digital image 3
Dip digital image 3Dip digital image 3
Dip digital image 3
Shajun Nisha
 
Image Processing Using MATLAB
Image Processing Using MATLABImage Processing Using MATLAB
Image Processing Using MATLAB
Amarjeetsingh Thakur
 
Image processing in MATLAB
Image processing in MATLABImage processing in MATLAB
Image processing in MATLAB
Amarjeetsingh Thakur
 
Matlab intro
Matlab introMatlab intro
Matlab introfvijayami
 
Image processing
Image processingImage processing
Image processing
Antriksh Saxena
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
Ankur Nanda
 
Introduction to Image Processing with MATLAB
Introduction to Image Processing with MATLABIntroduction to Image Processing with MATLAB
Introduction to Image Processing with MATLAB
Sriram Emarose
 
Image processing basics using matlab
Image processing basics using matlabImage processing basics using matlab
Image processing basics using matlabAnkur Tyagi
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
minhtaispkt
 
Images in matlab
Images in matlabImages in matlab
Images in matlab
Ali Alvi
 
4 image enhancement in spatial domain
4 image enhancement in spatial domain4 image enhancement in spatial domain
4 image enhancement in spatial domain
Prof. Dr. Subhasis Bose
 
Dip day1&2
Dip day1&2Dip day1&2
Dip day1&2
nakarthik91
 
Digital Image Processing (Lab 07)
Digital Image Processing (Lab 07)Digital Image Processing (Lab 07)
Digital Image Processing (Lab 07)
Moe Moe Myint
 
Dip syntax 4
Dip syntax 4Dip syntax 4
Dip syntax 4
Shajun Nisha
 

Similar to Working with images in matlab graphics (20)

Image processing tool box.pptx
Image processing tool box.pptxImage processing tool box.pptx
Image processing tool box.pptx
 
ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)ImageProcessingWithMatlab(HasithaEdiriweera)
ImageProcessingWithMatlab(HasithaEdiriweera)
 
Dip digital image 3
Dip digital image 3Dip digital image 3
Dip digital image 3
 
Image Processing Using MATLAB
Image Processing Using MATLABImage Processing Using MATLAB
Image Processing Using MATLAB
 
Image processing in MATLAB
Image processing in MATLABImage processing in MATLAB
Image processing in MATLAB
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Image processing
Image processingImage processing
Image processing
 
Ec section
Ec section Ec section
Ec section
 
Image processing
Image processingImage processing
Image processing
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 
Introduction to Image Processing with MATLAB
Introduction to Image Processing with MATLABIntroduction to Image Processing with MATLAB
Introduction to Image Processing with MATLAB
 
Image processing basics using matlab
Image processing basics using matlabImage processing basics using matlab
Image processing basics using matlab
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
 
Report
ReportReport
Report
 
Images in matlab
Images in matlabImages in matlab
Images in matlab
 
4 image enhancement in spatial domain
4 image enhancement in spatial domain4 image enhancement in spatial domain
4 image enhancement in spatial domain
 
Dip day1&2
Dip day1&2Dip day1&2
Dip day1&2
 
Digital Image Processing (Lab 07)
Digital Image Processing (Lab 07)Digital Image Processing (Lab 07)
Digital Image Processing (Lab 07)
 
Dip syntax 4
Dip syntax 4Dip syntax 4
Dip syntax 4
 

Recently uploaded

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 

Working with images in matlab graphics

  • 1. Multimedia Technology in MATLAB By: Mustafa N. Jaafar Lecture 2: Representation Images In MATLAB Graphics
  • 2. OUTLINE • What Is Image Data? • Data Types in MATLAB • Supported Image Formats • Read image from graphics file • Information about graphics file • Write image to graphics file • Convert RGB image or colormap to grayscale • Image Histogram in MATLAB • Resize image in MATLAB • Image representation, sampling and quantization • Sampling image in MATLAB • quantization image in MATLAB
  • 3. WHAT IS IMAGE DATA? • The basic MATLAB data structure is the array, an ordered set of real or complex elements. An array is naturally suited to the representation of images, real-valued, ordered sets of color or intensity data. (An array is suited for complex-valued images.) • In the MATLAB workspace, most images are represented as two-dimensional arrays (matrices), in which each element of the matrix corresponds to a single pixel in the displayed image. For example, an image composed of 200 rows and 300 columns of different colored dots stored as a 200-by-300 matrix. Some images, such as RGB, require a three-dimensional array, where the first plane in the third dimension represents the red pixel intensities, the second plane represents the green pixel intensities, and the third plane represents the blue pixel intensities.
  • 4. DATA TYPES IN MATLAB • MATLAB math supports three different numeric classes for image display: • double-precision floating-point (double) • 16-bit unsigned integer (uint16) • 8-bit unsigned integer (uint8)
  • 5. SUPPORTED IMAGE FORMATS • MATLAB commands read, write, and display several types of graphics file formats for images. As with MATLAB generated images, once a graphics file format image is displayed, it becomes an image object. MATLAB supports the following graphics file formats, along with others: • 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)
  • 6. READ IMAGE FROM GRAPHICS FILE • Syntax • A = imread(filename) • Example 1 from Matlab : • A = imread('ngc6543a.jpg'); • imshow(A)% Display the image. • Example 2 by using File in a folder • A = imread(C:myFoldermyImage.ext’) • Example 3 by using File in a folder • A = imread(C:myFoldermyImage.ext')
  • 7. BIT DEPTH • Bit depth is the number of bits used to represent each image pixel. Bit depth is calculated by multiplying the bits-per-sample with the samples-per-pixel. Thus, a format that uses 8 bits for each color component (or sample) and three samples per pixel has a bit depth of 24. Sometimes the sample size associated with a bit depth can be ambiguous. For example, does a 48-bit bit depth represent six 8-bit samples, four 12-bit samples, or three 16-bit samples? See Algorithms for sample size information to avoid this ambiguity.
  • 8. INFORMATION ABOUT GRAPHICS FILE • Syntax • info = imfinfo(filename) • Description imfinfo(filename) returns a structure whose fields contain information about an image in a graphics file • Example : • info = imfinfo('ngc6543a.jpg');
  • 9. WRITE IMAGE TO GRAPHICS FILE • Syntax • imwrite(A,filename) • Description: imwrite(A,filename) writes image data A to the file specified by filename, inferring the file format from the extension. imwrite creates the new file in your current folder. The bit depth of the output image depends on the data type of A and the file format. • Example • A = rand(50); • imwrite(A,'myGray.png')
  • 10. CONVERT RGB IMAGE OR COLORMAP TO GRAYSCALE • Syntax • I = rgb2gray(RGB) • Description rgb2gray(RGB) converts the truecolor image RGB to the grayscale image I. The rgb2gray function converts • Examples • RGB = imread('peppers.png’); • subplot(121); imshow(RGB) ; title (‘color image’) • gray = rgb2gray(RGB); • subplot(122); imshow(gray) ; title(‘Gray image’)
  • 11. CONVERT RGB IMAGE OR COLORMAP TO GRAYSCALE
  • 12. IMAGE HISTOGRAM • Description : the imhist function creates a histogram plot by defining n equally spaced bins, each representing a range of data values, and then calculating the number of pixels within each range • Example • I = imread('rice.png’); • subplot(121) ; imshow(I) ; title (‘ Orginal image’) • subplot(122) ; imhist(I) ; title (‘ histogram image’)
  • 14. RESIZE IMAGE IN MATLAB • Syntax • B = imresize(A,scale) • Description imresize(A,scale) returns image B that is scale times the size of image A. The input image A can be a grayscale, RGB, binary, or categorical image. • Example1 • I = imread('ngc6543a.jpg’); • J = imresize(I, 0.5); • Example2 • RGB = imread('peppers.png’); • RGB2 = imresize(RGB,[64 64]);
  • 15. IMAGE REPRESENTATION, SAMPLING AND QUANTIZATION • To create an image which is digital, we need to covert continuous data into digital form. there are two steps in which it is done: (sampling , quantization ) • Sampling : related to coordinates values (nyquist frequency) • Quantization : related to intensity values • Sampling is done on the x-axis while quantization is done on the y-axis
  • 16. SAMPLING • Sampling corresponds to a discretization of the space. That is, of the domain of the function, into f : [1, . . . ,N] × [1, . . . , M] → R
  • 17. SAMPLING • clc;clear all;close all; n=2; • img = rgb2gray( imread('Lenna.png’)) • for i=1:n:size(img,1) • for j=1:n:size(img,2) • for k=0:n-1 • for l=0:n-1 • im(i+k,j+l)=img(i,j); • end end end end • subplot(1,2,1);imshow(uint8(img));title('Original Image'); • subplot(1,2,2);imshow(uint8(im));title('Sampled Image');
  • 19.
  • 20. QUANTIZATION IMAGE • Syntax • quant_A = imquantize(A,levels) • Description example quant_A = imquantize(A,levels) quantizes image A using specified quantization values contained in the N element vector levels.
  • 22. QUANTIZATION IMAGE • clc;clear all; close all • Image = imread('peppers.png'); • grayImage= rgb2gray(Image); • subplot(2, 4, 1);imshow(grayImage, []); title('Original Gray Scale Image') • for level =2:8 • thresh = multithresh(grayImage,level) • quantizedImage = imquantize(grayImage, thresh); • subplot(2, 4, level);imshow((quantizedImage),[]); title(['quantized with level ' num2str(level) ]); • end
  • 24. SUMMERY Matalb function : • imread() – reading an image with different postfixes • imresize() – resizing an image to any given size • figure – opening a new graphical window • subplot(#of row, # of col, location) – showing different plots/images in one graphical window • imshow() – displaying an image • Imquantize- (A,levels) quantizes image  We have looked at:  What is sampling?  What is spatial resolution?  What is quantization?  What is grey-level resolution