Image Processing in MATLAB | Fundamental Operations
Last Updated :
06 Aug, 2021
1. Reading Images
Images are read into the MATLAB Environment using imread() function which takes filename with applicable extension as the argument
For Example:
>> I=imread('nature.jpg');
This will read JPEG image 'nature' into the image array.
Note: The semicolon(;) at the end of command line is used to suppress the output in MATLAB.If ';' is not used at the end, it will show the output of the specified operation.
2.Displaying Images
imshow() function is used to display images in MATLAB. The basic syntax of imshow() is
imshow(f, G);
Here f is image matrix and G is number of intensity level used to display the image. The second Argument in the above syntax is optional. If G is omitted its value defaults to 256 levels.
When we use the syntax
imshow(f, [Low, High]);
It displays all value less than or equal to 'Low' as black and all values greater than or equal to 'High' as white. The values between 'Low' and 'High' are displayed as the intermediate intensity value using the default number of levels.
Examples:
Showing Grayscale Images
>> imshow(f);
This will display the grayscale image f.
Also, we can write
>> imshow(f, [90, 180]);
It will display all value less than or equal to 90 as black and all values greater than or equal to 180 as white. The values between 90 and 180 are displayed as the intermediate intensity value using the default number of levels.
Showing Binary images
>> imshow(BW);
It displays the binary image BW. It displays pixels with the value 0 (zero) as black and pixels with the value 1 as white.
Showing RGB images
>> imshow(f);
It displays the RGB image f.
3. Writing images to disk
Images are written to disk using imwrite() function. The basic syntax of imwrite() is
imwrite(f, 'filename');
Here f is our image and filename is the name of file including a recognized file format extension. Alternatively, we can also specify desired format explicitly with a third argument.
For example
>> imwrite(f, 'nature.jpg');
Alternatively, we can write it as,
>> imwrite(f, 'nature', 'jpg');
The above commands write image f to a filename nature with extension jpg.
Note: The imwrite() function have some optional parameters too, depending upon file format.
For example:
>> imwrite(f, 'filename', 'quality', q);
The above syntax is applicable for only JPEG images. Here q is an integer and can take value between 0 to 100. Lower the value of q higher the degradation due to JPEG compression.
Some Other Important functions
i.) imfinfo
It displays the details of an image file
Example:
>> imfinfo nature.jpg;
Output:
Filename: 'nature.jpg'
FileModDate: '23-Jun-2016 09:57:04'
FileSize: 238290
Format: 'jpg'
FormatVersion: ''
Width: 1920
Height: 1200
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {'CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), quality = 92?'}
ii.) size()
size() function take image matrix as an argument and give the row and column dimension of an image f. This function is used to determine the size of an image automatically.
Example :
>> size(f)
Output :
ans =
1920 1200
Here 1920 is the number of rows and 1200 is the number of columns in image f.
Note: As we know RGB images are represented using 3-D matrix in MATLAB. So, if f is a RGB image the above function will produce output as
ans =
1920 1200 3
iii.) whos f
This function will show additional detail about image matrix f.
Example :
whos f
Output :
Name Size Bytes Class Attributes
f 300x400x3 360000 uint8
Similar Reads
Negative of an image in MATLAB The negative of an image is achieved by replacing the intensity 'i' in the original image by 'i-1', i.e. the darkest pixels will become the brightest and the brightest pixels will become the darkest. Image negative is produced by subtracting each pixel from the maximum intensity value. For example i
2 min read
MATLAB - Intensity Transformation Operations on Images Intensity transformations are among the simplest of all image processing techniques. Approaches whose results depend only on the intensity at a point are called point processing techniques or Intensity transformation techniques. Although intensity transformation and spatial filtering methods span a
4 min read
Boundary Extraction of image using MATLAB The boundary of the image is different from the edges in the image. Edges represent the abrupt change in pixel intensity values while the boundary of the image is the contour. As the name boundary suggests that something whose ownership changes, in the image when pixel ownership changes from one sur
3 min read
Digital Image Processing Algorithms using MATLAB Like it is said, "One picture is worth more than ten thousand words "A digital image is composed of thousands and thousands of pixels. An image could also be defined as a two-dimensional function, f(x, y), where x and y are spatial (plane) coordinates and therefore the amplitude of f at any pair of
8 min read
Image Zooming in MATLAB MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. With the help of this software, we can also zoom in on an image. Following are the steps to the same. Example 1: Matlab % MATLAB progr
2 min read