0% found this document useful (0 votes)
7 views

Image Compression Venkatesh

The document discusses compressing a medical image using discrete cosine transform (DCT) at different compression ratios. It performs DCT on the image, thresholds high-frequency coefficients, reconstructs the image, and calculates compression ratio and peak signal-to-noise ratio (PSNR) for each compression level.

Uploaded by

venkat011003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Image Compression Venkatesh

The document discusses compressing a medical image using discrete cosine transform (DCT) at different compression ratios. It performs DCT on the image, thresholds high-frequency coefficients, reconstructs the image, and calculates compression ratio and peak signal-to-noise ratio (PSNR) for each compression level.

Uploaded by

venkat011003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

EXPT NO :

DATE :
IMAGE COMPRESSION

AIM:
To compress the given medical image and calculate the compression ratio.

OBJECTIVES:

• To compress the given medical image using dct2 function for different
compression ratios
• To calculate the compression ratio for each compression level

THEORY:

Image compression methods are used to reduce the amount of data required to
represent a digital image.The basis of the reduction process is the removal of
redundant data.

In digital image compression, three basic data redundancies are


➢ coding redundancy,
➢ interpixel redundancy
➢ psychovisual redundancy.

Coding redundancy: If the gray levels of an image are coded in a way that uses
more code symbols than absolutely necessary to represent each gray level, that is, the
code fails to minimize, the resulting image is said to contain coding redundancy.

Interpixel redundancy: Correlations that results from the structural or geometric


relationships between the objects in the image leads to interpixel redundancy or
spatial redundancy or geometric redundancy or interframe redundancy

Psychovisual redundancy: Certain information simply has less relative importance


than other information in normal visual processing is said to be Psychovisual
redundant.

Unlike coding and interpixel redundancy, Psychovisual redundancy is associated with


real or quantifiable visual information. Its elimination is only possible only because
the information itself is not essential for normal visual processing.

Relative redundancy can be calculated by,


PROGRAM:

clc;
clear all;
close all;

% Read the image


img = imread("C:\Users\venka\Downloads\cranium_color.jpg");

% Convert the image to grayscale if it's in RGB


if size(img, 3) == 3
img = rgb2gray(img);
end

% Convert to double precision


img = double(img);

% Perform 2D Discrete Cosine Transform


dct_img1 = dct(img);
dct_img2 = dct(img);
dct_img3 = dct(img);

% Set a threshold to discard high-frequency DCT coefficients


compression_ratio1 = 0.01; % Adjust this value as needed
dct_img1(abs(dct_img1) < compression_ratio1 * max(abs(dct_img1(:)))) = 0;
compression_ratio2 = 0.1; % Adjust this value as needed
dct_img2(abs(dct_img2) < compression_ratio2 * max(abs(dct_img2(:)))) = 0;
compression_ratio3 = 1; % Adjust this value as needed
dct_img3(abs(dct_img3) < compression_ratio3 * max(abs(dct_img3(:)))) = 0;

% Reconstruct the image using inverse DCT


compressed_img1 = idct(dct_img1);
compressed_img2 = idct(dct_img2);
compressed_img3 = idct(dct_img3);

% Convert back to uint8 for display


compressed_img1 = uint8(compressed_img1);
compressed_img2 = uint8(compressed_img2);
compressed_img3 = uint8(compressed_img3);

% Calculate MSE and PSNR


mse1 = mean((img(:) - double(compressed_img1(:))).^2);
psnr1 = 10 * log10((255^2) / mse1);

mse2 = mean((img(:) - double(compressed_img2(:))).^2);


psnr2 = 10 * log10((255^2) / mse2);

mse3 = mean((img(:) - double(compressed_img3(:))).^2);


psnr3 = 10 * log10((255^2) / mse3);
% Display the original and compressed images
figure;
subplot(2, 2, 1);
imshow(uint8(img));
title('Original Image');
subplot(2, 2, 2);
imshow(compressed_img1);
title(['Compressed Image (PSNR = ', num2str(psnr1), ' dB)']);
subplot(2, 2, 3);
imshow(compressed_img2);
title(['Compressed Image (PSNR = ', num2str(psnr2), ' dB)']);
subplot(2, 2, 4);
imshow(compressed_img3);
title(['Compressed Image (PSNR = ', num2str(psnr3), ' dB)']);

% Calculate compression ratio


original_size = numel(img);
compressed_size1 = nnz(dct_img1);
compression_ratio1 = original_size / compressed_size1;

compressed_size2 = nnz(dct_img2);
compression_ratio2 = original_size / compressed_size2;

compressed_size3 = nnz(dct_img3);
compression_ratio3 = original_size / compressed_size3;

disp(['Compression Ratio 1: ', num2str(compression_ratio1)]);


disp(['Compression Ratio 2: ', num2str(compression_ratio2)]);
disp(['Compression Ratio 3: ', num2str(compression_ratio3)]);

disp(['MSE 1: ', num2str(mse1)]);


disp(['MSE 2: ', num2str(mse2)]);
disp(['MSE 3: ', num2str(mse3)]);

disp(['PSNR 1: ', num2str(psnr1)]);


disp(['PSNR 2: ', num2str(psnr2)]);
disp(['PSNR 3: ', num2str(psnr3)]);
OUTPUT:
INFERENCE:

• As the compression ratio increases, the amount of compression also increases.


• Lower compression ratio results in higher image quality but larger file size, while a
higher compression ratio sacrifices image quality for smaller file size.
• For 0.00001 it is compressed least, for 0.0001 it is moderately compressed and for 0.5
it is highly compressed.
• Compression Ratios: 16.3308, 427.2577,669940 respectively.
• MSE 1, 2 and 3 are calculated as 68.2205, 756.1105, 13075.6012 respectively.
• PSNR 1,2 and 3 are calculated as 29.7917, 19.345, 19.345 respectively.
RESULT :

Thus, Image compression is applied to the medical image and output is obtained.

You might also like