Absorptions Code: Difference between revisions

From Psych 221 Image Systems Engineering
Jump to navigation Jump to search
imported>Student2016
No edit summary
imported>Student2016
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 8: Line 8:


%% Init Parameters
%% Init Parameters
 
    ieInit;
ieInit;
 
%% Here is a new function: oisCreate
%% Here is a new function: oisCreate


Line 19: Line 17:
% Gaussian onset and offset of the grating
% Gaussian onset and offset of the grating


tSeries = ieScale(fspecial('gaussian',[1,100],10),0,1);
    tSeries = ieScale(fspecial('gaussian',[1,100],10),0,1);


%
%
Line 27: Line 25:
% This is the field of view of the scene.
% This is the field of view of the scene.


sparams.fov = 0.5;
    sparams.fov = 0.5;
sparams.meanluminance = 200;
    sparams.meanluminance = 200;


% Initialize the harmonic parameters structure with default
% Initialize the harmonic parameters structure with default
% Change entries that are common to uniform and harmonic
% Change entries that are common to uniform and harmonic


clear params
    clear params
for ii=2:-1:1
    for ii=2:-1:1
    params(ii) = harmonicP;  
        params(ii) = harmonicP;  
    params(ii).GaborFlag = 0.15;
        params(ii).GaborFlag = 0.15;
    params(ii).freq      = 30;
        params(ii).freq      = 30;
end
    end


% params(1) is for the uniform field
% params(1) is for the uniform field
 
    params(1).contrast  = 0.5;  % contrast of the two frequencies
params(1).contrast  = 0.5;  % contrast of the two frequencies
 
% params(2) is matched and describes the grating
% params(2) is matched and describes the grating
 
    params(2).contrast = 0.4;
params(2).contrast = 0.4;
    len = length(tSeries);
 
len = length(tSeries);


% The call to create the optical image sequence
% The call to create the optical image sequence
 
    oisH = oisCreate('harmonic','blend',tSeries(len/2:len/2+1),'testParameters',params,'sceneParameters',sparams);
oisH = oisCreate('harmonic','blend',tSeries(len/2:len/2+1),'testParameters',params,'sceneParameters',sparams);
 
% Have a look, though the code here is not that great yet so the look is
% Have a look, though the code here is not that great yet so the look is
% only approximate.
% only approximate.
 
    oisH.visualize;
oisH.visualize;
 
% oisH.timeStep


%% Now, make the cone mosaic and compute absorptions and current
%% Now, make the cone mosaic and compute absorptions and current


fov = oiGet(oisH.oiFixed,'fov');
    fov = oiGet(oisH.oiFixed,'fov');
 
    emSamples = oisH.length;
emSamples = oisH.length;
    cMosaic = coneMosaic;
 
    cMosaic.noiseFlag = 'none';
cMosaic = coneMosaic;
    cMosaic.integrationTime = 0.001;
cMosaic.noiseFlag = 'none';
    cMosaic.setSizeToFOV(0.5*fov);
cMosaic.integrationTime = 0.001;
cMosaic.setSizeToFOV(0.5*fov);


% The number of eye movement samples should extend as long as the oisH
% The number of eye movement samples should extend as long as the oisH
Line 79: Line 66:
%  
%  


tSamples = floor(oisH.length*oisH.timeStep/cMosaic.integrationTime);
    tSamples = floor(oisH.length*oisH.timeStep/cMosaic.integrationTime);
 
    cMosaic.emGenSequence(tSamples);
cMosaic.emGenSequence(tSamples);


% Compute and then look
% Compute and then look
 
    cMosaic.compute(oisH);
cMosaic.compute(oisH);
    cMosaic.window;
 
    fprintf('Spatial frequency %.1f cpd\n',params(ii).freq/sparams.fov);
cMosaic.window;
 
fprintf('Spatial frequency %.1f cpd\n',params(ii).freq/sparams.fov);
 


%% Create the current with and without noise
%% Create the current with and without noise


% cMosaic.os.noiseFlag = true;
% cMosaic.os.noiseFlag = true;
 
    cMosaic.computeCurrent;
