Image Processing LAB Manual

 


Exp:1 Median Filter in MATLAB to remove Salt & Pepper noise.

Code: first.m

clc; 

clear all;

 close all;

I=imread('image.jpg');

K = rgb2gray(I);

J= imnoise(K ,'salt & pepper',0.05);

f= medfilt2(J,[3,3]);

f1=medfilt2(J,[10,10]);

subplot(3,2,1); 

imshow(I);

title('Original Image');

subplot(3,2,2); 

imshow(K);

title('Gray Image');

subplot(3,2,3);

imshow(J); 

title('Noise added Image');

subplot(3,2,4); 

imshow(f);

title('3x3 Image');

subplot(3,2,5);

imshow(f1);

title('10x10 Image');

Output :-




Exp:2) MATLAB program for Deblur Images Using a Wiener Filter.

Code: second.m


clc;

clear all;

close all;

Ioriginal = imread('cameraman.jpg');

subplot(1,3,1);

imshow(Ioriginal);

title('Original Image');

PSF = fspecial('motion',21,11);

Idouble = im2double(Ioriginal);

blurred = imfilter(Idouble,PSF,'conv','circular');

subplot(1,3,2);

imshow(blurred);

title('Blurred Image'); 

wnr1 = deconvwnr(blurred,PSF);

subplot(1,3,3);

imshow(wnr1);

title('Restored Blurred Image');


output :-













Exp:3 MATLAB program for Image Negation.

Code : third.m


clc; 

clear all;

close all;

a = imread('bird.jpg');

subplot(1,2,1);

imshow(a);

title('bird'); 

b = 255-a;

subplot(1,2,2);

imshow(b);

title('Negation of bird');


Output :-


Exp:4 ) Edge Detection using Sobel, Prewitt and Roberts Operators.

Code : edge.m


clc;

clear all;

close all;

a = imread('rose.jpg');

b = rgb2gray(a);

subplot(2,2,1);

imshow(a);

title('Original Image');

c1 = edge(b,'sobel');

subplot(2,2,2);

imshow(c1);

title('Sobel Operator');

c2 = edge(b,'prewitt');

subplot(2,2,3);

imshow(c2);

title('Prewitt Operator');

c3 = edge(b,'roberts');

subplot(2,2,4);

imshow(c3);

title('Roberts Operator');


Output :-














Exp:5) ) MATLAB program for morphological operations on binary images. 

Code : binary.m

clc;

clear all;

close all;

a = imread ('image.jpg');

b = im2bw(a,0.4);

subplot(2,3,1);

imshow(b);

title('original binary image');

c = bwmorph(b,'remove'); % removes interior pixels to obtain outline

subplot(2,3,2);

imshow(c);

title('outline of original image');

d = bwmorph(b,'skel',Inf); % applies operation infinite times till image no longer changes

subplot(2,3,3);

imshow(d);

title('skeleton of original image');

se = strel('line',11,90); % create a 'line' structuring element

e = imdilate(b,se); % dilate image with a structuring element

subplot(2,3,4);

imshow(e),

title('dilation of original image');

f = imerode(b,se); % erode image with a structuring element

subplot(2,3,5);

imshow(f),

title('erosion of original image');

g = bwmorph(b,'bothat'); % performs morphological "bottom hat" operation

subplot(2,3,6);

imshow(g);

title('bottom hat operation on original image');


Output :- 







Exp:6)  Image Smoothening and Sharpening

Code : Smoothening.m


clc;

clear all;

close all;

a=imread('leena.jpg');

subplot(1,3,1);

imshow(a);

title('original image');

h = fspecial('gaussian');

b = imfilter(a,h); 

subplot(1,3,2);

imshow(b);

title('smoothened image');

c = imsharpen(a);

subplot(1,3,3);

imshow(c);

title('sharpened image');








Output :-














Exp:7)  MATLAB program for Scaling & Rotation Scaling (Resize).


I=imread('bird.jpg');

subplot(2,2,1); 

subimage(I); 

title('Original Image');

s=input('Enter Scaling Factor');

j=imresize(I,s);

subplot(2,2,2); 

subimage(j);

 title('Scaled Image');

K=imrotate(I,90);

subplot(2,2,3); 

imshow(K); 

title('Rotated Image 90deg');

R=imrotate(I,45);

subplot(2,2,4);

 imshow(R); 

title('Rotated Image 45deg');



output :-



















Exp:8)  MATLAB program for edge detection , Gray level Thresolding  in Image Segmentation .

%Gray level Thresolding

a=imread('bird.jpg');

level=graythresh(a);

c= im2bw(a,level);

subplot(1,2,1);

imshow(a);

title('original image');

subplot(1,2,2);

imshow(c);

title('threshold image');

%edge detection

a=imread('jump.jpg');

a=rgb2gray(a);

c=edge(a,'roberts');

d=edge(a,'sobel');

e=edge(a,'prewitt');

f=edge(a,'canny');

g=edge(a,'log');

subplot(2,3,1);

imshow(a); 

title('original image');

subplot(2,3,2);

imshow(c);

title('roberta image');

subplot(2,3,3);

imshow(d);

title('sobel image');

subplot(2,3,4);

imshow(e);

title('prewitt image');

subplot(2,3,5); 

imshow(f);

title('canny image');

subplot(2,3,6);

imshow(g);

title('log image');

output :-



Exp 9) Write a program on Discrete Cosine Transform.

// Java program to perform discrete cosine transform


import java.util.*;


class GFG

{

public static int n = 8,m = 8;

public static double pi = 3.142857;

// Function to find discrete cosine transform and print it

static strictfp void dctTransform(int matrix[][])

{

int i, j, k, l;


// dct will store the discrete cosine transform

double[][] dct = new double[m][n];


double ci, cj, dct1, sum;


for (i = 0; i < m; i++)

{

for (j = 0; j < n; j++)

{

// ci and cj depends on frequency as well as

// number of row and columns of specified matrix

if (i == 0)

ci = 1 / Math.sqrt(m);

else

ci = Math.sqrt(2) / Math.sqrt(m);

if (j == 0)

cj = 1 / Math.sqrt(n);

else

cj = Math.sqrt(2) / Math.sqrt(n);


// sum will temporarily store the sum of

// cosine signals

sum = 0;

for (k = 0; k < m; k++)

{

for (l = 0; l < n; l++)

{

dct1 = matrix[k][l] *

Math.cos((2 * k + 1) * i * pi / (2 * m)) *

Math.cos((2 * l + 1) * j * pi / (2 * n));

sum = sum + dct1;

}

}

dct[i][j] = ci * cj * sum;

}

}


for (i = 0; i < m; i++)

{

for (j = 0; j < n; j++)

System.out.printf("%f\t", dct[i][j]);

System.out.println();

}

}

// driver program

public static void main (String[] args)

{

int matrix[][] = { { 255, 255, 255, 255, 255, 255, 255, 255 },

{ 255, 255, 255, 255, 255, 255, 255, 255 },

{ 255, 255, 255, 255, 255, 255, 255, 255 },

{ 255, 255, 255, 255, 255, 255, 255, 255 },

{ 255, 255, 255, 255, 255, 255, 255, 255 },

{ 255, 255, 255, 255, 255, 255, 255, 255 },

{ 255, 255, 255, 255, 255, 255, 255, 255 },

{ 255, 255, 255, 255, 255, 255, 255, 255 } };

dctTransform(matrix);

}

}


Output :-










1 comment:

ads
Powered by Blogger.