Professional Documents
Culture Documents
Computer Vision: Assignment #02
Computer Vision: Assignment #02
Computer Vision: Assignment #02
Assignment #02
Task: Optical Mark Recognition from Camera Based Images
CODE:
clear all;
close all;
%Loading Image
InputImage = im2bw( imread('C:\Users\Sara Latif
Khan\OneDrive\Desktop\CV2\img.jpg'), 0.3);
figure, imshow(InputImage);
% Binarizing Image
binImage = ~InputImage;
binImage = 1-InputImage;
binImage = (InputImage == 0);
figure, imshow(binImage), title('Inverted Binary Image');
%Reducing Size
Image= imresize(Image,[800 800]);
% 'imtool' Function to get coordinates information from image
imtool(Image);
% Strcuturing element
se = strel('rectangle', [1, 85]);
%Dilation
img_dilated = imdilate(Image, se);
figure, imshow(img_dilated), title('Dilated Image')
% Labelling image to extract all connected lines
[Level,number] = bwlabeln(img_dilated,4);
disp(number);
% Initializing Arrays to store Answer, x and y coordinates respectively
Ans = blanks(number-2);
Array1 = [];
Array2 = [];
% Loop for analysis each line
for l=1: number
% 'regionprops' method to extract area and centeriod information
components = regionprops(Level==l, 'area','centroid');
% A condition to discard first two line with labels of Options
if(components(1).Area>5000)
% Intersecting each dilated indiviusal line from complement of image to get
indivisual labeled line
img = Level==l & Image;
2
%figure, imshow(Level1);
% Finding possition of filled circle
[column,row] = imfindcircles(Level1,[10,20]);
% A condition to check if question is unattempted
if (size(column)==0)
Array1(l) = round(components(1).Centroid(:,1));
Array2(l) =round( components(1).Centroid(:,2));
Ans(l)='0';
else
% Else If Question is attempted then finding possition of circle
x= round(column(:,1));
y= round(column(:,2));
3
end
end
% Zero ‘0’ Represents unattempt Question
disp('Left Column Answer');
disp(ArrayX);
disp('Right Column Answer');
disp(ArrayY);
Output:
Original Binary Image:
4
9/19/2020
5
Resized Image with Coordinates Info:
9/19/2020
6
Dilated Binary Image, with rectangular Structuring Element of Size [1,85]:
9/19/2020
7
Detected Answers :
9/19/2020