Skip to content

Commit

Permalink
Working to make the G data analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
wandell committed Jul 24, 2020
1 parent 7d1162d commit 64c77b8
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 14 deletions.
120 changes: 120 additions & 0 deletions sensor/sensorCrop.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
function sensor = sensorCrop(sensor,rect)
% Crop a the sensor data, while preserving the CFA
%
% Synopsis
% sensor = sensorCrop(sensor,rect)
%
% Inputs
% sensor: ISETCam sensor struct
% rect: [x,y,width,height]
%
% Optional variables
%
% Outputs
%
% See also
% sensorSetSizeToFOV, v_sensorSize
%

% Examples:
%{
scene = sceneCreate;
oi = oiCreate;
oi = oiCompute(oi,scene);
sensor = sensorCreate;
sensor = sensorCompute(sensor,oi);
sensorWindow(sensor);
rect = [10 12 13 21];
test = sensorCrop(sensor,rect);
sensorWindow(test);
%}

%% Parameters
if ieNotDefined('sensor'), error('sensor required'); end

% For now. Though we could allow this to be interactive at some point.
if ieNotDefined('rect'), error('crop rect required'); end

%%

% Get the data
cfaSize = sensorGet(sensor,'cfaSize');

% The [x,y, width, height] needs to match the cfaSize. The cfaSize is
% [row,col]. So we need to deal with that.
cfaSize = fliplr(cfaSize);

% If the cfa size is even, then the x and y values should be odd The number
% of entries in numel(x:(x + width)) and numel(y:(y + height)) should be a
% multiple of the cfaSize.
%

%% Select rect values that will preserve the CFA pattern

% Here are some test cases
%{
cfaSize = [2,2]; rect = [ 7 9 6 8]; % 7 9 6 8
cfaSize = [2,2]; rect = [ 8 9 6 8] % 9 9 6 8
cfaSize = [5,3]; rect = [6,10,6,8] % 6 10 10 9
cfaSize = [5,3]; rect = [ 7 10 5 8] % 11 10 5 9
cfaSize = [5,3]; rect = [ 8 11 6 9] % 11 13 10 9
cfaSize = [3,5]; rect = [ 8 11 6 9] % 10 11 6 10
%}

%
% First deal with x = rect(1), width = rect(3).
% Then deal with y = rect(2), height = rect(4)
%
for ii=0:1
% The x value should start on a multiple of the cfaSize plus 1.
thisRem = rem(rect(ii+1),cfaSize(ii+1));
if thisRem ~= 1
if thisRem == 0
rect(ii+1) = rect(ii+1) + 1;
else
% Adjust the starting value by the amount we missed by. which gets
% us to 0 and then add 1.
rect(ii+1) = rect(ii+1) + (cfaSize(ii+1) - thisRem + 1);
end

end
% The total size should be a multiple of the cfaSize
cnt = numel(rect(ii+1):(rect(ii+1) + rect(ii+3)));
if rem(cnt,cfaSize(ii + 1)) % Zero if a proper multiple
% Not an even devisor of the cfaSize. So add an amount needed to
% make it a proper multiple
rect(ii+3) = rect(ii+3) + cfaSize(ii + 1) - rem(cnt,cfaSize(ii+ 1));
end
end

% These are checks that the adjustment worked. Though the width and height
% seem to be off a bit. So we should figure that out and fix it.
assert(rem(rect(1),cfaSize(1)) == 1);
assert(rem(rect(2),cfaSize(2)) == 1);
assert(rem(numel(rect(1):(rect(1) + rect(3))),cfaSize(1)) == 0)
assert(rem(numel(rect(2):(rect(2) + rect(4))),cfaSize(2)) == 0)

%% Crop the voltage image

% Crop the volts
volts = sensorGet(sensor,'volts');
if isempty(volts)
% That's weird. why crop a sensor that has no data? Just resize.
else
newVolts = imcrop(volts,rect);
newSize = size(newVolts);
sensor = sensorSet(sensor,'size',newSize);
sensor = sensorSet(sensor,'volts',newVolts);
end

% Crop the digital values
dv = sensorGet(sensor,'dv');
if ~isempty(dv)
newDV = imcrop(dv,rect);
sensor = sensorSet(sensor,'digital values',newDV);
end

