
image_set = randn(50,50,25);
[emean, estdev, enoise] = cv_est_noise(image_set);
if abs(mean2(emean))>0.01
  disp('cv_est_noise: bad emean');
end
if abs(mean2(estdev)-1)>0.05
  disp('cv_est_noise: bad estdev');
end
if abs(enoise-1)>0.05
  disp('cv_est_noise: bad enoise');
end

image_row = [-100 -100 -100 100 100 100 -100 -100 -100 100 100 100];
image_in = [image_row; image_row; image_row];
image_in = [image_in; image_in; image_in; image_in];
cee = cv_auto_covariance(image_in);
ceen = cee./(max(max(cee)));
if abs(ceen(1,1)-1)>0.05
   disp('cv_auto_covariance: variance wrong');
end
if ceen(1,4)>0
   disp('cv_auto_covariance: wrong');
end

x = -2*pi:0.1:2*pi;
x = [x 6.3168 6.4168];
A = sin(x);
A = [A;A;A;A;A;A;A;A];
A = [A;A;A;A;A;A;A;A];
A = [A;A];
%Ai = mat2gray(A);
load As;
range_in = cv_rng_shade(A);
shaded_image = cv_rng_shade(range_in);
image_dif = sum(sum(As-shaded_image));
if image_dif>0.01
  disp('cv_rng_shade: images differ');
end

pts = [1 0 0; 0 1 0; -1 0 0; 0 -1 0];
pts_new = [0 1 0; -1 0 0; 0 -1 0; 1 0 0];
trnsfm = [0 -1 0 0; 1 0 0 0; 0 0 1 0; 0 0 0 1];
pts_trns = cv_trnsfm3(trnsfm, pts);
pts_dif = sum(sum(pts_new-pts_trns));
if pts_dif>0.01
  disp('cv_tnsfm3: points differ');
end

pts = [pts zeros(4,1) zeros(4,1) ones(4,1)];
pts_new = [pts_new zeros(4,1) zeros(4,1) ones(4,1)];
pts_trns = cv_trnsfm6(trnsfm, pts);
pts_dif = sum(sum(pts_new-pts_trns));
if pts_dif>0.01
  disp('cv_tnsfm6: points differ');
end

%load ptsrect;
pts = cv_rect_pts(1,1,0.5,0.5);
sx = max(pts(:,1))-min(pts(:,1));
if abs(sx-1)>0.01
  disp('cv_rect_pts: side x wrong');
end
  
sy = max(pts(:,2))-min(pts(:,2));
if abs(sy-1)>0.01
  disp('cv_rect_pts: side y wrong');
end
  
dx = max(diff(pts(:,1)));
if abs(dx-0.5)>0.01
  disp('cv_rect_pts:  dx wrong');
end
  
dy = max(diff(pts(:,2)));
if abs(dy-0.5)>0.01
  disp('cv_rect_pts: dy wrong');
end

%load ptscircle;
pts = cv_circle_pts(1,0.25,0.25);
[num_pts,dummy] = size(pts);
maxdist = -20;
for p1 = 1:num_pts-1
  for p2 = p1+1:num_pts
    ptdist = sqrt(sum((pts(p1,:)-pts(p2,:)).^2));
    if ptdist>maxdist
      maxdist = ptdist;
    end
  end
end
if maxdist > 2
  disp('cv_circle_pts:  radius wrong');
end
  
dx = max(diff(pts(:,1)));
if abs(dx-0.25)>0.01
  disp('cv_circle_pts:  dx wrong');
end
  
dy = max(diff(pts(:,2)));
if abs(dy-0.25)>0.01
  disp('cv_circle_pts: dy wrong');
end

%load ptsbox;
pts = cv_box_pts(2,2,2,0.5,0.5,0.5); bpts = pts;
sx = max(pts(:,1))-min(pts(:,1));
if abs(sx-2)>0.01
  disp('cv_box_pts: side x wrong');
end
  
sy = max(pts(:,2))-min(pts(:,2));
if abs(sy-2)>0.01
  disp('cv_box_pts: side y wrong');
end
  
sz = max(pts(:,3))-min(pts(:,3));
if abs(sz-2)>0.01
  disp('cv_box_pts: side z wrong');
end
  
%dx = max(diff(pts(:,1)));
%if abs(dx-0.5)>0.01
%  disp('cv_box_pts:  dx wrong');
%end
  
%dy = max(diff(pts(:,2)));
%if abs(dy-0.5)>0.01
%  disp('cv_box_pts: dy wrong');
%end

%dz = max(diff(pts(:,3)));
%if abs(dz-0.5)>0.01
%  disp('cv_box_pts: dz wrong');
%end
figure(1);
plot3(pts(:,1),pts(:,2),pts(:,3),'r*');
figure(2);
plot3(pts(:,4),pts(:,5),pts(:,6),'r*');

%load ptssphere;
pts = cv_sphere_pts(2, 0.3, 0.3, 0.3, 0.1);
figure(3);
plot3(pts(:,1),pts(:,2),pts(:,3),'r*');
figure(4);
plot3(pts(:,4),pts(:,5),pts(:,6),'r*');

%load ptssphere;
pts = cv_cyl_pts(2, 4, pi/8., 0.2);
figure(5);
plot3(pts(:,1),pts(:,2),pts(:,3),'r*');
figure(6);
plot3(pts(:,4),pts(:,5),pts(:,6),'r*');

