0% found this document useful (0 votes)
160 views9 pages

Basic Image Processing in MATLAB

This document provides instructions for performing basic image processing operations in MATLAB. It describes how to read images using imread(), display images using imshow(), add noise to images using imnoise(), and write images to different file formats using imwrite(). It then lists several tasks for students to complete involving importing, displaying, converting, and generating different types of images in MATLAB.

Uploaded by

Mahnoor Mansoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views9 pages

Basic Image Processing in MATLAB

This document provides instructions for performing basic image processing operations in MATLAB. It describes how to read images using imread(), display images using imshow(), add noise to images using imnoise(), and write images to different file formats using imwrite(). It then lists several tasks for students to complete involving importing, displaying, converting, and generating different types of images in MATLAB.

Uploaded by

Mahnoor Mansoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

2020-CE-044 B

LAB# 9
BASIC OPERATIONS ON IMAGE PROCESSING

OBJECTIVES:
● Follow instructions to perform basic operations on image processing
Image reading:
The command in matlab to read an image is imread() where inside the
bracket the name of the file to be read is mentioned e.g. ‘[Link]’.
Matlab supports a wide variety of image types with various parameters. See
the Matlab help for full list of supported files and diferent imread() command
options. Note that we onlly need the basic command format.
In case of reading an indexed image, color map can be read as well using the
folloing command:
[X,map] = imread(‘An indexed image name’)

where X is the image and map stores the color map. The code below reads
different kind of images. Note that there are four types of concerned
images,namely, RGB (true color), indexed image, grayscale and binary. In
addition, data type of the images once read can be of many data format
incluing double, uint8 (unsigned integer 8 bit representation) and logical (i.e.
binary). The size of the image can be seen using the command size().

Basic Operations on Image Processing


imread: reads a grayscale or color image from the file specified by the string
filename. imshow: displays binary, grayscale and color image. For binary,
displays pixels with the value 0 as black and pixels with the value 1 as white.
A color map matrix may have any number of rows, but it must have exactly 3
columns. Each row is interpreted as a color, with the first element specifying
the intensity of red light, the second green, and the third blue. Color intensity
can be specified on the interval 0.0 to 1.0.
imnoise: adds noise of a given type to the intensity of image I. type is a string
that can have one of following values. See syntax and table below;
imnoise(I,type)
2020-CE-044 B

EXAMPLE:
2020-CE-044 B

LAB TASK:
Task #1: Type in the command window
>> help imdemos

This will give you a list of, amongst other things; the entire sample TIFF images which come with the
Image Processing Toolbox. Make a list of these sample images, and for each image
(a) Determine its type (binary, grayscale or true color),

(b) Determine its size (in pixels)


2020-CE-044 B

(c) Give a brief description of the picture

imageinfo('[Link]')

Task #2: Pick any grayscale image. Using the imwrite function, write it to files of type JPEG, PNG and
BMP. What are the sizes of those files?
2020-CE-044 B

Task #3: Repeat the above question with


(a) (a) A binary image,

(b) An indexed color image,


2020-CE-044 B

(c) A true color image.

Task #4: Pick any image and convert its mode to uint8 and uint16.
2020-CE-044 B

Task #5: Import an image ‘[Link]’ and display it. Also convert the image formats into:
(a) Indexed image.
(b) Intensity image.
(c) Binary image.
Use subplot command to display all formats in one figure.

Task #6: Import any color image and extract out the red, green and blue color from it.
2020-CE-044 B

Task #7: Design the following images through Matlab, by using loops, trigonometric functions and
matrices:
(a) (b)

