Write a MatLab program that takes as an input an RGB image and compress it into
ID: 2081988 • Letter: W
Question
Write a MatLab program that takes as an input an RGB image and compress it into the JPEG format and then store it on the hard disk. The JPEG file should be openable by any program that reads JPEG images such as windows. Your code should dearly show all the compression stages; the image is firstly converted to DCT, quantized using thresholding (method three in the lectures), Zigzag scanned and then Huffman coded. If your resulting image cannot for any reason be opened by any program that reads JPEG images, then it is your duty to write a program the can decode the compressed image and restore the original image. You should submit a hardcopy and softcopy of a report that includes the following Typed or printed neatly. It includes: Project title Course number Students names Date due Date handed in One page (max). This section should include the techniques used and the principal equations (if any) implemented. Includes listings of all programs written by the student. Standard routines and other material obtained from other sources should be acknowledged by name, but their listings should not be included. Shows the original image together with the results. A discussion of results should include major findings in terms of the project objectives, and make clear reference to any images generated. Results. Includes all the images generated in the project. NumberExplanation / Answer
clc;
close all;
clear all;
[IMG1,map] = imread('lenna.jpg');
figure
imshow(IMG1);
title('IMAGE');
im = rgb2gray(IMG1);
figure
imshow(im);
title('RGB IMAGE');
img_dct = dct2(im);
figure
imshow(img_dct);
title('RGB IMAGE');
%change this as needed
desired_bit_depth = 2;
my_pixel_depth = 2 ^ desired_bit_depth;
%converts grayscale to an indexed image at the appropriate depth
%quant_A = imquantize(im,my_pixel_depth)
[ind_im, reduced_colormap ] = gray2ind(img_dct, my_pixel_depth);
figure
imshow(ind_im);
title('GRAYSCALE');
out_in = zigzag(ind_im);
figure
imshow(out_in);
title('ZIGZAG');
symbols = [1:length(out_in)]; % Alphabet vector
prob = (1/length(out_in))*ones(1,length(out_in)); % Symbol probability vector
[dict,avglen] = huffmandict(symbols,prob) ;
IMG_HUFF = huffmanenco(out_in,dict);
figure
imshow(IMG_HUFF);
title('HUFFMAN ENCODED');
saveas(IMG_HUFF,'IMG_JPG.jpg');
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.