PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/MatlabCode/branches/Greg's Branch/Slave/Monitor Calibration/testCalCC.m

http://horwitzlab.googlecode.com/
MATLAB | 111 lines | 92 code | 14 blank | 5 comment | 5 complexity | 7fffa3a579de0822084b491b7e64f0a6 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. function [requested, spd] = testCalCC(nRepeats)
  2. ccs = [0.005 0.01 0.015 0.02 0.03 0.04 0.05 0.07 0.09 0.11];
  3. l_ccs = [ccs(:), zeros(length(ccs), 2)];
  4. m_ccs = [zeros(length(ccs), 1), ccs(:), zeros(length(ccs), 1)];
  5. ccs = [0.05 0.01 0.015 0.02 0.03 0.04 0.05 0.07 0.09 0.11 0.15 0.19 0.22 0.28 0.31];
  6. s_ccs = [zeros(length(ccs), 2), ccs(:)];
  7. no_ccs = [0 0 0];
  8. requested = repmat([l_ccs; m_ccs; s_ccs; no_ccs], nRepeats, 1);
  9. idx = randperm(size(requested,1));
  10. requested = requested(idx,:);
  11. %set up the PR650
  12. S = [380, 4, 101]; % Native PR650 settings
  13. spd = nan(101, size(requested,1));
  14. CMCheckInit(1, 'USA19H')
  15. input('Press <Enter> to continue');
  16. %set up the monitor
  17. maxdac = (2^16)-1;
  18. load('T_cones_smj.mat');
  19. load('/Users/horwitzlab/Desktop/MatlabCode/Monitor Calibration/Monitor data/Dell 2/Dell2BitsCal.mat');
  20. cal = cals{end};
  21. fundamentals = T_cones_smj;
  22. gammaTable = cal.gammaTable;
  23. bkgndRGB = round(255 .* cal.bgColor)+1; %bkgnd voltages discretized b/w 1&256
  24. bkgndrgb = [gammaTable(bkgndRGB(1),1), gammaTable(bkgndRGB(2),2), gammaTable(bkgndRGB(3),3)];
  25. monSpd = SplineSpd(cal.S_device, cal.P_device, S_cones_smj);
  26. M = fundamentals * monSpd;
  27. invGamma = InvertGamma(cal, 1);
  28. bkgndlms = M * bkgndrgb';
  29. wind = Screen('OpenWindow', 0, bkgndRGB);
  30. textRect = [150, 300, 350, 500];
  31. spd = nan(size(requested,1), 101);
  32. for a = 1:size(requested, 1)
  33. img = nan(100, 100, 3);
  34. tCCS = requested(a,:);
  35. tlms = ((1+tCCS) .* bkgndlms');
  36. trgb = M \ tlms(:); %left divide instead of inv(M)
  37. trgb = round(maxdac .* trgb) + 1; %index b/w 1 and 2^16
  38. tRGB = [invGamma(trgb(1), 1), invGamma(trgb(2), 2), invGamma(trgb(3), 3)];
  39. tRGB = round(maxdac .* tRGB); %voltage b/w 0 & 2^16
  40. img(:,:,1) = tRGB(1);
  41. img(:,:,2) = tRGB(2);
  42. img(:,:,3) = tRGB(3);
  43. tex = Screen('MakeTexture', wind, TranslateToColourModeMex(img));
  44. Screen('DrawTexture', wind, tex, [], textRect, [], 0);
  45. Screen('Flip', wind);
  46. tSpd = PR650measspd(S);
  47. spd(a,:) = tSpd;
  48. pause(2)
  49. end
  50. Screen('CloseAll')
  51. % analyze the data, start by finding the zero contrast conditions
  52. fundamentals = T_cones_smj';
  53. l_zero = ismember(requested, [0 0 0], 'rows');
  54. spd_zero = spd(l_zero, :);
  55. spd_zero_avg = mean(spd_zero, 1);
  56. bkgndspd = SplineSpd([380, 4, 101], spd_zero_avg(:), S_cones_smj);
  57. bkgndlms = bkgndspd' * fundamentals;
  58. for a = 1:size(spd,1)
  59. tmp_spd = SplineSpd([380, 4, 101], spd(a,:)', S_cones_smj);
  60. tmp_lms = tmp_spd' * fundamentals;
  61. presented(a,:) = (tmp_lms - bkgndlms) ./ bkgndlms;
  62. end
  63. %cycle through the cone isolations and plot (for each cone) the actual vs.
  64. %predicted
  65. signs = sign(requested);
  66. types = [1,0,0; 0,1,0; 0,0,1];
  67. titles = {'L iso', 'M iso', 'S iso'};
  68. colors = {'r.', 'g.', 'b.'};
  69. for a = 1:3
  70. l_cone = ismember(signs, types(a,:), 'rows');
  71. pres_cone = presented(l_cone,:);
  72. req_cone = requested(l_cone,:);
  73. uniqueRequests = unique(req_cone, 'rows');
  74. avgs = [];
  75. stds = [];
  76. for i = 1:size(uniqueRequests,1)
  77. l_type = ismember(req_cone, uniqueRequests(i,:), 'rows');
  78. pres_type = pres_cone(l_type,:);
  79. avgs(:,i) = mean(pres_type,1)';
  80. stds(:,i) = std(pres_type, [], 1)';
  81. end
  82. figure
  83. for i = 1:3
  84. subplot(1,3,i)
  85. errorbar(uniqueRequests(:,a), avgs(i,:), stds(i,:), colors{i});
  86. ymin = min(min(pres_cone(:,i)), 0);
  87. ylim([ymin, max(pres_cone(:,a))])
  88. xlim([0, max(uniqueRequests(:,a))])
  89. if i == 2
  90. title(titles{a})
  91. end
  92. end
  93. subplot(1,3,a)
  94. hold on,
  95. plot([0, max(uniqueRequests(:,a))], [0, max(uniqueRequests(:,a))], 'k')
  96. end