Académique Documents
Professionnel Documents
Culture Documents
>> a = [1 2 3] a= 1 2 3
>> b = [1,2,3] b= 1 2 3
>> c = [1;2;3] c= 1 2 3
>> d = [1 2;3 4]
d= 1 3 2 4
>> rand(3,4) ans = 0.9501 0.2311 0.6068 0.4860 0.8913 0.7621 0.4565 0.0185 0.8214 0.4447 0.6154 0.7919
1 0
1 1
1 0
>> randn(3,4)%%Displays +ve and -ve values ans = -0.4326 0.2877 1.1892 0.1746
>> A = [1 2 3;4 5 6; 7 8 9] A= 1 4 7 2 5 8 3 6 9
>> B = size(A) B=
>> C = length(A) C= 3
>> B = sum(A) B= 42 45 48
>> D = diag(A) D= 11 15 19
18
>> 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 1.8765
1.8765 -3.7530
>> J = A' J= 11 12 13 14 15 16 17 18 19
>> K = A/2 K= 5.5000 7.0000 8.5000 6.0000 7.5000 9.0000 6.5000 8.0000 9.5000
>> L = mod(A,4) L= 3 2 1 0 3 2 1 0 3
%%%%%%%%%Matrix Indexing%%%%%%%%%
>> A = [1 2 3;4 5 6; 7 8 9] A= 1 4 7 2 5 8 3 6 9
3 6 9
ans = 1 2 3
Day 2
%%%%%%%%%------Image Processing------%%%%%%%%%%%
X=imread(Path); imshow(X);
OUTPUT:
% Scale an image by a constant factor: I = imread('moon.tif'); J = immultiply(I,0.5); subplot(1,2,1), imshow(I) subplot(1,2,2), imshow(J) OUTPUT:
% Divide by a constant of the rice image. I = imread('rice.png'); J = imdivide(I,2); subplot(1,2,1), imshow(I) subplot(1,2,2), imshow(J)
OUTPUT:
500 0
400 0
300 0
200 0
100 0
0 0 50 100 1 50 20 0 250
%Entropy
%Entropy is used to characterize the texture of the input image. I = imread('circuit.tif'); J = entropy(I) OUTPUT: J= 6.9439
%A high-contrast image with its histogram. I = imread('cameraman.tif'); figure; imshow(I); imhist(I,64); OUTPUT:
4000 3500 3000 2500 2000 1500 1000 500 0 0 50 100 150 200 250
%Add two images together and specifies an output class. I = imread('rice.png'); J = imread('cameraman.tif'); K = imadd(I,J,'uint16'); imshow(K,[])
OUTPUT:
% To display the r, g, b components of an color image a=imread('football.jpg'); subplot(2,2,1),imshow(a);title('rgb image'); 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
subplot(2,2,3),imshow(c);title('indexed image');
rgb image
indexed image
binary image
% To convert an indexed image to the gray scale image [a,map]=imread('trees.tif'); imshow(a,map); f=ind2gray(a,map);figure, subplot(2,2,2),imshow(f);title('gray scale image');
o r ig in a l im a g e g ra y s c a le im a g e
b=rgb2ycbcr(a);
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:
% To increases the size of the image I = imread('circuit.tif'); J = imresize(I,1.25); imshow(I) figure, imshow(J) OUTPUT:
Fourier transform
original image
transformed image
restored image
% Create geometric transformation structure I = imread('cameraman.tif'); tform = maketform('affine',[1 0 0; .5 1 0; 0 0 1]); J = imtransform(I,tform); imshow(I), figure, imshow(J)
OUTPUT:
DAY 3
Image enhancement
% Add gaussian noise to an image I = imread('eight.tif'); J = imnoise(I, 'gaussian'); imshow(I); figure, imshow(J); OUTPUT:
% Add salt & pepper noise to an image I = imread('eight.tif'); J = imnoise(I,'salt & pepper',0.02); imshow(I) figure, imshow(J) OUTPUT:
Flat No,#G-5,103,305,502,Rathna Coimplex,Beside Image Hospital,Ameerpet,Hyderabad Ph: 9885112363
% 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)
Flat No,#G-5,103,305,502,Rathna Coimplex,Beside Image Hospital,Ameerpet,Hyderabad Ph: 9885112363
% Filtering of images, either by correlation or convolution I = imread('coins.png'); h = ones(5,5) / 25; I2 = imfilter(I,h); imshow(I), title('Original Image'); figure, imshow(I2), title('Filtered Image')
OUTPUT:
Original Image
Filtered Image
Original Image
Blurred Image
Sharpened Image
%To blur an image using a function psf. 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 Im age
%Deblurring with the Wiener Filter: 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
% Deblurring with a Regularized Filter I = imread('tissue.png'); I = I(125+[1:256],1:256,:); figure; imshow(I); title('Original Image'); PSF = fspecial('gaussian',11,5); Blurred = imfilter(I,PSF,'conv'); V = .02; BlurredNoisy = imnoise(Blurred,'gaussian',0,V); figure;imshow(BlurredNoisy);title('Blurred and Noisy Image'); NP = V*prod(size(I));
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 ');
Restored Image
DAY 5 COMPRESSIO N
%%%%%%%%%%%%%%%%day 5 %%%%%%%%%% Compression
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:
% Un sharp contrast enhancement filter I = imread('cameraman.tif'); subplot(2,2,1); imshow(I); title('Original Image'); H = fspecial('unsharp');
Flat No,#G-5,103,305,502,Rathna Coimplex,Beside Image Hospital,Ameerpet,Hyderabad Ph: 9885112363
Wavelets
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 approximation coefficents 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:
% edge-detection method that edge provides is the prewitt and Canny method z= imread('cameraman.tif'); BW1 = edge(z,'prewitt'); BW2 = edge(z,'canny'); imshow(BW1);title('prewitt image'); figure, imshow(BW2);title('canny image'); OUTPUT:
prewitt image
canny image
Segmentation
Flat No,#G-5,103,305,502,Rathna Coimplex,Beside Image Hospital,Ameerpet,Hyderabad Ph: 9885112363
% applying the watershed transform a=imread('football.jpg'); imshow(a);title('original image'); b=watershed(a); figure,imshow(b);title('transformed image');
original image
transformed image
%bwmorph means Morphological operations on binary images % Morphological operations are create connectivity array, % reconstruction morphologically etc.
%SKELETONIZATION
%To reduce all objects in an image to lines, without changing the essential structure of the image is known as skeletonization.
%Matrix to grayscale image convertion %filter2- 2-D digital filter %fspecial- Create predefined 2-D filter %mat2gray- Convert matrix to grayscale image I = imread('rice.png'); J = filter2(fspecial('sobel'),I); K = mat2gray(J); imshow(I), figure, imshow(K)
Flat No,#G-5,103,305,502,Rathna Coimplex,Beside Image Hospital,Ameerpet,Hyderabad Ph: 9885112363
OUTPUT:
%Reverse black and white in a binary image. %imcomplement- Complement image bw = imread('text.png'); bw2 = imcomplement(bw); subplot(1,2,1),imshow(bw) subplot(1,2,2),imshow(bw2)
OUTPUT:
% To plot the border on the image. I=imread(cameraman.tif); imshow(I) BW = im2bw(I); imshow(BW) dim = size(BW) col = round(dim(2)/2)-90; row = min(find(BW(:,col))) boundary = bwtraceboundary(BW,[row, col],'N'); imshow(I) hold on; plot(boundary(:,2),boundary(:,1),'g','LineWidth',10);
Flat No,#G-5,103,305,502,Rathna Coimplex,Beside Image Hospital,Ameerpet,Hyderabad Ph: 9885112363
OUTPUT:
%To rotate an image 35 counterclockwise and use bilinear interpolation. I = imread('circuit.tif'); J = imrotate(I,35,'bilinear'); imshow(I) figure, imshow(J)
OUTPUT:
%creating a mask to an image. I = imread('cameraman.tif'); BW = imread('text.png'); mask = BW(1:256,1:256); f = inline('imadjust(x,[],[],0.3)'); I2 = roifilt2(I,mask,f); imshow (I2)
OUTPUT:
%Edgetapering
original = imread('cameraman.tif'); PSF = fspecial('gaussian',60,10); edgesTapered = edgetaper(original,PSF); figure, imshow(original,[]); figure, imshow(edgesTapered,[]);
OUTPUT: