Вы находитесь на странице: 1из 15

1.

Program to find D4, D8 & Euclidean distance


%To find D4,D8 & euclidean distance X=imread('C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\sunrise.jpg'); figure,imshow(X); [x,y]=ginput(2) k=x(1)-y(1);l=x(2)-y(2); D4=abs(k)+abs(l) D8=max(abs(k),abs(l)) DE=sqrt((k*k)+(l*l)) Input:

For X= 39 61 Y=33 79 Output: D4=24 D8=18 DE=18.9737

2. Program to get negative of an image


%TO get negative of an image clear all; X=imread('sunrise.jpg'); Y=imresize(X,[512 512]); figure; imshow(Y); Z=rgb2gray(Y); figure; imshow(Z); for i=1:512 for j=1:512 R(i,j)=255-Z(i,j); end end figure; imshow(R);

Output:

fig. (a)

fig.(b)

fig.(c)

fig.(a) Original image fig.(b) Gray scale image fig.(c) Negative of original image

3. To Perform histogram equalization of an image %To perform histogram equalization clear all; close all; X = imread('child.jpg'); Y=rgb2gray(X); figure(1); imshow(X), figure(2), imhist(Y); Z=histeq(Y), figure(3), imshow(Z), figure(4), imhist(Z); Results:

Original image

Histogram of image

Gray scale image

Histogram equalization of gray scale image

4. To read, display & rotate an image %Image to read,display & rotate image. x=imread('images.jpg') figure(1),imshow(x) y=rgb2gray(x) figure(2),imshow(y) m=imresize(y,0.2) figure(3),imshow(m) n=imrotate(y,120) figure(4),imshow(n) z=imnoise(y,'salt & pepper'); figure(5),imshow(z)

Results:

Fig(a) Original

Fig(b)Gray scale

Fig(c)Resized image

Fig(d)Rotated image

Fig(e)Noise added image

5. To change the contrast of an image


% To change the contrast of an image x=imread('face8.jpg'); y=rgb2gray(x); figure, imshow(y); z=int8(y); figure,imshow(z); Results:

Original image

Contrasted image

6.Stimulas background
%program to change background of square clc clear all; close all; x1(256,255)=0; x1(86:165,86:165)=0.7 I=mat2gray(x1) subplot(1,3,1); imshow(x1); x2(1:256,1:256)=0.3; x2(86:165,86:165)=0.7 I=mat2gray(x2) subplot(1,3,2); imshow(x2) x3(1:256,1:256)=0.9; x3(86:165,86:165)=0.7 I=mat2gray(x3) subplot(1,3,3); imshow(x3)

Result:

7. To show line sequence (horizontal & vertical)


clc; close all clear all x=zeros(64,64); x(:,32)=255; figure,mesh(x) figure,imshow(x) y=zeros(64,64); y(32,:)=255; figure,mesh(y) figure,imshow(y) Result:

8)To perform plot impulse


%To plot impulse clc; close all; clear all; x=zeros(64,64); x(32,32)=255; mesh(x) figure,imshow(uint8(x)) Result:

9. To perform low pass of an image


clc; close all; clear all; X=9^-1.*ones(3); F=fft2(X,512,512); S=fftshift(F); figure;mesh(abs(S)); I=imread('nature.jpg'); figure;imshow(I); Z=imfilter(I,X,'conv'); figure;imshow(Z) Result:

Fig(a) Original image

Fig(b) Lpf

Fig(c)resultant image

10. To perform high pass filter


clc; close all; clear all; P= [0 -1 0; -1 4 -1 ; 0 -1 0]; M=fft2(P,512,512); N=fftshift(M); figure,mesh(abs(N)); I=imread('nature.jpg'); figure;imshow(I); Z=imfilter(I,P,'conv'); figure;imshow(Z);

Result:

Fig(a)Original

Fig(b)HPF

Fig(c)resultant image

11. Bit plane slicing


%BIT PLANE SLICING Close all; N=imread ('D:\Program Files\MATLAB\ip\fractal.jpg'); figure(1); imshow(N) a=double (bitget (N, 1)); b=double (bitget (N, 2)); c=double (bitget (N, 3)); d=double (bitget (N, 4)); e=double (bitget (N, 5)); f=double (bitget (N, 6)); g=double (bitget (N, 7)); h=double (bitget (N, 8)); figure(2); Subplot (2, 2, 1), subimage (a); title ('BIT-PLANE 0'); Subplot (2, 2, 2), subimage (b); title ('BIT-PLANE 1'); Subplot (2, 2, 3), subimage (c); title ('BIT-PLANE 2'); Subplot (2, 2, 4), subimage (d); title ('BIT-PLANE 3'); figure(3); Subplot (2, 2, 1), subimage (e); title ('BIT-PLANE 4'); Subplot (2, 2, 2), subimage (f); title ('BIT-PLANE 5'); Subplot (2, 2, 3), subimage (g); title ('BIT-PLANE 6'); Subplot (2, 2, 4), subimage (h); title ('BIT-PLANE 7'); Result:

Original image

Result: Higher bit planes consists of more information

12. Median filtering


I = imread('x ray.jpg'); K = medfilt2(I); X=9^-1.*ones(3); Z=imfilter(I,X,'conv'); figure,imshow(I) figure,imshow(Z) figure,imshow(K) Result:

Fig(a)

fig(b)

fig(c)

Fig(a):-x ray image with salt & pepper noise Fig(b):-noise being removed with 3*3 mask filter Fig(c):-noise removed with 3*3 median filter

13. checker board effect


clear all; close all; a=imread('images.jpg'); b=rgb2gray(a); c=imresize(b,[100 100]); d=imresize(b,[50 50]); e=imresize(b,[25 25]); % d=imresize(c,[163 163]); subplot(311),imshow(c); subplot(312),imshow(d); subplot(313),imshow(e); Result:

Fig(a)

fig(b)

fig(c)

Вам также может понравиться