measure focal length

measurement based on manual measurements of image features

clear
close all
load imgdata
sz = size(files);
N = sz(1);
for m=1:N
    subplot(3,3,m);
    rgb = imread(files(m,:));
    sz = size(rgb);
    small = imcrop(rgb,[sz(1)/4 sz(2)/4 512 512]);
    g = rgb2gray(im2double(small));
    imshow(g);
    hold on
    plot(data(:,1,m),data(:,2,m),'yo');
    hold off
    fprintf('image %d threshold %g width %g\n',m,graythresh(g),data(2,1,m)-data(1,1,m));
end
image 1 threshold 0.560784 width 232
image 2 threshold 0.564706 width 166
image 3 threshold 0.517647 width 98
image 4 threshold 0.490196 width 82
image 5 threshold 0.458824 width 71
image 6 threshold 0.458824 width 62
image 7 threshold 0.458824 width 53
image 8 threshold 0.458824 width 49
image 9 threshold 0.439216 width 44
subplot(1,1,1);
imhist(g);
hold on
thres = graythresh(g);
plot([thres thres],[0 4000],'k--','LineWidth',2);
hold off
name = files(1,:);
caminfo;
File name: 2013_0131_162938AA.JPG
Camera Make: FUJIFILM
Camera Model: FinePix6900ZOOM
Focal length 9.7
Image size 2048 x 1536
DateTime 2013:01:31 16:29:38
w = 2*5.3; % cm, width of two squares
diff = data(2,1,:)-data(1,1,:);
width = diff(:);
% camera shutter did not trigger at a couple of stops
zcm = zinches([2:3,5:11])*2.54;
y = w./width;
subplot(1,1,1);
plot(zcm,y,'ko');
grid;
xlabel('distance (cm)');
ylabel('actual/measured (cm/pixel)');
ndx = 3:length(zcm);
c1 = polyfit(zcm(ndx),y(ndx),1);
hold on
xr = [0 600];
plot(xr,polyval(c1,xr),'k','LineWidth',2);
hold off
fprintf('effective focal length %g pixels\n',1/c1(1));
effective focal length 2462.91 pixels