cMosaic.computeCurrent;
    cMosaic.window;
 
cMosaic.window;
 


%% Compute and look at the current
%% Compute and look at the current
% cMosaic.os.noiseFlag = false;
% cMosaic.os.noiseFlag = false;
 
    cMosaic.computeCurrent;
cMosaic.computeCurrent;
    cMosaic.window;
 
cMosaic.window;


%% How to adjust the eye movement parameters
%% How to adjust the eye movement parameters
% create simple sinusoidal eye movement
% create simple sinusoidal eye movement
emF = 3; emA = 3;
    emF = 3; emA = 3;
 
    x = round(emA*sin(2*pi*emF*(1:tSamples)/tSamples));
x = round(emA*sin(2*pi*emF*(1:tSamples)/tSamples));
    y = zeros(size(x(:)));
 
    cMosaic.emPositions = [x(:),y(:)];
y = zeros(size(x(:)));
    [abs_move, curr_move] = cMosaic.compute(oisH,'currentFlag',true);
 
    abs_move = squeeze(abs_move);
cMosaic.emPositions = [x(:),y(:)];
    curr_move = squeeze(curr_move);
 
    movement_pos = cMosaic.emPositions;
[abs_move, curr_move] = cMosaic.compute(oisH,'currentFlag',true);
    cMosaic.plot('eye movement path');  % How did we do?
 
    set(gca,'xlim',[-15 15],'ylim',[-15 15]);
abs_move = squeeze(abs_move);
 
curr_move = squeeze(curr_move);
 
movement_pos = cMosaic.emPositions;
 
 
cMosaic.plot('eye movement path');  % How did we do?
 
set(gca,'xlim',[-15 15],'ylim',[-15 15]);
 


% no tremor
% no tremor
em_noMove = emCreate;    % Create an eye movement object
    em_noMove = emCreate;    % Create an eye movement object
 
    em_noMove.emFlag = [0 0 0];  % Make sure tremor, draft and saccade are all on
em_noMove.emFlag = [0 0 0];  % Make sure tremor, draft and saccade are all on
    em_noMove.tremor.amplitude = 0.02;  % Set the big amplitude
 
    cMosaic.emGenSequence(tSamples,'em',em_noMove);  % Generate the sequence
em_noMove.tremor.amplitude = 0.02;  % Set the big amplitude
    [abs_noMove, curr_noMove] = cMosaic.compute(oisH,'currentFlag',true);
 
    abs_noMove = squeeze(abs_noMove);
cMosaic.emGenSequence(tSamples,'em',em_noMove);  % Generate the sequence
    curr_noMove = squeeze(curr_noMove);
 
    noMove_pos = cMosaic.emPositions;
[abs_noMove, curr_noMove] = cMosaic.compute(oisH,'currentFlag',true);
    cMosaic.plot('eye movement path');  % How did we do?
 
    set(gca,'xlim',[-15 15],'ylim',[-15 15]);
abs_noMove = squeeze(abs_noMove);
 
curr_noMove = squeeze(curr_noMove);
 
noMove_pos = cMosaic.emPositions;
 
 
cMosaic.plot('eye movement path');  % How did we do?
 
set(gca,'xlim',[-15 15],'ylim',[-15 15]);


%% plot movement
%% plot movement
 
    figure;
figure;
    hold on;
 
    plot(1:length(movement_pos),movement_pos,'b');
hold on;
    plot(1:length(noMove_pos),noMove_pos,'r');
 
    hold off;
plot(1:length(movement_pos),movement_pos,'b');
    title('eye movement over time');
 
    xlabel('time (ms)');
plot(1:length(noMove_pos),noMove_pos,'r');
    ylabel('distance (cone width)');
 
hold off;
 
title('eye movement over time');
 
xlabel('time (ms)');
 
ylabel('distance (cone width)');
 




Line 179: Line 126:


%% absorption level comparison
%% absorption level comparison
 
    H = sum(abs_move,3)./sum(abs_noMove,3);
