Skip to content

Image Compression Error Free

Aim:- Image Compression Error Free
MSc Computer Science Image Processing Practical No. 5
Index of all Practicals ~ Click Here

Code:- Image_comp_error_free.m

clc;clear all;close all;

infile = ‘car.jpg’;     % 3D Image

if (exist(infile)==2)
   a = imread(infile);
   subplot(1,2,1);
   imshow(a);
   title(‘Input image’);
else
   warndlg(‘The file does not exist.’,’ Warning ‘);
   im=[];
   return
end

singvals = 20;
%if isrgb(a) 
   
    if isa(a(:,:,1),’uint8′)
        red = double(a(:,:,1));
        green = double(a(:,:,2));
        blue = double(a(:,:,3));      % For 3D Image
       
% S = SVDS(A,K) computes the K largest singular values of A.
        [u,s,v] = svds(red, singvals);
        imred = uint8(u * s * transpose(v));
       
        [u,s,v] = svds(green, singvals);
        imgreen = uint8(u * s * transpose(v));
       
        [u,s,v] = svds(blue, singvals);        % For 3D Image
        imblue = uint8(u * s * transpose(v));  % For 3D Image

       

        im1(:,:,1) = imred;
        im1(:,:,2) = imgreen;
        im1(:,:,3) = imblue;                  % For 3D Image
       
        %imwrite(im, outfile);
        %figure(‘Name’,’Output image’);
        Image1 = a;
        Image2 = im1;
       
        save(‘c:Image1.jpg’);
        save(‘c:Image2.jpg’,’im1′);
       
        subplot(1,2,2);
        imshow(im1);
        title(‘Compressed Image’);
    end

Output:-

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!