Saturday, September 27, 2014

Image Processing -Matlab Tutorial 1

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.

Difference between Image Processing and Computer Vision




Introduction

An image may be defined as a two-dimensional function,{(x, y), where x and y are spatial (plane) coordinates, and the amplitude of f at any pair of coordinates (x, y) is allied the intensity or gray level of the image at that point When x,y, and the amplitude values of{are all finite, discrete quantities, we call the image a digital image.The field of digital image processing refers to processing of digital images by means of a digital computer. Note that a digital image is composed of a finite number of elements, each of which has a particular location and value. These elements are referred to as picture elements, image elements, pels, and pixels. Pixel is the term most widely used to denote the elements of a digital image.

An image is formed on a display using geometric and lighting properties. Once the image is acquired using an electronic device, it is digitized using various algorithms for storage. There are several formats in which an image can be saved as a set of pixels. 

Converting RGB images into gray scale images

Original Image
Matlab Code

[im1 map1]=imread('mechildcmp.jpg');
[im2 map2]=imread('myimagecmp.jpg')
imshow(im1)
figure, imshow(im2);
gray1=rgb2gray(im1);
gray2=rgb2gray(im2);
figure, imshow(gray1);
figure, imshow(gray2);
Gray scale image

Image Transformations

Point processing transformations

Negative Images

Matlab Code

[R1 C1]=size(gray1)
for i=1:R1
    for j=1:C1
        negative1(i,j)=255-gray1(i,j);      
    end 
end
figure,imshow(negative1)
i=0;j=0;
[R2 C2]=size(gray2)
for i=1:R2
    for j=1:C2
        negative2(i,j)=255-gray2(i,j);      
    end 
end
figure,imshow(negative2)


Negative Image
Contrast Stretching Images

Gray scale image and it's histogram
Matlab Code

%Load images
[im1 map1]=imread('mechildcmp.jpg');
%imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);
 
figure,imhist(gray1)
%contrast streching
im4=gray1
[R1 C1]=size(im4)
for i=1:R1
    for j=1:C1
        contrast1(i,j)=1.6*im4(i,j);
    end 
end
figure,imshow(contrast1)
figure,imhist(contrast1)

Contrast stretched image and it's histogram

Contrast Compress Images

Matlab Code

%Load images
[im1 map1]=imread('mechildcmp.jpg');
%imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);
 
figure,imhist(gray1)
%contrast compression
im4=gray1
[R1 C1]=size(im4)
for i=1:R1
    for j=1:C1
        contrast2(i,j)=0.6*im4(i,j);
    end 
end
figure,imshow(contrast2)
figure,imhist(contrast2)

Contrast compressed images and it's histogram

Threshold
Gray scale original image

Matlab Code

clear all
%Load images
[im1 map1]=imread('athauda.jpg');
imshow(im1)

figure,imhist(im1)
%thresholding for black and white
[im2 map1]=imread('mechildcmp.jpg');
gray1=rgb2gray(im2);
figure,imhist(gray1)
 level = graythresh(gray1);
 BW = im2bw(gray1,level);
 figure,imshow(BW)
 figure,imhist(BW)
 
%thresholding 100
[R1 C1]=size(im1)
for i=1:R1
    for j=1:C1
        if(im1(i,j)<100
        threshold1(i,j)=0;
        else
        threshold1(i,j)=im1(i,j);
        end
    end 
end
figure,imshow(threshold1); 
figure,imhist(threshold1);


Thresholded image

Intensity Level Slicing

Original image and it's histogram

Matlab Code

[im1 map1]=imread('athauda.jpg');
imshow(im1)
figure,imhist(im1)
[R1 C1]=size(im1)
for i=1:R1
    for j=1:C1
        if(im1(i,j)<=100)&& (im1(i,j)>=50)
        threshold1(i,j)=255;
        else
        threshold1(i,j)=im1(i,j);
        end
    end 
end
figure,imshow(threshold1)
figure,imhist(threshold1)

Sliced image and it's histogram


Logarithmic Transformation 

Matlab Code

clear all
%Load images
[im1 map1]=imread('athauda.jpg');
imshow(im1)
im2=im2double(im1)
%gray1=im1
%Point Processing Tranformations
 
figure,imhist(im1)
%logarithmetic Transformation
 
[R1 C1]=size(im2);
logarithamic1= 1*log(1+im2);
figure,imshow(logarithamic1);
figure,imhist(logarithamic1);

[R1 C1]=size(im2);
logarithamic2= 2*log(1+im2);
figure,imshow(logarithamic2);
figure,imhist(logarithamic2);
 
[R1 C1]=size(im2);
logarithamic3= 3.5*log(1+im2);
figure,imshow(logarithamic3);
figure,imhist(logarithamic3);

Logarithmic transformed image and it's histogram

Exponential Transformation

Matlab Code
clear all
%Load images
[im1 map1]=imread('athauda.jpg');
imshow(im1)
im2=im2double(im1)
%gray1=im1
%Point Processing Tranformations
 
figure,imhist(im1)
%exponential Transformation
 
[R1 C1]=size(im2);
expo1=0.1* exp(im2);
figure,imshow(expo1);
figure,imhist(expo1);
 
[R1 C1]=size(im2);
expo2=0.5* exp(im2);
figure,imshow(expo2);
figure,imhist(expo2);
 
[R1 C1]=size(im2);
expo3= 0.7*exp(im2);
figure,imshow(expo3);
figure,imhist(expo3);


Exponential transformed image and it's histogram


Histogram Equalization

Original gray scale image and its' histogram

Matlab Code

clear all
%Load images
[im1 map1]=imread('mechildcmp.jpg');
imshow(im1)
gray1=rgb2gray(im1);
%gray1=im1
%Point Processing Tranformations
 
figure,imhist(gray1);
hist1=histeq(gray1);
figure,imshow(gray1);
figure,imshow(hist1);
figure,imhist(hist1);

Histogram equalized image and it's histogram



2 comments: