Dec 29, 2015

*Applied Lossy ans Lossless Image Compression on Matlab

*Spatial and Frequency Filter on Matlab

*Spatial and Frequency Filter on Matlab

Project Report on

Digital Image Processing

INDIAN INSTITUTE OF TECHNILOGY JODHPUR

Jodhpur 342001, INDIA

By AkarshRastogi

(UG201211003)

DIGITAL IMAGE PROCESSING

Digital image processing is the use of computer algorithms to

perform image processing on digital images. As a subcategory

or field of digital signal processing, digital image processing

has many advantages over analog image processing. It allows

a much wider range of algorithms to be applied to the input

data and can avoid problems such as the build-up of noise and

signal distortion during processing. Since images are defined

over two dimensions digital image processing may be

modeled in the form of multidimensional systems.

POINTS COVERED

Image Compression Lossy Image Compression

JPEG image compession

Lossless Image Compression

Image Enhancement Spatial Intensity Transformation

Frequency Filter

Image Restoration Noise Estimation and their effects

Weiner Filtering

Image Compression Image compression addresses the problem of reducing the amount of data

required to represent a digital image. Compression is achieved by the removal

of one or more of the three basic redundancies

Coding redundancy, which is present when less than optimal code

words are used

Interpixel redundancy, which results from correlations between the

pixels of an image

Psychovisual redundancy, which is due to data that is ignored by the

Human Visual System.

Image compression can belossy or lossless.

Lossy Compression are especially suitable for natural images such as

photographs in applications where minor (sometimes imperceptible) loss of

fidelity is acceptable to achieve a substantial reduction in bit rate.

Lossless Compression is preferred for archival purposes and often for

medical imaging, technical drawings, clip art or comics.

JPEG Image Compression JPEG is a commonly used method of lossy compression for digital images

It includesfollowing steps:

Construct nxnsubmatrices

Image is a two dimensional M x N matrices . It is very difficult for computer

to handle full image at once so the whole image is divided into

nxnsubimages.

Forward Transform

Each sub image is transformed through Discrete Cosine Transform.

Quantization

This is the main step behind compression. Also, this is the step where

major loss of data takes place. Quantization decreases the number of

different values.

Symbol Encoder

JPEG encodes through Hoffman Encoding which further compresses the

image. It finally outputs the compressed image.

Construct

nxnsubimage

s

Forward

Transform

Quantizer Symbol

encoder

Symbol

decoder

Inverse

transform

Merge

nxn images

Input

image

Compressed

image

Compressed

image Decompressed

image

Symbol Decoder

This is the first step while decoding the compressed image.

Inverse Transform

Then the inverse transform of the matrix is taken.

Merge nxnsubimages

Finally all the subimages are merged and the decompressed image is

obtained.

Matlab Code of JPEG %%%%%%%%%%%%%%%%%%image compression%%%%%%%%%%%%%%%%% %read original image original_image = imread ('IMG_5809.bmp'); %transform image to ycbcr format new_image= rgb2ycbcr(original_image); % seperating all 3 frames seperatly y_image=new_image(:,:,1); cb_image=new_image(:,:,2); cr_image=new_image(:,:,3); % changing image to small matrices cell_size= 8; repeat_height=floor(size(y_image,1)/cell_size); repeat_width=floor(size(y_image,2)/cell_size); repeat_height_mat = repmat(cell_size, [1 repeat_height]); repeat_width_mat = repmat(cell_size, [1 repeat_width]); y_subimg = mat2cell(y_image ,repeat_height_mat,repeat_width_mat); cb_subimg = mat2cell(cb_image ,repeat_height_mat,repeat_width_mat); cr_subimg = mat2cell(cr_image ,repeat_height_mat,repeat_width_mat); %discrete cosine transform fori=1:repeat_height for j=1:repeat_width y_subimg{i, j} = dct2(y_subimg{i, j});

cb_subimg{i, j} = dct2(cb_subimg{i, j}); cr_subimg{i, j} = dct2(cr_subimg{i, j}); end end %quantization quantization_factor = 16; fori=1:repeat_height for j=1:repeat_width y_subimg{i, j} = y_subimg{i, j} / quantization_factor; cb_subimg{i, j} = cb_subimg{i, j} / quantization_factor; cr_subimg{i, j} = cr_subimg{i, j} / quantization_factor; end end fori=1:repeat_height for j=1:repeat_width y_subimg{i, j}(:, 5:8) = 0; y_subimg{i, j}(5:8, :) = 0; cb_subimg{i, j}(:, 5:8) = 0; cb_subimg{i, j}(5:8, :) = 0; cr_subimg{i, j}(:, 5:8) = 0; cr_subimg{i, j}(5:8, :) = 0; end end y_compimg = uint8(cell2mat(y_subimg )) * quantization_factor; cb_compimg = uint8(cell2mat(cb_subimg)) * quantization_factor; cr_compimg = uint8(cell2mat(cr_subimg)) * quantization_factor; %to assign no of row comp_img=original_image; % now assign values to compressed image comp_img(:,:,1)=y_compimg; comp_img(:,:,2)=cb_compimg; comp_img(:,:,3)=cr_compimg; %%%%%%%%%%%%%%%%% image decompression %%%%%%%%%%%%%%%% %Dequanitzation fori=1:repeat_height for j=1:repeat_width y_subimg{i, j} = y_subimg{i, j} * quantization_factor; cb_subimg{i, j} = cb_subimg{i, j} * quantization_factor; cr_subimg{i, j} = cr_subimg{i, j} * quantization_factor; end end

