Documente Academic
Documente Profesional
Documente Cultură
>> zeros(3)
ans =
0
>> ones(3)
ans =
1
>> eye(3)
ans =
1
>> ones(3)*2
ans =
2
>> a = [1 2 3]
a=
1
>> b = [1,2,3]
b=
1
>> c = [1;2;3]
c=
1
2
3
>> d = [1 2;3 4]
d=
1
>> magic(3)
ans =
8
>> pascal(3)
ans =
1
>> rand(3,4)
ans =
0.9501
0.4860
0.4565
0.4447
0.2311 0.8913
0.0185
0.6154
0.6068
0.8214
0.7919
0.7621
>> randint(3)
ans =
1
0.2877
1.1892
0.1746
1.1909
0.3273
>> A = [1 2 3;4 5 6; 7 8 9]
A=
1
>> B = size(A)
0.7258
B=
3
>> C = length(A)
C=
3
13
14
15
16
17
18
19
>> B = sum(A)
B=
42
45
48
>> C = sum(B)
C=
135
>> D = diag(A)
D=
11
15
19
>> F = det(A)
F=
0
>> G = norm(A)
G=
45.6601
>> H = inv(A)
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.387779e-017.
H=
1.0e+014 *
1.8765 -3.7530
-3.7530
7.5060 -3.7530
1.8765 -3.7530
>> J = A'
J=
11 14
17
12
15
18
13
16
19
>> K = A/2
K=
1.8765
1.8765
5.5000
6.0000
6.5000
7.0000
7.5000
8.0000
8.5000
9.0000
9.5000
>> L = mod(A,4)
L=
3
%%%%%%%%%Matrix Indexing%%%%%%%%%
>> A = [1 2 3;4 5 6; 7 8 9]
A=
1
>> A(3, 2)
ans =
8
>> A(end,end-2)
ans =
7
>> A(1,:)
ans =
1
>> A(2,:)
ans =
4
>> A(:,1)
ans =
1
4
7
>> A(:,3)
ans =
3
6
9
>> A(:,:,:)
ans =
1
>> A(:,2,:)
ans =
2
5
8
>> A(1,:,:)
ans =
>> A(1,2,:)
ans =
2
>> A(0+[1 2],1+[1 2])
ans =
2
Day 2
%%%%%%%%%------Image Processing------%%%%%%%%%%%
X=imread(Path);
imshow(X);
OUTPUT:
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(J)
OUTPUT:
OUTPUT:
OUTPUT:
5000
4000
3000
2000
1000
0
0
50
100
150
200
%Entropy
%Entropy is used to characterize the texture of the input image.
I = imread('circuit.tif');
J = entropy(I)
OUTPUT:
J = 6.9439
250
4000
3500
3000
2500
2000
1500
1000
500
0
0
50
100
150
200
250
OUTPUT:
b=a(:,:,1);
subplot(2,2,2),imshow(b);title('r component image');
c=a(:,:,2);
subplot (2,2,3),imshow(c);title('g component image');
d=a(:,:,3);
subplot(2,2,4),imshow(d);title('b component image');
rgb image
r component image
g component image
b component image
2)
a=imread('peppers.png');
subplot(2,2,1),imshow(a);title('rgb image');
b=rgb2gray(a);
d=im2bw(a);
subplot(2,2,4),imshow(d);title('binary image');
e=rgb2ntsc(a);figure,
subplot(2,2,1),imshow(e);title('national television systems commitee
image');
rgb image
indexed image
binary image
f=ind2gray(a,map);figure,
subplot(2,2,2),imshow(f);title('gray scale image');
original image
a=imread('peppers.png');
subplot(2,2,1),imshow(a);title('rgb image');
b=rgb2ycbcr(a);
subplot(2,2,2),imshow(b);title('ycbcr image ');
c= ycbcr2rgb(b);
subplot(2,2,3),imshow(c);title('rgb image');
rgb image
ycbcr image
indexed image
OUTPUT:
% Crop an image
clc;
close all;
clear all;
I = imread('circuit.tif');
I2 = imcrop(I,[75 68 130 112]);
imview(I), imview(I2)
OUTPUT:
IMAGE TRANSFORMS
Image transforms
Fourier transform
a=imread('peppers.png');
subplot(2,2,1),imshow(a);title('original image');
b=fft(a);
subplot(2,2,2),imshow(b);title('transformed image');
c=ifft(b);
subplot(2,2,3),imshow(c,[]);title('restored image');
original image
transformed image
restored image
DAY 3
Image enhancement
imshow(I);
figure, imshow(J);
OUTPUT:
% Filter the noisy image with an averaging filter and display the
results.
I = imread('eight.tif');
imshow(I)
J = imnoise(I,'salt & pepper',0.02);
figure, imshow(J)
K = filter2(fspecial('average',3),J)/255;
figure, imshow(K)
OUTPUT:
% Median filters to filter the noisy image and display the results.
I = imread('eight.tif');
imshow(I)
J = imnoise(I,'salt & pepper',0.02);
figure, imshow(J)
L = medfilt2(J,[3 3]);
figure, imshow(L)
OUTPUT:
OUTPUT:
Original Image
Filtered Image
% Blurred image.
I = imread('cameraman.tif');
subplot(2,2,1);
imshow(I); title('Original Image');
H = fspecial('motion',20,45);
MotinBlur = imfilter(I,H,'replicate');
subplot(2,2,2);
imshow(MotionBlur); title('Motion Blurred Image');
H = fspecial('disk',10);
blurred = imfilter(I,H,'replicate');
subplot(2,2,3);
imshow(blurred); title('Blurred Image');
H = fspecial('Unsharp');
sharpeneded = imfilter(I,H,'replicate');
subplot(2,2,4);
imshow(sharpened); title('Sharpened Image');
OUTPUT:
Original Image
Blurred Image
Sharpened Image
DAY 4
Image
restoration
I = imread('peppers.png');
I = I(10+[1:256],222+[1:256],:);
figure;imshow(I);title('Original Image');
LEN = 31;
THETA = 11;
PSF = fspecial('motion',LEN,THETA);
Blurred = imfilter(I,PSF,'circular','conv');
figure; imshow(Blurred);title('Blurred Image');
OUTPUT:
Original Image
Blurred Image
I = I(10+[1:256],222+[1:256],:);
figure;imshow(I);title('Original Image');
LEN = 31;
THETA = 11;
PSF = fspecial('motion',LEN,THETA);
Blurred = imfilter(I,PSF,'circular','conv');
figure; imshow(Blurred);title('Blurred Image');
wnr1 = deconvwnr(Blurred,PSF);
figure;imshow(wnr1);
title('Restored, True PSF');
OUTPUT:
Original Image
Blurred Image
Original Image
Restored Image
Restoration algorithms
% deblurring with the lucy richardson filter
I = imread('football.jpg');
subplot(2,2,1),imshow(I);title('Original Image');
PSF = fspecial('gaussian',5,5);
% Create a simulated blur in the image and add noise.
Blurred = imfilter(I,PSF,'circular','conv');
V = .02;
BlurredNoisy = imnoise(Blurred,'gaussian',0,V);
subplot(2,2,2),imshow(BlurredNoisy);title('Blurred and Noisy ');
luc1 = deconvlucy(BlurredNoisy,PSF,5);
subplot(2,2,3); imshow(luc1);
title('Restored Image');
Original Image
Restored Image
DAY 5
COMPRESSIO
N
%%%%%%%%%%%%%%%%day 5 %%%%%%%%%%
Compression
a = im2double(imread('cameraman.tif'));
imshow(a);title('original image');
v = dctmtx(size(a,1));
dct = v*a*v';
dct image
I = imread('coins.png');
imshow(I);title('original image');
I = im2double(I);
T = dctmtx(8);
B = blkproc(I,[8 8],'P1*x*P2',T,T');
mask = [1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
B2 = blkproc(B,[8 8],'P1.*x',mask);
I2 = blkproc(B2,[8 8],'P1*x*P2',T',T);
imshow(I), figure, imshow(I2);title('dct compressed image');
OUTPUT:
Wavelets
a=imread('cameraman.tif');
subplot(3,2,1),imshow(a);title('original image');
[ca,ch,cv,cd]=dwt2(a,'haar');
subplot(3,2,2),imshow(mat2gray(ca));title('approximation coefficents
image');
subplot(3,2,3),imshow(ch);title('horizontal coefficients image');
subplot(3,2,4),imshow(cv);title('vertical coefficients image');
subplot(3,2,5),imshow(cd);title('diagnol coefficients image');
c=idwt2(ca,ch,cv,cd,'haar');
subplot(3,2,6),imshow(mat2gray(c));title('reconstructed image');
original image
reconstructed image
DAY 6
%%%%%%%%%%day 6 %%%%%%%%%%
segmentation
% Edge-detection method that edge provides is the Sobel and Canny
method
I = imread('coins.png');
imshow(I)
BW1 = edge(I,'sobel');
BW2 = edge(I,'canny');
imshow(BW1);
figure, imshow(BW2);
OUTPUT:
BW2 = edge(z,'canny');
imshow(BW1);title('prewitt image');
figure, imshow(BW2);title('canny image');
OUTPUT:
prewitt image
Segmentation
% applying the watershed transform
a=imread('football.jpg');
imshow(a);title('original image');
b=watershed(a);
figure,imshow(b);title('transformed image');
canny image
original image
transformed image
%SKELETONIZATION
%To reduce all objects in an image to lines, without changing the essential
structure of the image is known as skeletonization.
BW1 = imread('circbw.tif');
BW2 = bwmorph(BW1,'skel',Inf);
imshow(BW1);
figure, imshow(BW2)
OUTPUT:
OUTPUT:
%Edgetapering
original = imread('cameraman.tif');
PSF = fspecial('gaussian',60,10);
edgesTapered = edgetaper(original,PSF);
figure, imshow(original,[]);
figure, imshow(edgesTapered,[]);
OUTPUT: