Vous êtes sur la page 1sur 4

Determination of Dimension of an Unknown Object from an Image with a Known Dimension and Camera Aperture Profile

Sarah Amir1, Bishwajit Debnath2, Sariful Islam


Department of Electrical and Electronic Engineering Bangladesh University of Engineering and Technology, Dhaka-1000, Bangladesh.
2

prema_buet@yahoo.com bishwajit.debnath.eee@gmail.com

Abstract The unknown dimension of an object can be measured comparing to an object of known height adjacent to the previous object in an image with digital image processing. This paper includes the mathematical derivation, algorithm of the full procedure and the necessary MATLAB code with sample data. Keywords MATLAB, Digital Image Processing, Unknown Height Detection, Programming, Algorithm

, & . To get the image, we draw FD & GE perpendicular on AB. Extend AG & DF so that they cut each other in point I. So the images of BF & BG are DF & DI respectively. Let image ratio,

I. INTRODUCTION Many objects are often too large or in different shape to measure with common procedure, like mountains. The process presented here is based on digital image processing to measure those dimension is proposed in this work, where the image is taken from the same base level and known distance from camera. In the image, An object with known height is also placed as a reference with the object to be measured. II. GEOMETRICAL DERIVATION An image of two objects having different heights and standing on the same view plane as the camera, with a known camera height H. If the actual height of the smaller object is h, the distance between the base point of the objects and camera is D, Actual object length ratio is Ko. Then Unknown length = Ko Known length

In

Again in

Now, we draw

( in Figure-2)

Fig 1: Geometrical position of objects and camera

) (

) ( )

Let, Two objects, BF with known dimension and BG with unknown dimension are standing on a common point B. On the same plane BC, a camera A is standing on AC stand. Join A, B; A, F & A, G. Also let,

= Actual Object Height Ratio

Now,

III. ALGORITHM The algorithm used in this paper is stated in the flow-chart below: Collect sample images with distances. Detect objects in image. Save h & D in 1 row matrixes. Plot sample points. Find the relation between D & h with polynomial regression

Get the main image. Detect the images of known & unknown heights.
With the detected h of main image, find the distance D from the evaluated polynomial.
;

Again,

Get the image ratio, k.


Calculate & with proper equation derived previously. Calculate the actual object ratio with values of k, & with the derived equation. Calculate required length = h actual object ratio.

Fig 2: Flow-chart of the algorithm

Where, k = image height ratio (measured from image)


,

IV. IMAGE PIXEL VS. DISTANCE PROFILE The distance between the objects and the camera can be measured from a series of sample data acquired from a number of images taken from different distances from the reference object to camera. These data shows the relationship between the known object height in pixels and distance. The relation between distance D and the height of image of a known height object is not linear. This relation can be expressed as a polynomial of higher degree of x determined by polynomial regression as presented in fig.3. The relationship between distance and the known image height can be determined. Either from the relationship or from the plot, the distance of the object and camera from the particular image can be evaluated, by measuring the known object pixel length in the image. The process is included in the MATLAB code given. For another object, the set of data for distance measurement may vary, but the process will be same, as the code. In practical, the object was of 1 foot. And pictures were taken from 5 feet to 75 feet. That showed image decrement rate does not show linearity for even 75 times large distance

of object. The curve plotted for image vs. distance is found as in fiq.3.

end end end s1 = strcat('pic',int2str(i-21)); s1 = strcat(s1,'.bmp'); imwrite(I,s1,'BMP'); end B. Main Code: clear all; clc %% For D-h relationship: % Detecting h: adrs1= ('C:\MATLABproject_group1\samples\pic'); for I = 1:15 %taken 15 sample images adrs = strcat(adrs1,int2str(i)); adrs = strcat(adrs,'.bmp'); % generated the address of samples [ix,ih] = imagedetect(adrs); ihs(i) = ih; end % pixel length of 15 image of known object is collected Ds = 5:5:75; % sample images distance: 5 to 75 feet with 5 feet interval % Relation between Distance & image of h plot(ihs,Ds,'o'); % shows the non-linear relation of image with distance ylabel('Distance, D (in feet)'); xlabel('Small image height (in pixel)'); hold on; P=fitincurve(ihs,Ds); % calling a polynomial regression function to get the relation % calculating D: [imx,imh]=imagedetect('C:\MATLABproject_group1\main\im age.bmp'); % imx=length of large image in pixel, imh=length of smaller known image in pixel D=polyval(P,imh); %% Calculation of Actual Object Ratio: k = imx/imh; % k is image ratio H = (56.75)/12; % H is the camera height h = 1; % h is the actual height of known object alpha = atand(D/H); theta = (atand(D/(H-h)))-alpha; actratio = (((k-1)*tand(alpha))/ ((k*tand(theta))+(tand(alpha))))+1; %% Calculation of Actual height of unknown object: x = actratio*h*12; % x is the actual height of unknown object in inch disp('The actual height of the unknown object is: '); disp(x);

