source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/BlueCCal/MultiCamSelfCal/FindingPoints/im2imstat.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 4.4 KB
Line 
1% im2imstat    computes image statistics from several images
2%              and finds the projections of laser points
3%
4% The computation core is taken from  im2points.m
5% computes average image and image of standard deviations
6% requires configdata.m
7% The name of the experiment has to be specified
8% it determines the location of files etc ...
9%
10% the scripts serves as a template for a multiprocessing
11% it assumes a vector of camera IDs CamIds to be known
12% indexes in the CamIds are supposed to be correct
13%
14% It is used by im2pmultiproc.pl
15
16% $Author: svoboda $
17% $Revision: 2.0 $
18% $Id: im2imstat.m,v 2.0 2003/06/19 12:06:51 svoboda Exp $
19% $State: Exp $
20
21config = configdata(expname);
22
23STEP4STAT = 5; % step for computing average and std images, if 1 then all images taken
24
25im.dir = config.paths.img;
26im.ext = config.files.imgext;
27
28% NoCams = size(config.files.idxcams,2);        % number of cameras
29% Use concrete CameraIds instead of all cameras
30NoCams = size(CamsIds,2);
31CamsIds
32
33% load image names
34for i=1:NoCams,
35  seq(i).camId = CamsIds(i);
36  if seq(i).camId > -1
37        seq(i).data = dir([sprintf(im.dir,seq(i).camId),sprintf(config.files.imnames,seq(i).camId),im.ext]);
38        [sprintf(im.dir,seq(i).camId),sprintf(config.files.imnames,seq(i).camId),im.ext]
39  else
40        seq(i).data = dir([im.dir,sprintf(config.files.imnames),im.ext]);
41  end
42  seq(i).size = size(seq(i).data,1);
43  if seq(i).size<4
44        error('Not enough images found. Wrong image path or name pattern?');
45  end
46end
47
48% Expected number of 3D points is equal to the number of frames.
49% In fact, some frames might be without any calibration point
50
51% Because of non-consistent stopping of capturing, the sequences might
52% have different number of images, select the minimal value as the right one
53NoPoints = min([seq.size]);
54
55% compute the average images that will be used for finding LEDs
56% if not already computed
57
58pointsIdx = [1:STEP4STAT:NoPoints];
59
60t = cputime;
61for i=1:NoCams,
62  if ~exist(sprintf(config.files.avIM,seq(i).camId)),
63        disp(sprintf('The average image of the camera %d is being computed',seq(i).camId));
64        avIM = zeros(size(imread([sprintf(im.dir,seq(i).camId),seq(i).data(1).name])));
65        for j=pointsIdx,
66          IM = imread([sprintf(im.dir,seq(i).camId),seq(i).data(j).name]);
67          avIM = avIM + double(IM);
68        end
69        avIM = uint8(round(avIM./size(pointsIdx,2)));
70        imwrite(avIM,sprintf(config.files.avIM,seq(i).camId));
71  else  disp('Average files already exist');
72  end
73end
74disp(sprintf('Elapsed time for average images: %d [sec]',cputime-t))
75% compute the standard deviations images that will be used for finding LEDs
76% if not already computed
77t = cputime;
78for i=1:NoCams,
79  if ~exist(sprintf(config.files.stdIM,seq(i).camId)),
80        avIM = double(imread(sprintf(config.files.avIM,seq(i).camId)));
81        disp(sprintf('The image of standard deviations of the camera %d is being computed',seq(i).camId));
82        stdIM = zeros(size(imread([sprintf(im.dir,seq(i).camId),seq(i).data(1).name])));
83        for j=pointsIdx,
84          IM = imread([sprintf(im.dir,seq(i).camId),seq(i).data(j).name]);
85          stdIM = stdIM + (double(IM)-avIM).^2;
86        end
87        stdIM = uint8(round(sqrt(stdIM./(size(pointsIdx,2)-1))));
88        imwrite(stdIM,sprintf(config.files.stdIM,seq(i).camId));
89  else
90        disp('Image of standard deviations already exist')
91  end
92end
93disp(sprintf('Elapsed time for computation of images [sec]: %d',cputime-t))
94
95% find points in the images
96Ws    = [];
97IdWs  = [];
98Res       = [];
99
100IdMat = ones(NoCams,NoPoints);
101% IdMat is very important for Martinec&Pajdla filling [ECCV2002]
102% it is a NoCams x NoPoints matrix,
103% IdMat(i,j) = 0 -> no j-th point in i-th
104% IdMat(i,j) = 1 -> point successfully detected
105
106for i=1:NoCams,
107  Points = [];
108  avIM  = imread(sprintf(config.files.avIM,seq(i).camId));
109  stdIM = imread(sprintf(config.files.stdIM,seq(i).camId));
110  for j=1:NoPoints,
111        [pos,err] = getpoint([sprintf(im.dir,seq(i).camId),seq(i).data(j).name], 0, config.imgs, avIM, stdIM);
112        if err   
113          IdMat(i,j) = 0;
114          Points = [Points, [NaN; NaN; NaN]];
115        else
116          Points = [Points, [pos; 1]];
117        end
118  end
119  Ws = [Ws; Points];
120  Res= [Res; size(avIM,2), size(avIM,1)];
121end
122
123idx = '.';
124for i=CamsIds,
125  idx = sprintf('%s%02d',idx,i);
126end
127       
128save([config.files.points,idx], 'Ws','-ASCII')
129% save(config.files.IdPoints,'IdWs','-ASCII')
130save([config.files.Res,idx], 'Res', '-ASCII')
131save([config.files.IdMat,idx], 'IdMat', '-ASCII')
132
133% write auxiliary file that is done
134done=1;
135save(donefile,'done','-ascii');
136
137% exit the Matlab
138% this script is to be used in the batch mode
139% hence exit at the end is necessary
140exit;
Note: See TracBrowser for help on using the repository browser.