0% found this document useful (0 votes)
9 views8 pages

NM Week2 Final

The document outlines a MATLAB experiment focused on image transformations and filtering, detailing objectives such as importing, exporting, and displaying images, as well as performing various transformations and conversions. It includes procedures for manipulating images, adding shapes and text, and detecting colors using HSV thresholding. The results highlight the effectiveness of techniques like noise addition and removal, along with image analysis through color space conversions and region detection.

Uploaded by

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

NM Week2 Final

The document outlines a MATLAB experiment focused on image transformations and filtering, detailing objectives such as importing, exporting, and displaying images, as well as performing various transformations and conversions. It includes procedures for manipulating images, adding shapes and text, and detecting colors using HSV thresholding. The results highlight the effectiveness of techniques like noise addition and removal, along with image analysis through color space conversions and region detection.

Uploaded by

22l121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Exp 2 Image Transformations & Filtering

OBJECTIVE:
1. To import, export, and display images in MATLAB.
2. To perform image transformations like rotate, resize, and flip.
3. To convert images to grayscale, binary, and HSV.
4. To separate RGB and HSV image planes.
5. To apply block operations on image regions.
6. To add noise and apply filters (Gaussian, Median).
7. To detect edges and contours in images.
8. To access and process video frames.
9. To capture and analyze webcam images.
10. To detect colors using HSV thresholding.
11. To draw shapes and add text to images.
12. To analyze pixel values and image details.
13. To display results in multiple figure windows.

PROCEDURE:
• Import images using imread, visualize with imshow, and export with imwrite.

• Perform type conversions like grayscale (rgb2gray) and double precision


(im2double).
• Resize and rotate images using imresize and imrotate.

• Enhance contrast using imadjust and inspect individual pixel values. •

Add shapes (line, circle) and text using insertShape and insertText. •
Separate RGB color planes and convert to HSV using rgb2hsv.

• Add noise using imnoise and reduce it using median filtering (medfilt2). • Detect

specific color regions (e.g., red) by thresholding hue component in HSV space.
1. Importing, Exporting and Visualizing
Images CODE:
% Import image
img = imread('img1.png');

% Display image
figure; imshow(img); title('Original Image');

% Export image as new file


imwrite(img, 'output_img1.png');

2. Image Transformations and Type Conversions


CODE:
% Load image
img = imread('img1.png');

% Convert to grayscale and double type


gray_img = rgb2gray(img);
double_img = im2double(gray_img);

% Resize and rotate image


resized_img = imresize(img, 0.5);
rotated_img = imrotate(img, 45);

% Display results
figure;
subplot(1,3,1); imshow(gray_img); title('Grayscale');
subplot(1,3,2); imshow(resized_img); title('Resized');
subplot(1,3,3); imshow(rotated_img); title('Rotated');
OUTPUT:

1.Importing, Exporting and Visualizing Images

2. Image Transformations and Type Conversions

3. Contrast Adjustment & Pixel Info Analysis

Pixel value at (100,150): 154


3. Contrast Adjustment & Pixel Info Analysis
CODE:
% Load image and convert to grayscale
img = imread('img1.png');
gray_img = rgb2gray(img);

% Adjust contrast
adjusted_img = imadjust(gray_img);

% Get pixel info


pixel_value = gray_img(100,150);

% Display images
figure;
subplot(1,2,1); imshow(gray_img); title('Original Grayscale');
subplot(1,2,2); imshow(adjusted_img); title('Contrast Adjusted');
disp(['Pixel value at (100,150): ', num2str(pixel_value)]);

4. Adding Shapes and Text to Image


CODE:
% Load image
img = imread('img1.png');

% Insert a line, circle, and text


img_with_shapes = insertShape(img, 'Line', [50, 50, 200, 200], 'Color',
'red', 'LineWidth', 3);
img_with_shapes = insertShape(img_with_shapes, 'Circle', [150,150,40],
'Color', 'green', 'LineWidth', 3);
img_with_text = insertText(img_with_shapes, [10, 10], 'Sample Image',
'FontSize', 18, 'BoxColor', 'yellow');

% Display final image


figure; imshow(img_with_text); title('Image with Shapes and Text');
4. Adding Shapes and Text to Image

5.Image Conversions – Plane Separation, HSV


5. Image Conversions – Plane Separation, HSV
CODE:
% Load image
img = imread('img1.png');

% Plane separation (RGB)


R = img(:,:,1); G = img(:,:,2); B = img(:,:,3);

% HSV conversion
hsv_img = rgb2hsv(img);

% Display planes and HSV image


figure;
subplot(2,2,1); imshow(R); title('Red Plane');
subplot(2,2,2); imshow(G); title('Green Plane');
subplot(2,2,3); imshow(B); title('Blue Plane');
subplot(2,2,4); imshow(hsv_img); title('HSV Image');

6. Noise Types & Removal using Median Filter


CODE:
% Load image and add salt & pepper noise
img = imread('img1.png');
noisy_img = imnoise(img, 'salt & pepper', 0.02);

% Remove noise using median filter


filtered_img = medfilt2(rgb2gray(noisy_img), [3 3]);

% Display results
figure;
subplot(1,2,1); imshow(noisy_img); title('Noisy Image');
subplot(1,2,2); imshow(filtered_img); title('Filtered Image');

6. Noise Types & Removal using Median Filter


7. Region Detection & HSV Based Color Detection
7. Region Detection & HSV Based Color Detection
CODE:
% Load image
img = imread('img1.png');

% Convert to HSV
hsv_img = rgb2hsv(img);
hue = hsv_img(:,:,1);

% Color detection (e.g., red regions)


red_mask = (hue < 0.05 | hue > 0.95);

% Display mask
figure;
imshow(red_mask); title('Detected Red Regions');

RESULT:
Image resizing, rotation, and contrast adjustments were applied. Noise addition and
removal demonstrated filtering effectiveness. Color space conversions and region
detection aided image analysis.

You might also like