H = sum(abs_move,3)./sum(abs_noMove,3);
    figure();
 
    imagesc(H);
figure();
    colorbar;
 
    title('Ratio of total absorptions (with mvmnt / without mvmnt)');
imagesc(H);
 
colorbar;
 
title('Ratio of total absorptions (with mvmnt / without mvmnt)');


% figure();
% figure();
% imagesc(sum(abs_noMove,3));
% imagesc(sum(abs_noMove,3));
avg_ratio = sum(sum(H))/numel(H)
avg_ratio = sum(sum(H))/numel(H)


%% Separate cone types
%% Separate cone types
% calculate absorption sums for R,G,B cones  
% calculate absorption sums for R,G,B cones  
 
    red_indices = find(cMosaic.pattern == 2);
red_indices = find(cMosaic.pattern == 2);
    green_indices = find(cMosaic.pattern == 3);
 
    blue_indices = find(cMosaic.pattern == 4);
green_indices = find(cMosaic.pattern == 3);
    avg_ratio_red = sum(sum(H(red_indices)))/numel(H(red_indices));
 
    avg_ratio_blue = sum(sum(H(blue_indices)))/numel(H(blue_indices));
blue_indices = find(cMosaic.pattern == 4);
    avg_ratio_green = sum(sum(H(green_indices)))/numel(H(green_indices));
 
    ratios = [avg_ratio_red avg_ratio_green avg_ratio_blue];
 
    figure();
avg_ratio_red = sum(sum(H(red_indices)))/numel(H(red_indices));
    C = categorical(ratios,ratios,{'L','M','S'});
 
    h = histogram(C,'BarWidth',0.5);
avg_ratio_blue = sum(sum(H(blue_indices)))/numel(H(blue_indices));
    set(gca,'ylim',[0 1.2]);
 
    title('Ratio of absorption total absorptions by cone type');
avg_ratio_green = sum(sum(H(green_indices)))/numel(H(green_indices));
 
 
ratios = [avg_ratio_red avg_ratio_green avg_ratio_blue];
 
figure();
 
C = categorical(ratios,ratios,{'L','M','S'});
 
h = histogram(C,'BarWidth',0.5);
 
set(gca,'ylim',[0 1.2]);
 
title('Ratio of absorption total absorptions by cone type');





Latest revision as of 13:06, 16 December 2016

%% Create harmonic sequences % % Make the images of harmonics % Compute the cone mosaic responses and photocurrent responses % Show how to control eye movements % %

%% Init Parameters

   ieInit;

%% Here is a new function: oisCreate

% We are going to mix a grating (harmonic) with a uniform background. % These are the relative weights of the grating and background. % Set up the timing

% Gaussian onset and offset of the grating

   tSeries = ieScale(fspecial('gaussian',[1,100],10),0,1);

% % Have a look at the stimulus amplitude time series % vcNewGraphWin; plot(stimWeights);

% This is the field of view of the scene.

   sparams.fov = 0.5;
   sparams.meanluminance = 200;

% Initialize the harmonic parameters structure with default % Change entries that are common to uniform and harmonic

   clear params
   for ii=2:-1:1
       params(ii) = harmonicP; 
       params(ii).GaborFlag = 0.15;
       params(ii).freq      = 30;
   end

% params(1) is for the uniform field

   params(1).contrast  = 0.5;  % contrast of the two frequencies

% params(2) is matched and describes the grating

   params(2).contrast = 0.4;
   len = length(tSeries);

% The call to create the optical image sequence

   oisH = oisCreate('harmonic','blend',tSeries(len/2:len/2+1),'testParameters',params,'sceneParameters',sparams);

% Have a look, though the code here is not that great yet so the look is % only approximate.

   oisH.visualize;

%% Now, make the cone mosaic and compute absorptions and current

   fov = oiGet(oisH.oiFixed,'fov');
   emSamples = oisH.length;
   cMosaic = coneMosaic;
   cMosaic.noiseFlag = 'none';
   cMosaic.integrationTime = 0.001;
   cMosaic.setSizeToFOV(0.5*fov);