%inverse dct fori=1:repeat_height for j=1:repeat_width y_subimg{i, j} = idct2(y_subimg{i, j}); cb_subimg{i, j} = idct2(cb_subimg{i, j}); cr_subimg{i, j} = idct2(cr_subimg{i, j}); end end %%Stich sub images into single image y_image = cell2mat(y_subimg); cb_image = cell2mat(cb_subimg); cr_image = cell2mat(cr_subimg); %%Convert to RGB space ycbcr_img(:, :, 1) = y_image; ycbcr_img(:, :, 2) = cb_image; ycbcr_img(:, :, 3) = cr_image; final_img = ycbcr2rgb(ycbcr_img); figure(1); imshow(original_img); figure(2); imshow(final_img);

Result of JPEG Compression

Uncompressed Image (51.2 Mb)

Compressed Image (36 Mb)

akkuTypewritten textData lost after decompression=

akkuTypewritten text15.2 Mb

Image Enhancement Quality of image can be enhanced through changes on the basis of histogram.

Spatial Intensity Transformation

Spatial domain techniques operate directly to the pixels of an image as

opposed, for example to the frequency domain where operations are

performed on the Fourier Transform of an image, rather than on image

itself.

Basic Transformation Program on Matlab

%% Basic Transformation on Matlab img=imread('IMG_5809.bmp'); %%Converting image to grayscale img=rgb2gray(img); %%Observing image and its histogram figure(1); imshow(img); figure(2); imhist(img); %%Histogram is towards right hand side hence colours are lighter new_img=img-50; %%new image and its histogram figure(3); imshow(new_img); figure(4); imhist(new_img); %%Equalising histogram newimage=histeq(img); figure(5); imshow(newimage); figure(6); imhist(newimage);

Result of spatial Transformation Initial image

Initial Histogram

Final Image

Final Histogram

After histogram equalization, image

After histogram equalization, histogram

Frequency Filter

Frequency filters process an image in the frequency domain. The image

is Fourier transformed, multiplied with the filter function and then re-

transformed into the spatial domain. Attenuating high frequencies results in a

smoother image in the spatial domain, attenuating low frequencies enhances the

edges.

All frequency filters can also be implemented in the spatial domain and, if there

exists a simple kernel for the desired filter effect, it is computationally less

expensive to perform the filtering in the spatial domain. Frequency filtering is

more appropriate if no straightforward kernel can be found in the spatial

domain, and may also be more efficient.

Matlab Code for basic Frequency Filter

I=imread('eight.tif'); J=imnoise(I,'gaussian',0,.01); [M,N]=size(J); u=0:M-1; v=0:N-1; idx= find(u>M/2); u(idx)=u(idx)-M; idy=find(v>N/2); v(idy)=v(idy)-N; [V,U]=meshgrid(v,u); K=fft2(J,M,N); D0=.05*2500; H=exp(-(U.^2 + V.^2)/(2*(D0^2))); G=(H).*(K); L=real(uint8(ifft2(G))); figure(1); imshow(J); figure(2); imshow(L);

Result of Low pass Frequency Filter

Initial image

Filtered image

Image Restoration The objective of image restoration is to improve image in some

predefined sense. Restoration attempts to recover or reconstruct an

image that has been degraded by using a priori knowledge of the

degradation phenomenon. Thus restoration techniques are oriented

toward modelling the degradation and applying the inverse process in

order to recover the original image.

Effect of noise on histogram

I=imread('eight.tif'); A=imnoise(I,'gaussian'); B=imnoise(I,'poisson'); C=imnoise(I,'salt& pepper',.5); D=imnoise(I,'speckle'); figure(1); imhist(I); figure(2); imhist(A); figure(3); imhist(B); figure(4); imhist(C); figure(5); imhist(D);

Original Histogram

Gaussian noise

Poisson noise

Speckle noise

Simple code of Weiner Filtering of a noised image

I=imread('saturn.png'); I=rgb2gray(I); J=imnoise(I,'gaussian',0,0.05); K=wiener2(J,[10,10]); H=fspecial('disk',10); blurred=imfilter(J,H,'replicate'); figure(1); imshow(I); figure(2); imshow(J); figure(3); imshow(K); figure(4); imshow(blurred);

Resu

Related Documents See more >