DIP_ASSIGNMENT_RAhul[1]

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

INDIAN INSTITUTE OF INFORMATION

TECHNOLOGY, BHOPAL (IIIT-BHOPAL)


Department of Computer Science and
Engineering

Digital Image Processing Lab


(IT - 312)
Vth - Semester
Submitted to: Submitted By:

Dr. Bhupender Singh Kirar Yogesh Jadhav

Subject Coordinator (DIP) 22U03006


INDEX
S. No. Name of Assignment Date Of Date Of Pg. No Remarks
Assignment Submission

1. Write about introduction to


commands and functions used in
7/08/24 04/09/24 3-4
Digital Image Processing

2. Write a program to read and display


images using MATLAB.
7/08/24 04/09/24 5-7

3. To write a MATLAB program to


convert an RGB image to grayscale
7/08/24 04/09/24 8-10
and display both the original and
grayscale images using the subplot
function.

4. Write a program for Histogram


Calculation and equalization
21/08/24 04/09/24 11-15
(a) Standard MATLAB
Function

(b) Enchancing contrast using


histogram equalization
ASSIGNMENT 1
AIM:Write about introduction to commands and
functions used in Digital Image Processing.
MATLAB (Matrix Laboratory) is a powerful tool that can be widely used for digital image
processing due to its robust set of built-in functions and toolboxes. The Image Processing
Toolbox in provides a comprehensive set of reference-standard algorithms and functions for
image analysis, visualization, and algorithm development.

Category Command Description Example Code


Reading and imread Reads an img = imread('image.jpg');
Displaying image from a
Images file into a
matrix.
imshow Displays an imshow(img);
image in a
figure
window.
imwrite Writes an Imwrite(img,
image to a 'new_image.jpg');
file.
Image imresize Resizes an resized_img =
Transformation image to a imresize(img, [256 256]);
specified size.
imrotate Rotates an rotated_img =
image by a imrotate(img, 45);
specified
angle.
imcrop Crops a cropped_img =
portion of an imcrop(img, [50 50 100
image. 100]);
Image rgb2gray Converts an gray_img = rgb2gray(img);
Enhancement RGB image to
grayscale.
histeq Performs enhanced_img =
histogram histeq(gray_img);
equalization
to enhance
contrast.
imadjust Adjusts the adjusted_img =
intensity imadjust(gray_img);
values or
colormap.
Filtering and imfilter Applies a filtered_img = imfilter(img,
Noise linear filter to fspecial('sobel'));
Reduction an image.
medfilt2 Applies a median_filtered_img =
median filter medfilt2(gray_img);
to a 2D
image.
Morphological imopen Performs opened_img =
Operations morphological imopen(img, strel('disk',
opening. 5));
imclose Performs closed_img = imclose(img,
morphological strel('disk', 5));
closing.
imerode Erodes an eroded_img =
image. imerode(img, strel('disk',
3));
imdilate Dilates an dilated_img =
image. imdilate(img, strel('disk',
3));
Edge Detection edge Detects edges edges = edge(gray_img,
using 'canny');
different
methods such
as Sobel,
Canny, etc.
Image imbinarize Converts an binary_img =
Segmentation image to a imbinarize(gray_img);
binary image
using
thresholding.
bwlabel Labels [L, num] =
connected bwlabel(binary_img);
components
in a binary
image.
regionprops Measures stats = regionprops(L,
properties of 'Area', 'Centroid');
image
regions.
Color Image rgb2hsv Converts an hsv_img = rgb2hsv(img);
Processing RGB image to
HSV color
space.
ind2rgb Converts an rgb_img =
indexed ind2rgb(indexed_img,
image to RGB colormap);
using a
colormap.
ASSIGNMENT 2
AIM: Write a program to read and display images using
MATLAB.
THEORY:
Image processing involves the manipulation of pixel data within an image to achieve a
desired outcome. Reading and displaying images are fundamental tasks in image processing.
MATLAB provides built-in functions like `imread` for reading images and `imshow` for
displaying them. These functions help in understanding the dimensions, data type, and basic
properties of the image.