end
11 changes: 7 additions & 4 deletions sensor/sensorSetSizeToFOV.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [sensor,actualFOV] = sensorSetSizeToFOV(sensor,newFOV,scene,oi)
function [sensor,actualFOV] = sensorSetSizeToFOV(sensor,newFOV,~,oi)
% Adjust sensor rows and columns so that horizontal FOV is deg (angle)
%
% Synopsis
Expand Down Expand Up @@ -32,7 +32,8 @@
% size must be a multiple of the cfa size.
%
% The FOV of the sensor depends on the focal length to the optics and the
% size of the sensor. Hence, we normally send in the scene and oi.
% size of the sensor. Hence, we normally send in the oi. We should never
% have to send in the scene and that will be deprecated.
%
% We try to handle the human cone array case, which is special, by catching
% the string 'human' in the name and saying the block size is one. This is
Expand Down Expand Up @@ -64,10 +65,12 @@
[sensor, fov] = sensorSetSizeToFOV(sensor,[3,3],scene,oi);
%}

%%
%% Parameters

% It appears that we do not really need to send in the scene
if ieNotDefined('sensor'), sensor = vcGetObject('sensor'); end
if ieNotDefined('newFOV'), error('Must specify desired horizontal field of view (degrees)'); end
if ieNotDefined('scene'), scene = []; end
% if ieNotDefined('scene'), scene = []; end
if ieNotDefined('oi'), oi = []; end

% Get the size. If size is 0,0 set to a small size. Not sure when it is
Expand Down
24 changes: 14 additions & 10 deletions validate/v_sensorResize.m
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
% v_sensorResize
%
% Resize the sensor

% Test resizing the sensor. Mostly tested with human here.
%
% v_sensorResize
%
% Resize the sensor
% See also
% v_sensorSize (should be merged; that one tests with camera)

%%
ieInit

%% Create a scene and compute an OI
scene = sceneCreate;
vcAddAndSelectObject(scene); sceneWindow;
sceneWindow(scene);

oi = oiCreate;
oi = oiCompute(scene,oi);
Expand All @@ -21,34 +22,37 @@
sensor = sensorCreate('human');
sensor = sensorSet(sensor,'exptime',0.2);
sensor = sensorCompute(sensor,oi);
vcAddAndSelectObject(sensor); sensorWindow('scale',1);
sensorWindow(sensor,'scale',1);

% Something funny happens with the exposure duration.
%% Something funny happens with the exposure duration.
rows = [10,10]; cols = [10,10];
sensor2 = sensorHumanResize(sensor,rows,cols);
sensor2 = sensorSet(sensor2,'exptime',0.2);
sensor2 = sensorCompute(sensor2,oi);
vcAddAndSelectObject(sensor2); sensorWindow;
sensorWindow(sensor2);

%%
rows = [-10,-10]; cols = [-10,-10];
sensor3 = sensorHumanResize(sensor2,rows,cols);
sensor3 = sensorSet(sensor3,'exptime',0.2);
sensor3 = sensorCompute(sensor3,oi);
vcAddAndSelectObject(sensor3);

%%
rows = [50,0]; cols = [0,0];
sensor4 = sensorHumanResize(sensor,rows,cols);
sensor4 = sensorSet(sensor4,'exptime',0.2);
sensor4 = sensorCompute(sensor4,oi);
v = sensorGet(sensor4,'volts');
imagesc(v)
vcAddAndSelectObject(sensor4); sensorWindow;
sensorWindow(sensor4);

%%
rows = [-50,0]; cols = [0,0];
sensor5 = sensorHumanResize(sensor4,rows,cols);
sensor5 = sensorSet(sensor5,'volts',v(51:end,:));
% vcNewGraphWin; v2 = sensorGet(sensor5,'volts'); imagesc(v2)
vcAddAndSelectObject(sensor5); sensorWindow;
sensorWindow(sensor5);

%% END


32 changes: 32 additions & 0 deletions validate/v_sensorSize.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%% v_sensorSize
%
% Test adjusting the sensor field of view and size.
%
% See also
% v_sensor*

%%
scene = sceneCreate;
oi = oiCreate;
oi = oiCompute(oi,scene);
sensor = sensorCreate;
sensor = sensorCompute(sensor,oi);

sensorWindow(sensor);

%%
sensor2 = sensorSetSizeToFOV(sensor,sceneGet(scene,'fov'),[],oi);
sensor2 = sensorCompute(sensor2,oi);
sensorWindow(sensor2);

%% Increase the size this way

sz = sensorGet(sensor2,'size');
sensor3 = sensorSet(sensor,'size',sz);
sensor3 = sensorCompute(sensor3,oi);
sensorWindow(sensor3);

%%



0 comments on commit 64c77b8

Please sign in to comment.