0% found this document useful (0 votes)
7 views5 pages

Dip Assignment 1

Uploaded by

Namratha Nagaraj
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)
7 views5 pages

Dip Assignment 1

Uploaded by

Namratha Nagaraj
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/ 5

Question 1) Take your own photo of size 1024x1024 of jpg format.

1. Convert into gray scale image.


2. Plot histogram.
3. Add noise(Salt Pepper Noise,Guassian) separately to the original image.
4. Reconstruct the image.
5. Polt histogram .
6. Perform histogram equalization on gray scale image.
7. Reconstruct image and Calculate MSE and PSNR between step1 and step4 ,step1 and
step7.

Code
input_image = imread('Namratha_Image.jpg');
figure, imshow(input_image), title('Original Image');
resized_image = imresize(input_image, [1024 1024]);
figure, imshow(resized_image), title('Resized Image (1024 × 1024)');
if size(resized_image, 3) == 3
grayscale_image = rgb2gray(resized_image);
else
grayscale_image = resized_image; % If already grayscale
end
figure, imshow(grayscale_image), title('Grayscale Image');
figure, imhist(grayscale_image);
title('Histogram of Grayscale Image');
noisy_image = imnoise(grayscale_image, 'salt & pepper', 0.02);
figure, imshow(noisy_image), title('Noisy Image (Salt & Pepper)');
denoised_image = medfilt2(noisy_image, [3 3]);
figure, imhist(rgb2gray(denoised_image));
title('Histogram of Denoised Image');
MSE_original_noisy = immse(double(grayscale_image), double(noisy_image));
MSE_original_denoised = immse(double(grayscale_image), double(denoised_image));
PSNR_original_noisy = psnr(noisy_image, grayscale_image);
PSNR_original_denoised = psnr(denoised_image, grayscale_image);
equalized_image = histeq(grayscale_image);
figure, imshow(equalized_image), title('Histogram Equalized Image');
MSE_original_equalized = immse(double(grayscale_image), double(equalized_image));
PSNR_original_equalized = psnr(equalized_image, grayscale_image);
fprintf('MSE (Original vs Noisy): %.2f\n', MSE_original_noisy);
fprintf('MSE (Original vs Denoised): %.2f\n', MSE_original_denoised);
fprintf('MSE (Original vs Equalized): %.2f\n', MSE_original_equalized);
fprintf('PSNR (Original vs Noisy): %.2f dB\n', PSNR_original_noisy);
fprintf('PSNR (Original vs Denoised): %.2f dB\n', PSNR_original_denoised);
fprintf('PSNR (Original vs Equalized): %.2f dB\n', PSNR_original_equalized);
imwrite(noisy_image, 'Noisy_Image.jpg');
imwrite(denoised_image, 'Denoised_Image.jpg');
imwrite(equalized_image, 'Equalized_Image.jpg');

1
Output

2
MSE(Original vs Noisy): 508.49
MSE(Original vs Denoised): 3.15
MSE(Original vs Equalized):
6924.15
PSNR (Original vs Noisy): 21.07 dB
PSNR (Original vs Denoised): 43.15 dB

3
Question 2) Perform image scaling in your original image for the size
170x170 and 256x256 and repeat the above steps for the (.tiff format).

% Read the input image


image = imread("C:\Users\Namratha Nagaraj\Downloads\Namratha_Image.jpeg"); % Replace
with your image path

% Resize the image to two different dimensions


resized_image_up = imresize(image, [256 256]);
resized_image_down = imresize(image, [170 170]);

% Display the original and resized images


figure;
subplot(1, 3, 1), imshow(image), title('Original Image');
subplot(1, 3, 2), imshow(resized_image_down), title('Resized to 170x170');
subplot(1, 3, 3), imshow(resized_image_up), title('Resized to 256x256');

% Save the resized images


imwrite(resized_image_up, 'resized_256x256.jpg');
imwrite(resized_image_down, 'resized_170x170.jpg');

Output:

4
Code for (.Tiff) Format

% Specify the path to your original image


image_path = "C:\Users\Namratha Nagaraj\Downloads\Namratha_Image.jpeg";

% Read the original image


originalImage = imread(image_path);

% Resize the original image to two different dimensions


resized_170x170 = imresize(originalImage, [170 170]);

resized_256x256 = imresize(originalImage, [256 256]);

% Save the images in TIFF format


imwrite(originalImage, 'original_image.tiff'); % Save the original image as TIFF
imwrite(resized_170x170, 'resized_170x170.tiff'); % Save the 170×170 image as TIFF
imwrite(resized_256x256, 'resized_256x256.tiff'); % Save the 256×256 image as TIFF

% Display a message indicating that the images have been saved


disp('Original and resized images have been saved as TIFF format.');

% Display the original and resized images in a figure


figure;
subplot(1, 3, 1); imshow(originalImage); title('Original Image');
subplot(1, 3, 2); imshow(resized_170x170); title('Resized 170×170');
subplot(1, 3, 3); imshow(resized_256x256); title('Resized 256×256');

Output:

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