0% found this document useful (0 votes)
40 views

For For End End: % Generating Ramp Image

The documents contain MATLAB code for performing various image processing tasks such as generating ramp and circle images, transposing, flipping, and taking histograms of images. Arithmetic operations like subtraction, addition, and multiplication are also demonstrated between two images. Noise is added to images using Gaussian and salt and pepper models and filtered using average and median filters.

Uploaded by

Sharath Mysore
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

For For End End: % Generating Ramp Image

The documents contain MATLAB code for performing various image processing tasks such as generating ramp and circle images, transposing, flipping, and taking histograms of images. Arithmetic operations like subtraction, addition, and multiplication are also demonstrated between two images. Noise is added to images using Gaussian and salt and pepper models and filtered using average and median filters.

Uploaded by

Sharath Mysore
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

clc;

% Generating ramp image:


a=0;
colormap(gray)
for m=1:100
for n=1:100
c(n,m)=a;
end
a=a+1;
end
x=c
image(x);
figure(1);
OUTPUT:

%Generating a circle generate image of circle


N = 256;
I =zeros(N,N);
r1= 80;
K=0;
for r=1:N
for c=1:N
if (r-N/2)^2 + (c-N/2)^2 < r1^2;
I(r,c)=K;
K=K+256/(256*r1);
end

end
end
figure();
imshow(I,[0 255])
OUTPUT:

% Transpose of an image:
load mandrill
X2=X';
figure()
image(X);
colormap(map)
figure()
image(X2)
colormap(map)

% Vertical flipping of an image:


I = imread('cameraman.tif');
imshow(I),figure
I3 = flipdim(I ,1);
%# vertical flip
imshow(I3)
output

% Histogram of image:
x=imread('coins.png');
imshow(x),figure;
hist(x(:),0:1:255)
output

% sample mean variance sd of image.question 6


clear all;
close all;
a=imread('F:\M.Tech doc\image processing\doll.jpg');
imshow(a);
[m,n]=size(a);
b=mean(a(:));
display('sample mean of the image ');
display (b);
for i=1:m
for j=1:n
mx(i,j)=(abs(a(i,j)-b))^2;
end
end
c=mean(mx(:));
sd=(c)^(1/2);
display('Standard Deviation of the Image');
display(sd);
variance=sd^2;
display('Variance of the Image');
display(variance);

sample mean of the image


b = 196.8172
Standard Deviation of the Image
sd = 12.5145
Variance of the Image
variance =156.6138

% Gray and binary scaling of image:


figure(7);
g4=imread('board.tif');
subplot(3,1,1);
imshow(g4);
title('Given image');
g3=rgb2gray(g4);
subplot(3,1,2);
imshow(g3);
title('Gray scaled image');
g5=dither(g3);
subplot(3,1,3);
imshow(g5);
title('Binary image');
output:

% Gray level reduction:


I=imread('tire.tif')
figure()
subplot(2,2,1),imshow(I),title('original image');
i2=round(I/.2)
subplot(2,2,2),imshow(i2),title('fig of 128 gray levels');
i3=round(I/.4);
subplot(2,2,3);
imshow(i3),title('fig of 64 gray level');
i4=round(I/.8);
subplot(2,2,4);
imshow(i3),title('fig of 32 gray levels');

output:

% Arithmatic operations:
v1=imread('ddd.jpg');
v2=imread('aaa.jpg');
v3=imabsdiff(v1,v2);
figure(9);
subplot(3,3,1);
imshow(v1);title('First image');
subplot(3,3,2);
imshow(v2);title('Second image');
subplot(3,3,3);
imshow(v3);title('Absolute subtraction');
v4=imadd(v1,v2);
subplot(3,3,4);
imshow(v4);title('Addition');
v5=imcomplement(v1);
subplot(3,3,5);
imshow(v5);title('Complement of first image');
v6=imdivide(v1,v2);
subplot(3,3,6);
imshow(v6);title('Division: First/Second');
v7=imlincomb(3,v1,2,v2);
subplot(3,3,7);
imshow(v7);title('Linear combination');
v8=immultiply(v1,v2);
subplot(3,3,8);
imshow(v8);title('Multiplication');
v9=imsubtract(v1,v2);
subplot(3,3,9);
imshow(v9);title('Subtraction of First and Second');

output:

% Histogram equalisation;
I = imread('tire.tif');
J = histeq(I);
subplot(2,2,1),imshow(I)
subplot(2,2,2), imshow(J)
subplot(2,2,3); imhist(I,125)
subplot(2,2,4); imhist(J,125)
output:

%12.Enhancement using Spatial filteringclc;


clear;
x=imread('tire.tif');
[m n]=size(x);
% --------filter coeff.-----------%
f1=[1 1 1;1 1 1;1 1 1];
f2=[1 0 -1;1 0 -1;1 0 -1];
f3=[1 1 1;0 0 0;-1 -1 -1];
% -------filtering-----------%
x1=x(1:m,1:n);
y1=conv2(double(x1),double(f1));
y2=conv2(double(x1),double(f2));
y3=conv2(double(x1),double(f3));
figure()
subplot(2,2,1);imshow(x);title('IMAGE ')
subplot(2,2,2);imshow(uint8((y1)));title('f1- IMAGE ')
subplot(2,2,3);imshow(uint8((y2)));title('f2- IMAGE ')
subplot(2,2,4);imshow(uint8((y3)));title('f3-IMAGE ')
output:

Gaussian noise:
figure(11);
l1=imread('ddd.jpg');
l1=rgb2gray(l1);
subplot(3,3,1);
imshow(l1);title('Original image');
l3=imnoise(l1,'gaussian',0,0.01);
subplot(3,3,2);
imshow(l3);title('m=0, v=0.01');
la3=filter2(fspecial('average',3),l3)/255;
subplot(3,3,3);
imshow(la3);title('Average filtered');

l4=imnoise(l1,'gaussian',0,0.02);
subplot(3,3,4);
imshow(l4);title('m=0, v=0.02');
la4=filter2(fspecial('average',3),l4)/255;
subplot(3,3,5);
imshow(la4);title('Average filtered');
l5=imnoise(l1,'gaussian',0,0.05);
subplot(3,3,6);
imshow(l5);title('m=0, v=0.05');
la5=filter2(fspecial('average',3),l5)/255;
subplot(3,3,7);
imshow(la5);title('Average filtered');
l6=imnoise(l1,'gaussian',0,0.1);
subplot(3,3,8);
imshow(l6);title('m=0, v=0.1');
la6=filter2(fspecial('average',3),l6)/255;
subplot(3,3,9);
imshow(la6);title('Average filtered');

%adding salt n papper noise and filtered it by median and average filter
I = imread('eight.tif');
J = imnoise(I,'salt & pepper',0.05);
K = filter2(fspecial('average',3),J)/255;
L = medfilt2(J,[3 3]);
subplot(2,2,1), imshow(I),title('original image');
subplot(2,2,2), imshow(J),title('adding salt and papper');
subplot(2,2,3), imshow(K),title('averaging filter');
subplot(2,2,4), imshow(L),title('median filter');

output:

You might also like