Fig 3: Relationship between image size of known object and distance

So, it was found from data too that the height of image decrease with increasing distance non-linearly. V. MATLAB CODE The algorithm is applied to the code below written for MATLAB: The program has been tested for detecting an object of height 47.25 inch comparing with an object of smaller height of 12inch. The camera was placed on a height 56.75 inch. A. Required prior processing of image: One of the most important requirements for detecting heights from image was removing the same color elsewhere from the image which is being used for manually marking the heights. For our experiment, we used black color, which has the color number 0 in MATLAB. So it was very important that if we search the image for black as to determine height, no other black is detected. For this black had to be removed from image before marking manually the image. The following code was made to modify images. It searched for black (number 0) in the image, & replaced 0 with 5, a color not black but closely equal black, which do not change the image for our eye vision. Then new images were written as image file for further use. clear all; clc for i = 22:36 s = ('C:\MATLABproject_group1\samples\pic'); s = strcat(s,int2str(i)); s = strcat(s,'.jpg'); I = imread(s,'JPEG'); N = size(I); Col = N(1,1); Row = N(1,2); for j = 1:col for k = 1:row for t = 1:3 if I(j,k,t) == 0 I(j,k,t) = 5; end

C. Functions: Imagedetect(): function [imx,imh]=imagedetect(adrs) I1=imread(adrs,'BMP'); N=size(I1); nr=N(1,1); %number of row is the pixel height of the image nc=N(1,2); t=1; for r=1:nr %moving along the row at first for c=1:nc if I1(r,c)==0 B(t)=r; t=t+1; break; % whenever we got a height, the is no need to move along the same height end end end imx=B(1,3)-B(1,1); imh=B(1,3)-B(1,2); end fitincurve() : function C = fitincurve(x,y) n = length(x); % q1 = input('What is the maximum power of x ? '); q1 = 10; q = q1+1; qm = (2*q)-2; X = ones(qm,n); X(1,:) = x; sumX = ones(1,qm+1); sumX(1) = n; sumX(2) = sum(x); for I = 2:qm X(i,:) = X(i-1,:).*x; sumX(i+1) = sum(X(i,:)); end A = ones(q); for j = 1:q for k = 1:q A(j,k) = sumX(j+k-1); end end Y = ones(n); B = ones(q,1); B(1,1) = sum(y); for m = 2:q Y(m-1,:) = X(m-1,:).*y; B(m,1) = sum(Y(m-1,:)); end C = (A\B)'; C = fliplr(C); % disp(C);

y = polyval(C,x); plot(x,y,'r'); D. Result (on the command window of MATLAB): The actual height (in inches) of the unknown object is: 45.6699
E. Error Calculation:

The result encountered 3.34% error. The error was mainly for two reasons- first, when picking photos, camera height and focus could not be made constant. Camera height 0.5% varied in the sample pictures. Another reason was the height in image was manually marked with black color. As it was done manually, some error was occurred.
F. Limitation:

The procedure of detecting height in this code has one limitation. This code cannot detect image heights unless certain lines or dots of a specific color on the peaks and bottom is used as marks. The detection process can be simplified if the color of the peaks and bottom are unique and known. The work can be extended and improved with the help of modern edge detection algorithms to find the objects and measure their exact dimensions. VI. CONCLUSION The novelty of this paper lies in the development of a unique process to measure any comparative length from a simple digital image, which is very promising for low cost measurement options, in security cameras and military applications. ACKNOWLEDGMENT The authors are thankful to Md. Itrat Bin Shams, Assistant Professor, Bangladesh University of Engineering and Technology, for the valuable discussions and helping with the image processing toolbox. REFERENCES
[1] G. Blanchet, M. Charbit, Digital Signal and Image Processing Using MATLAB, 1st ed., London, United Kingdom: ISTE Publishing Company, 2006. C. Solomon, T. Breckon, Fundamentals of Digital Image Processing , West Sussex, United Kingdom : Wiley Blackwell Publishing Company, 2011.

[2]