Computer Vision New
Computer Vision New
a. Reading image
I = imread('columns.tif');
imshow(I)
Output:
1
LJ Institute of Engineering and Technology Computer Vision (3171614)
b. writing image
load clown
imwrite (X,map,'clown.tif');
image(X)
Output:
2
LJ Institute of Engineering and Technology Computer Vision (3171614)
c. conversion of images
RGB = imread('peppers.png');
imshow(RGB)
Output:
I = rgb2gray(RGB);
figure
imshow(I)
Output:
3
LJ Institute of Engineering and Technology Computer Vision (3171614)
d. complement of an image
I=imread('columns.tif');
imshow(I);
I=imcomplement(I);
figure, imshow(I);
Output:
4
LJ Institute of Engineering and Technology Computer Vision (3171614)
imshow('cameraman.tif')
Imcontrast
5
LJ Institute of Engineering and Technology Computer Vision (3171614)
6
LJ Institute of Engineering and Technology Computer Vision (3171614)
I = imread('columns.tif');
figure
subplot(1,2,1)
imshow(I)
subplot(1,2,2)
imhist(I,64)
Output:
J = histeq(I);
figure
subplot(1,2,1)
imshow(J)
subplot(1,2,2)
imhist(J,64)
7
LJ Institute of Engineering and Technology Computer Vision (3171614)
Output:
8
LJ Institute of Engineering and Technology Computer Vision (3171614)
3. Implement the various low pass and high pass filtering mechanisms.
a=imread('cameraman.tif');
b=size(a);
if size(b,2)==3
a = rgb2gray(a);
end
a = imnoise(a,'salt & pepper');
c=0;
h=0;
for i=n1:b(1)-n1
for j=n1:b(2)-n1
p=1;
for k=1:n
for l=1:n
c(p)=a(i-n1+k,j-n1+l);
p=p+1;
end
end
d(i,j)=median(c);
c=0;
end
end
e=uint8(d);
figure;imshow(e);title('low pass image');
for i=n1:b(1)-n1
for j=n1:b(2)-n1
for k=1:n
for l=1:n
h=h+a(i-n1+k,j-n1+l)*hpf(k,l);
end
9
LJ Institute of Engineering and Technology Computer Vision (3171614)
end
g(i,j)=h;
h=0;
end
end
f=uint8(g);
figure;imshow(f);title('high pass image');
figure;imshow(uint8(a));title('Original image');
Output:
10
LJ Institute of Engineering and Technology Computer Vision (3171614)
I=imread(' columns.tif');
I1=rgb2gray(I);
I2=fft2(I1);
subplot(311);
imshow(I);
subplot(312);
imshow(I1);
subplot(313);
imshow(I2)
Output:
11
LJ Institute of Engineering and Technology Computer Vision (3171614)
img = imread('cameraman.tif');
[featureVector,hogVisualization] = extractHOGFeatures(img);
figure;
imshow(img);
hold on;
plot(hogVisualization);
12
LJ Institute of Engineering and Technology Computer Vision (3171614)
I1 = imread('gantrycrane.png');
[hog1,visualization] = extractHOGFeatures(I1,'CellSize',[32
32]);
subplot(1,2,1);
imshow(I1);
subplot(1,2,2);
plot(visualization);
I2 = imread('gantrycrane.png');
corners = detectFASTFeatures(im2gray(I2));
13
LJ Institute of Engineering and Technology Computer Vision (3171614)
strongest = selectStrongest(corners,3);
[hog2,validPoints,ptVis] = extractHOGFeatures(I2,strongest);
figure;
imshow(I2);
hold on;
plot(ptVis,'Color','green');
14
LJ Institute of Engineering and Technology Computer Vision (3171614)
Output:
15
LJ Institute of Engineering and Technology Computer Vision (3171614)
I = imread('coins.png');
level = graythresh(I)
BW = imbinarize(I,level);
imshowpair(I,BW,'montage')
b. Edge Detection
I = imread('coins.png');
imshow(I)
16
LJ Institute of Engineering and Technology Computer Vision (3171614)
BW1 = edge(I,'sobel');
BW2 = edge(I,'canny');
tiledlayout(1,2)
nexttile
imshow(BW1)
title('Sobel Filter')
nexttile
imshow(BW2)
title('Canny Filter')
c. Morphological Processing
i. Dilation
ii. Erosion
I=imread('circles.png');
%structruring element
sel=strel('disk',11);
er=imerode(I,sel);
figure,
imshow(I);
title('original Image');
figure,
imshow(er);
title('Image after erosion');
A=imread('cameraman.tif');
se2=strel('ball',5,5);
de=imdilate(A,se2);
figure,I
imshow(A);
title('original Image');
17
LJ Institute of Engineering and Technology Computer Vision (3171614)
figure,
imshow(de);
title('Image after Dilation');
18
LJ Institute of Engineering and Technology Computer Vision (3171614)
flow = opticalFlow
Vx = randn(100,100);
Vy = randn(100,100);
opflow = opticalFlow(Vx,Vy);
opflow
plot(opflow,'DecimationFactor',[10 10],'ScaleFactor',10);
19
LJ Institute of Engineering and Technology Computer Vision (3171614)
20
LJ Institute of Engineering and Technology Computer Vision (3171614)
vidReader = VideoReader('visiontraffic.avi','CurrentTime',11);
opticFlow = opticalFlowHS
opticFlow =
opticalFlowHS with properties:
Smoothness: 1
MaxIteration: 10
VelocityDifference: 0
h = figure;
movegui(h);
hViewPanel = uipanel(h,'Position',[0 0 1 1],'Title','Plot of Optical Flow
Vectors');
hPlot = axes(hViewPanel);
while hasFrame(vidReader)
frameRGB = readFrame(vidReader);
frameGray = im2gray(frameRGB);
flow = estimateFlow(opticFlow,frameGray);
imshow(frameRGB)
hold on
plot(flow,'DecimationFactor',[5 5],'ScaleFactor',60,'Parent',hPlot);
hold off
pause(10^-3)
end
21
LJ Institute of Engineering and Technology Computer Vision (3171614)
Output:
22
LJ Institute of Engineering and Technology Computer Vision (3171614)
[bboxes,scores,labels] = detect(detector,I)
23
LJ Institute of Engineering and Technology Computer Vision (3171614)
detectedI = insertObjectAnnotation(I,'Rectangle',bboxes,cellstr(labels));
figure
imshow(detectedI)
24
LJ Institute of Engineering and Technology Computer Vision (3171614)
1. Preparing dataset
Dataset link =
https://drive.google.com/file/d/14g_fD74pDmX9AsgkAQG59cxQSh0fgRr2/view
persistent loaded;
persistent numeric_Image;
if(isempty(loaded))
cd(strcat('s',num2str(i)));
image_Container =
imread(strcat(num2str(j),'.pgm'));
all_Images(:,(i-
1)*10+j)=reshape(image_Container,size(image_Container,1)
*size(image_Container,2),1);
end
25
LJ Institute of Engineering and Technology Computer Vision (3171614)
cd ..
end
end
loaded = 1;
output_value = numeric_Image;
loaded_Image=load_database();
random_Index=round(400*rand(1,1));
random_Image=loaded_Image(:,random_Index);
rest_of_the_images=loaded_Image(:,[1:random_Index-1
random_Index+1:end]);
image_Signature=20;
white_Image=uint8(ones(1,size(rest_of_the_images,2)));
mean_value=uint8(mean(rest_of_the_images,2));
mean_Removed=rest_of_the_images-
uint8(single(mean_value)*single(white_Image));
L=single(mean_Removed)'*single(mean_Removed);
[V,D]=eig(L);
V=single(mean_Removed)*V;
26
LJ Institute of Engineering and Technology Computer Vision (3171614)
V=V(:,end:-1:end-(image_Signature-1));
all_image_Signatire=zeros(size(rest_of_the_images,2),ima
ge_Signature);
for i=1:size(rest_of_the_images,2);
all_image_Signatire(i,:)=single(mean_Removed(:,i))'*V;
end
subplot(121);
imshow(reshape(random_Image,112,92));
subplot(122);
p=random_Image-mean_value;
s=single(p)'*V;
z=[];
for i=1:size(rest_of_the_images,2)
z=[z,norm(all_image_Signatire(i,:)-s,2)];
if(rem(i,20)==0),imshow(reshape(rest_of_the_images(:,i),
112,92)),end;
drawnow;
end
[a,i]=min(z);
subplot(122);
imshow(reshape(rest_of_the_images(:,i),112,92));
27
LJ Institute of Engineering and Technology Computer Vision (3171614)
title('Recognition
Completed','FontWeight','bold','Fontsize',16,'color','re
d');
Output:
28