% The number of eye movement samples should extend as long as the oisH % So these should be equal % % tSamples * cMosaic.integrationTime = oisH.length*oisH.timeStep % %

   tSamples = floor(oisH.length*oisH.timeStep/cMosaic.integrationTime);
   cMosaic.emGenSequence(tSamples);

% Compute and then look

   cMosaic.compute(oisH);
   cMosaic.window;
   fprintf('Spatial frequency %.1f cpd\n',params(ii).freq/sparams.fov);

%% Create the current with and without noise

% cMosaic.os.noiseFlag = true;

   cMosaic.computeCurrent;
   cMosaic.window;

%% Compute and look at the current % cMosaic.os.noiseFlag = false;

   cMosaic.computeCurrent;
   cMosaic.window;

%% How to adjust the eye movement parameters % create simple sinusoidal eye movement

   emF = 3; emA = 3;
   x = round(emA*sin(2*pi*emF*(1:tSamples)/tSamples));
   y = zeros(size(x(:)));
   cMosaic.emPositions = [x(:),y(:)];
   [abs_move, curr_move] = cMosaic.compute(oisH,'currentFlag',true);
   abs_move = squeeze(abs_move);
   curr_move = squeeze(curr_move);
   movement_pos = cMosaic.emPositions;
   cMosaic.plot('eye movement path');  % How did we do?
   set(gca,'xlim',[-15 15],'ylim',[-15 15]);

% no tremor

   em_noMove = emCreate;     % Create an eye movement object
   em_noMove.emFlag = [0 0 0];  % Make sure tremor, draft and saccade are all on
   em_noMove.tremor.amplitude = 0.02;  % Set the big amplitude
   cMosaic.emGenSequence(tSamples,'em',em_noMove);  % Generate the sequence
   [abs_noMove, curr_noMove] = cMosaic.compute(oisH,'currentFlag',true);
   abs_noMove = squeeze(abs_noMove);
   curr_noMove = squeeze(curr_noMove);
   noMove_pos = cMosaic.emPositions;
   cMosaic.plot('eye movement path');  % How did we do?
   set(gca,'xlim',[-15 15],'ylim',[-15 15]);

%% plot movement

   figure;
   hold on;
   plot(1:length(movement_pos),movement_pos,'b');
   plot(1:length(noMove_pos),noMove_pos,'r');
   hold off;
   title('eye movement over time');
   xlabel('time (ms)');
   ylabel('distance (cone width)');


%% check to see if absorptions were actually computed differently % t = 1:size(abs_move,3); % plot(t,squeeze(abs_noMove(45,45,:)),t,squeeze(abs_move(45,45,:)));

%% absorption level comparison

   H = sum(abs_move,3)./sum(abs_noMove,3);
   figure();
   imagesc(H);
   colorbar;
   title('Ratio of total absorptions (with mvmnt / without mvmnt)');

% figure(); % imagesc(sum(abs_noMove,3)); avg_ratio = sum(sum(H))/numel(H)

%% Separate cone types % calculate absorption sums for R,G,B cones

   red_indices = find(cMosaic.pattern == 2);
   green_indices = find(cMosaic.pattern == 3);
   blue_indices = find(cMosaic.pattern == 4);
   avg_ratio_red = sum(sum(H(red_indices)))/numel(H(red_indices));
   avg_ratio_blue = sum(sum(H(blue_indices)))/numel(H(blue_indices));
   avg_ratio_green = sum(sum(H(green_indices)))/numel(H(green_indices));
   ratios = [avg_ratio_red avg_ratio_green avg_ratio_blue];
   figure();
   C = categorical(ratios,ratios,{'L','M','S'});
   h = histogram(C,'BarWidth',0.5);
   set(gca,'ylim',[0 1.2]);
   title('Ratio of absorption total absorptions by cone type');


% figure(); % subplot(3,1,1); % plot(1:length(red_indices),H(red_indices)); % subplot(3,1,2); % plot(1:length(green_indices),H(green_indices)); % subplot(3,1,3); % plot(1:length(blue_indices),H(blue_indices));