ALGORITHM:
1. Start the program by clearing the workspace and command window.

2. Define the filename of the image to be read.

3. Use the `imread` function to load the image into a variable.

4. Display the image using the `imshow` function within a figure window.

5. Retrieve and display the size (dimensions) and data type of the image.

CODE:
img = imread(filename); % Reading File %

imshow(img); % Showing Output %

[rows, cols, channels] = size(img); % Storing Output Data %

MATHEMATICAL EXPRESSION:
No specific mathematical expressions are involved in this task. The code primarily handles
image data as arrays of pixel values, and MATLAB functions perform the underlying
operations.

Image size: 272 x 337 x Image data type: uint8


TUTORIAL:

OUTPUT:
ASSIGNMENT 3
AIM: To write a MATLAB program to convert an RGB
image to grayscale and display both the original and
grayscale images using the subplot function.
THEORY:
Grayscale conversion is a common image processing task where a color image is transformed
into a grayscale image, reducing the color channels to a single channel representing intensity.
The rgb2gray function in MATLAB performs this conversion. Displaying multiple images in
a single figure can be efficiently done using the subplot function, which allows arranging
images in a grid within the figure window.

ALGORITHM:
1. Start by clearing the workspace and command window.

2. Define the filename of the image to be processed.

3. Use `imread` to load the image into a variable.

4. Convert the color image to grayscale using `rgb2gray`.

5. Create a figure window and use `subplot` to display the original and grayscale images side
by side.

6. Display the image size for both the original and grayscale images in the console.

CODE:
 color_img = imread(filename); % Reading File %

gray_img = rgb2gray(color_img); % Converting RGB to Grayscale %

subplot(1, 2, 1);
imshow(color_img); % Showing Original Image %

subplot(1, 2, 2);
imshow(gray_img); % Showing Grayscale Image %

fprintf('Original Image size: %d x %d x %d\n', size(color_img, 1),


size(color_img, 2), size(color_img, 3)); % Output Image Size %
fprintf('Grayscale Image size: %d x %d\n', size(gray_img, 1), size(gray_img,
2)); % Output Grayscale Size %

MATHEMATICAL EXPRESSION:
�ℎ� ��������� ����� �� ���������� ����� � ����ℎ��� ��� �� �ℎ� ��� �ℎ������ :[Gray = �. ���� ×
� + �. ���� × � + �. ���� × �]
TUTORIAL:

OUTPUT:
TUTORIAL

OUTPUT:
ASSIGNMENT 4
AIM: Write a program for Histogram Calculation and
equalization.
THEORY:
1. Histogram Calculation

Histogram: In image processing, the histogram is a graphical representation of the


distribution of pixel intensity values in an image. It shows the number of pixels for each
intensity level.

2. Histogram Equalization

Purpose: Histogram equalization is a technique to improve the contrast of an image by


redistributing the intensity levels. It aims to produce an image with a more uniform
distribution of pixel intensities.

ALGO:
How to Calculate Histogram:

For Grayscale Images: Each pixel value in a grayscale image ranges from 0 (black) to 255
(white). To calculate the histogram:

Create a vector hist of size 256 (for 8-bit images) initialized to zero.

Traverse the image pixel by pixel.

For each pixel intensity value, increment the corresponding index in the histogram vector.

Example MATLAB code:

img = imread('image.png'); % Read the image

gray_img = rgb2gray(img); % Convert to grayscale if needed

hist = imhist(gray_img); % Calculate histogram

MATLAB Functions:

imhist(I): Computes the histogram of image I.

histeq(I): Performs histogram equalization on image I.

Example MATLAB CODE:

img = imread('image.png'); % Read the image


gray_img = rgb2gray(img); % Convert to grayscale

equalized_img = histeq(gray_img); % Perform histogram equalization

subplot(1,2,1), imshow(gray_img), title('Original Image');

subplot(1,2,2), imshow(equalized_img), title('Equalized Image');

TUTORIAL

OUTPUT:

You might also like