No BSD License  

Highlights from
Callibrating an image

image thumbnail
from Callibrating an image by Gaurav Sehgal
This functions enables user to callibrate the image to get the relationship between pixel distance a

callibration1(d)
%%%%%%%%%%%%%%% This function helps callibrating distances on the image %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%% to real world distances. The files to be included for this function to be used are pixvals.m. This is the modified file from pixval.m available in Matlab image toolbox. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%d is the input image to be callibrated and dist1 is the callibration factor output%%%%
function dist1 = callibration1(d) 
 yed =1;                                              %%%% Variable%%%%%
 prompt  = {'Enter the Calibration scale in cm '};   
title   = 'Calibration';
lines= 1;
answer  = inputdlg(prompt,title,lines);         %%%% Reads the value entered by the user%%% 
v1 = str2double(answer);                        %%converts the value from string to double%%  

%%%%%%%The code below lets the user actually drag the line on the image for callibration%%%%%%
while (yed==1)
figure; imshow(d)
k = waitforbuttonpress;                %%%%%Left click once on the image to start the callibration%%%%
while ( k ~= 1)                       %%%% Again left click on the start point and drag the mouse holding the left key to the end point and release the key%%%%%%  
    pixvals on                         %%%%% after doing that press enter key on the keyboard, a dialog box should appear asking to confirm the callibration%%%%%  
     k = waitforbuttonpress;              
end

%%%%%%This is the callibration box that will appear after pressing enter key%%%%%%%%%%%%
 button2 = questdlg('Is this Calibration done',....   
  ' Calibration', 'Yes','No','No');
if strcmp(button2,'Yes')                   %%%%%%If YES is clicked then the file "aa1.dat" is read that has the starting and end coordinates 
   [aaa] = textread('aa1.dat','%s ',-1);   %%%%%% which is generated internally by pixvals function 
   yed =2;
elseif strcmp(button2,'No')               %%%%%%If NO is clicked then the image again reappers and ready for callibration%%%%%%%%%%%%%% 
      yed =1;
      close all;
  end
end

%%%%% The below code reads the coordinates from "aa1.dat" and finds the Eucledian distance between starting and end point%%%%%%%%%%%%%%%%
s = char(aaa);
 j = 1;
 i=1;
 k=0;
 f=1;
 xx1=size(s);
 for kk = 1:(xx1(1,1))
     k=k+1;
     j=1;
 for ii = 1:(xx1(1,2))
     if(s(kk,ii) ~=',')
        g(k,j) = (s(kk,ii));
        j=j+1;
     else
         k=k+1;
         j=1;
     end
 end
 end
 kf=1;
 Ce=cellstr(g);
 ss6 = size(Ce);
 for ww3 = 1:ss6(1,1)
     v(kf,1) = str2double(Ce{ww3,1});
     kf=kf+1;
 end
   deltax = (v(1,1) - v(3,1));
   deltay = (v(2,1) - v(4,1));
   dist = sqrt(deltax^2 + deltay^2);
   dist1 = v1/dist;            %%%%%%%%%%%%The callibration factor is calculated by dividing callibration value entered by the user with the eucledian distance%%%%%%%%%5 
 

Contact us at files@mathworks.com