(c) (
2020-CE-044 B

(e)

(f)

Common questions

Powered by AI

Converting image data to formats like uint8 and uint16 in MATLAB is crucial for compatibility with different functions and operations, ensuring efficient storage and processing capabilities. This conversion is done using the appropriate MATLAB functions, where a command can change the bit depth of an image, impacting the image's precision and size. The process is integral to tasks such as reducing file sizes for storage or enhancing compatibility with certain image processing functions that require specific data types.

To extract the RGB components from a color image in MATLAB, one must access each color channel separately. For an image matrix with RGB format, the red, green, and blue components can be extracted by splitting the 3D matrix along its third dimension. For an image called ‘img’, the components can be extracted using: R = img(:,:,1), G = img(:,:,2), and B = img(:,:,3), where each matrix R, G, and B represents the respective color channels of the image.

Image processing skills in MATLAB can be applied in developing applications addressing real-world problems such as automated quality inspection in manufacturing, where image processing identifies product defects with techniques like edge detection or pattern recognition. In healthcare, MATLAB can process medical images for diagnostic assistance. In traffic systems, it aids in image-based traffic analysis or vehicle counting. Leveraging MATLAB's robust processing power enhances image-related problem-solving, bringing computational capabilities to practical and diverse fields efficiently.

MATLAB manages noise addition in images using the imnoise function, where noise types like Gaussian, salt & pepper, speckle, and more can be added to an image to simulate real-world environments or test the robustness of image processing algorithms. This is specifically useful in applications where evaluating the performance of de-noising algorithms or assessing the impact of noise on image analysis is required. The syntax for adding noise is: imnoise(I,type), where type specifies the kind of noise added.

Challenges in performing type conversion on images in MATLAB include loss of precision, increased memory usage, and compatibility issues with certain functions requiring specific data types. To address these, it's essential to choose the appropriate conversion target based on application needs, i.e., using uint8 for conserving memory and speed for display purposes, or double for precision required in computational algorithms. Awareness of data type limitations and proper handling through MATLAB's type conversion functions ensure efficiency and functionality in processing.

The subplot function in MATLAB effectively enables the display of multiple image formats within the same window by dividing the display area into a grid of specified rows and columns, and plotting each image in its respective cell. This is particularly useful for comparing the effects of different image processing techniques, visualizing image transformations, or evaluating the outcomes of algorithms side by side, such as contrasting the original image against its indexed, intensity, or binary format variations in a coherent manner.

When converting a grayscale image to JPEG, PNG, and BMP formats in MATLAB, file size differences arise due to each format's compression efficiency and characteristics. JPEG applies lossy compression leading to smaller file sizes but potential quality loss. PNG uses lossless compression, maintaining image quality at larger file sizes than JPEGs. BMP generally results in the largest files due to minimal compression. The imwrite function in MATLAB can perform these conversions, and examining the file sizes post-conversion can provide insights into the efficiency and suitability of each format for different applications.

Efficient design of complex images in MATLAB using loops, trigonometric functions, and matrices involves algorithmic planning to reduce computation, utilizing pre-defined functions like meshgrid for matrix creation, optimizing loop statements, and leveraging MATLAB's vectorization features. Strategic use of trigonometric functions can create intricate patterns or simulate natural forms such as waves or spirals, while matrices define geometric placements or variations in intensity and color, leading to sophisticated visual outputs with minimal code complexity and higher execution efficiency.

MATLAB's image processing functions like imread() and imshow() allow for reading and displaying images in a variety of formats such as RGB, indexed, grayscale, and binary. The function imread() reads an image from a file, with different syntaxes for reading indexed images, which includes both the image data and the colormap. imshow() is used to display these images, representing binary images with black for 0 and white for 1. Each of these image types can be stored in different data formats such as double, uint8, or logical, depending on the operations to be performed.

Understanding the file size implications of JPEG, PNG, and BMP formats is critical in professional settings such as web development, digital archiving, and scientific analysis where storage, quality, and transmission speed are crucial factors. JPEG’s reduced file size benefits internet bandwidth but compromises quality. PNG balances quality and size for detailed images where text and line art are important. BMP, used rarely due to size, is critical in environments where compression is undesirable. These characteristics influence professional decisions on format selection depending on specific operational requirements.

You might also like