How represent the digital image in Matlab
https://www.youtube.com/watch?v=-6U8le3HQlI
https://www.slideshare.net/mustafa_92/working-with-images-inmatlabgraphics-251331243
https://github.com/Mustafa-nafaa/Multimedia-TechnologyLab/tree/main/Week2:Image%20Representation
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
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
What is sampling?
What is spatial resolution?
What is quantization?
What is grey-level resolution
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’)
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');
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.
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