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
Line 64: Line 64:


fov = oiGet(oisH.oiFixed,'fov');
fov = oiGet(oisH.oiFixed,'fov');
emSamples = oisH.length;
emSamples = oisH.length;


cMosaic = coneMosaic;
cMosaic = coneMosaic;
% cMosaic.noiseFlag = true;
cMosaic.noiseFlag = 'none';
cMosaic.integrationTime = 0.001;
cMosaic.integrationTime = 0.001;
cMosaic.setSizeToFOV(0.5*fov);
cMosaic.setSizeToFOV(0.5*fov);
Line 77: Line 78:
%
%
%  
%  
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;
cMosaic.window;


Line 90: Line 95:


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


Line 96: Line 103:
%% 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;


Line 102: Line 111:
% 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(:)));
y = zeros(size(x(:)));
cMosaic.emPositions = [x(:),y(:)];
cMosaic.emPositions = [x(:),y(:)];
[abs_move, curr_move] = cMosaic.compute(oisH,'currentFlag',true);
[abs_move, curr_move] = cMosaic.compute(oisH,'currentFlag',true);
abs_move = squeeze(abs_move);
abs_move = squeeze(abs_move);
curr_move = squeeze(curr_move);
curr_move = squeeze(curr_move);
movement_pos = cMosaic.emPositions;
movement_pos = cMosaic.emPositions;


cMosaic.plot('eye movement path');  % How did we do?
cMosaic.plot('eye movement path');  % How did we do?
set(gca,'xlim',[-15 15],'ylim',[-15 15]);
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
em_noMove.tremor.amplitude = 0.02;  % Set the big amplitude
cMosaic.emGenSequence(tSamples,'em',em_noMove);  % Generate the sequence
cMosaic.emGenSequence(tSamples,'em',em_noMove);  % Generate the sequence
[abs_noMove, curr_noMove] = cMosaic.compute(oisH,'currentFlag',true);
[abs_noMove, curr_noMove] = cMosaic.compute(oisH,'currentFlag',true);
abs_noMove = squeeze(abs_noMove);
abs_noMove = squeeze(abs_noMove);
curr_noMove = squeeze(curr_noMove);
curr_noMove = squeeze(curr_noMove);
noMove_pos = cMosaic.emPositions;
noMove_pos = cMosaic.emPositions;


cMosaic.plot('eye movement path');  % How did we do?
cMosaic.plot('eye movement path');  % How did we do?
set(gca,'xlim',[-15 15],'ylim',[-15 15]);
set(gca,'xlim',[-15 15],'ylim',[-15 15]);
%% plot movement
%% plot movement
figure;
figure;
hold on;
hold on;
plot(1:length(movement_pos),movement_pos,'b');
plot(1:length(movement_pos),movement_pos,'b');
plot(1:length(noMove_pos),noMove_pos,'r');
plot(1:length(noMove_pos),noMove_pos,'r');
hold off;
hold off;
title('eye movement over time');
title('eye movement over time');
xlabel('time (ms)');
xlabel('time (ms)');
ylabel('distance (cone width)');
ylabel('distance (cone width)');




Line 141: Line 179:


%% 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();
figure();
imagesc(H);
imagesc(H);
colorbar;
colorbar;
title('Ratio of total absorptions (with mvmnt / without mvmnt)');
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);
green_indices = find(cMosaic.pattern == 3);
blue_indices = find(cMosaic.pattern == 4);
blue_indices = find(cMosaic.pattern == 4);


avg_ratio_red = sum(sum(H(red_indices)))/numel(H(red_indices));
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_blue = sum(sum(H(blue_indices)))/numel(H(blue_indices));
avg_ratio_green = sum(sum(H(green_indices)))/numel(H(green_indices));
avg_ratio_green = sum(sum(H(green_indices)))/numel(H(green_indices));


ratios = [avg_ratio_red avg_ratio_green avg_ratio_blue];
ratios = [avg_ratio_red avg_ratio_green avg_ratio_blue];
figure();
figure();
C = categorical(ratios,ratios,{'L','M','S'});
C = categorical(ratios,ratios,{'L','M','S'});
h = histogram(C,'BarWidth',0.5);
h = histogram(C,'BarWidth',0.5);
set(gca,'ylim',[0 1.2]);
set(gca,'ylim',[0 1.2]);
title('Ratio of absorption total absorptions by cone type');
title('Ratio of absorption total absorptions by cone type');


% figure();
% figure();

Revision as of 12:57, 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;

% oisH.timeStep

%% 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));