FINAL INDEPENDENT PROJECT
Title : Measuring the Diameter of an Object within an Image
Aim : To measure objects within frame or an image for many applications where computer vision is required instead of making physical measurements.
Motivation :
While scrolling through 'Quora', I came across the questions related to Image Processing and Measuring using Matlab and thought of doing this project.
Objectives :
Through this project, we could manually import the image, process it and make it measurable using the coding in MATLAB.
Required Hardware and Software :
Hardware :
- Operating System: Windows XP or better, Mac OS X Lion or better
- Processors: Intel or AMD x86 processor
- Disk Space: 4 GB or better
- RAM: 2048 MB at least recommended
- Graphics Card: Hardware accelerated graphics card supporting OpenGL 3.3 with 1 GB GPU memory recommended.
Software :
- MATLAB
- Image Processing Toolbox
Procedure :
- Calling the Image : The image is being called from the current MATLAB folder whose object diameter is to be measured
- Segmentation 1 : In this we remove the RGB color of the image and do the color thresholding
- Segmentation 2 : In this we do the complete cleanup of the image by removing the holes filled in it and also the blobs in it
- Measuring the Diameter : Finally we measure the object diameter
Image that is to be processed and measured :
Matlab Code with detailed explaination :
%The code begins with the usual commands
clc
clear all;
%Importing the image
%The image is being imported from the current matlab folder. So, in order to read the image, it must be present in the folder
obj = imread('ball.jpg');
imshow(obj)
%Segmenting the Image
%Divide image 'obj' into its respective RGB intensities i.e. removing the RGB color from the image so that we can get the the required object
red = obj(:,:,1);
green = obj(:,:,2);
blue = obj(:,:,3);
%Plotting the Original Image, Red plane, Green Plane and the Blue Plane
figure(1)
subplot(2,2,1); imshow(obj); title('Original Image');
subplot(2,2,2); imshow(red); title('Red Plane');
subplot(2,2,3); imshow(green); title('Green Plane');
subplot(2,2,4); imshow(blue); title('Blue Plane');
%Threshold the blue plane
%This is done to do the segmentation of the image
figure(2)
blue = rgb2gray(imread('ball.jpg'));
bw2 = im2bw(blue,0.37);
subplot(2,2,1); imshow(bw2); title('Blue plane thresholded');
%Remove Noise and doing complete segmentation of the image
%Fill any holes
fill = imfill(bw2,'holes');
subplot(2,2,2); imshow(fill); title('Hole Filled');
%Remove any blobs on the border of the image
clear = imclearborder(fill);
subplot(2,2,3); imshow(clear); title('Remove blobs on border');
%Remove blobs that are smaller than 7 pixels across
se = strel('disk',7);
open = imopen(fill,se);
subplot(2,2,4); imshow(open); title('Remove small blobs');
%Measuring the Diameter
diameter = regionprops(open,'MajorAxisLength');
%Show result
figure(3)
imshow(obj)
d = imdistline;
Output :
1. Color Thresholding
2. Segmentation and complete cleanup
3. Original Image manually measured
4. Command Window showing the output :
5. Detailed view of diameter
Errors faced with its Solution :
1. Error was shown that the command 'im2bw' requires 'Image Processing Toolbox'.
This error was corrected by downloading the trial version of matlab carring the 'Image Processing Toolbox'. Thus, after downloading, it corrected the error and gave outputs for the program.
References :
1. https://in.mathworks.com/videos/image-processing-made-easy-81718.html