0% found this document useful (0 votes)
4 views6 pages

DIP_Experiments_1_to_6_with_Code_and_Outputs

The document outlines various image processing experiments, including arithmetic operations (addition, subtraction, multiplication, division), geometric transformations (rotation, scaling, translation), Fourier transforms (1D and 2D FFT), contrast adjustments (stretching, histogram equalization), and smoothing filters (mean, median). Each experiment includes code snippets and expected output descriptions. Additionally, it covers sharpening techniques and edge detection methods.
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)
4 views6 pages

DIP_Experiments_1_to_6_with_Code_and_Outputs

The document outlines various image processing experiments, including arithmetic operations (addition, subtraction, multiplication, division), geometric transformations (rotation, scaling, translation), Fourier transforms (1D and 2D FFT), contrast adjustments (stretching, histogram equalization), and smoothing filters (mean, median). Each experiment includes code snippets and expected output descriptions. Additionally, it covers sharpening techniques and edge detection methods.
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/ 6

Experiment 1A: Arithmetic Operations

1. Image Addition

Code:

I1 = imread("image1.jpg");

I2 = imread("image2.jpg");

I1 = rgb2gray(I1);

I2 = rgb2gray(I2);

I_sum = I1 + I2;

imshow(I_sum);

Output: Brighter image or blended version of two images.

2. Image Subtraction

Code:

I_diff = I1 - I2;

imshow(I_diff);

Output: Highlights differences (motion/changes) between two images.

3. Image Multiplication

Code:

I_mul = I1 * 1.5;

imshow(I_mul);

Output: Brightens or enhances contrast.

4. Image Division
Code:

I_div = I1 / 2;

imshow(I_div);

Output: Darkens or normalizes the image.

Experiment 1: Geometric Transformations


1. Rotation

Code:

angle = 45;

rotated_img = imrotate(img, angle, "bilinear");

imshow(rotated_img);

Output: Image rotated 45 degrees.

2. Scaling

Code:

scale_factor = 1.5;

scaled_img = imresize(img, scale_factor, "bilinear");

imshow(scaled_img);

Output: Enlarged image.

3. Translation

Code:

translation_matrix = [1, 0, 50; 0, 1, 30; 0, 0, 1];

translated_img = imtransform(img, translation_matrix, 'affine');

imshow(translated_img);
Output: Image moved 50px right and 30px down.

Experiment 2: FFT (Fourier Transform)


1. 1D FFT

Code:

row = gray_img(100, :);

fft_row = fft(row);

fft_shifted = fftshift(fft_row);

plot(abs(fft_shifted));

Output: Frequency plot of one image row.

2. 2D FFT

Code:

fft_img = fft2(gray_img);

fft_shifted = fftshift(fft_img);

magnitude_spectrum = log(1 + abs(fft_shifted));

imshow(magnitude_spectrum);

Output: Spectrum showing frequencies in image.

3. Masking with Low-Pass Filter

Code: Circular mask applied, then inverse FFT.

Output: Blurred image with low-frequency details only.

Experiment 3: Contrast, Histogram, Bit Planes


1. Contrast Stretching

Code:
stretched_img = (img - min(img(:))) * (255 / (max(img(:)) - min(img(:))));

Output: Expanded brightness range, improved clarity.

2. Histogram

Code:

histplot(256, img(:));

Output: Graph showing brightness distribution.

3. Histogram Equalization

Code:

equalized_img = histeq(uint8(img));

Output: Balanced brightness across image.

4. Bit Plane Slicing

Code:

for i = 0:7

bit_plane = bitand(uint8(img), 2^i);

imshow(bit_plane * 255);

end

Output: Shows contribution of each bit layer (0 to 7).

Experiment 4: Mean, Std Dev, Correlation


Code:

mean_val = mean(gray_img(:));
std_val = stdev(gray_img(:));

correlation_matrix = corr([R(:), G(:), B(:)]);

Output:

- Mean: Brightness level

- Std Dev: Contrast range

- Correlation: Color channel similarity

Experiment 5: Smoothing Filters


1. Mean Filter

Code:

g1 = fspecial('average', [3 3]);

b1 = imfilter(g, g1);

Output: Slightly blurred image.

2. Median Filter

Code:

J = imnoise(K, 'salt & pepper', 0.05);

f = medfilt2(J, [3, 3]);

Output: Cleaned salt-and-pepper noise.

3. Convolution Filter

Code:

a = [0.001 0.001 0.001; 0.001 0.001 0.001; 0.001 0.001 0.001];

R = conv2(a, I);
Output: Custom smoothed image.

Experiment 6: Sharpening & Edge Detection


1. Laplacian Sharpening

Code:

f = fspecial('laplacian', 0.05);

im = imfilter(g, f);

Output: Enhanced edges and details.

2. Edge Detection

Code:

s = edge(g, 'sobel');

p = edge(g, 'prewitt');

r = edge(g, 'roberts');

Output: Sobel, Prewitt, and Roberts edge outlines.

3. Sobel Horizontal/Vertical

Code:

edge(g, 'sobel', [], 'horizontal');

edge(g, 'sobel', [], 'vertical');

Output: Directional edge detection.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy