Skip to content

Commit

Permalink
Comments and adjusting for iset_google integration
Browse files Browse the repository at this point in the history
  • Loading branch information
wandell committed Apr 11, 2020
1 parent ff38063 commit ae2a37d
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 60 deletions.
5 changes: 4 additions & 1 deletion opticalimage/raytrace/rtFileNames.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
psfNameList = cell(nHeight,nWave);
for ii=1:nHeight
for jj=1:nWave
psfNameList{ii,jj} = sprintf('%s_2D_PSF_Fld%.0f_Wave%.0f.dat',lensFile,ii,jj);
% Get the full path. We are worried that there may be multiple
% optics with the same basename.
baseName = sprintf('%s_2D_PSF_Fld%.0f_Wave%.0f.dat',lensFile,ii,jj);
psfNameList{ii,jj} = which(baseName);
rtCheckPSFFile(psfNameList{ii,jj});
end
end
Expand Down
34 changes: 14 additions & 20 deletions opticalimage/raytrace/rtImportData.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function [optics, opticsFile] = rtImportData(optics,rtProgram,pFileFull)
%Import data for optics ray trace calculations
% Import data for optics ray trace calculations
%
% Synopsis
% [optics, opticsFile] = rtImportData(optics,rtProgram,pFileFull)
%
% Description:
Expand All @@ -11,8 +12,8 @@
% The ray trace (rt) data are returned as part of the optics structure
% (optics.rt).
%
% Using the GUI (oiWindow), the user can export the optics.rt information
% (oiWindow | Optics | Import Optics).
% Using the GUI (oiWindow), the user can export the optics ray trace
% information (oiWindow | Optics | Import Optics).
%
% If it is exported, then the ray trace it can be imported using the Import
% Optics pull down in the (oiWindow | Optics | Import Optics)
Expand All @@ -36,33 +37,20 @@
%
% See also

% Examples
%{
% Fails - need to make it work properly with a test data set.
% oi = vcGetObject('oi'); optics = oiGet(oi,'optics');
% optics = rtImportData(optics);
% oi = sceneSet(oi,'optics',optics);;
% vcReplaceObject(oi);
%}

% TODO:
%
% We are concerned that at present (4.25.2008) the x,y dimensions of zemax
% are flipped from the x,y of ISET. We think we need to rotate the zemax
% data before storing it.
% Features to consider:
%
% Read the Chief Ray Angle data
%
% Read the header for the psfSpacing (in microns) and interpolate to 0.25
% micron samples or some common size support for the PSF.
%
% All of the rt fields should be set using opticsSet(optics,'rtMumble')
% instead of directly touching the structure, as we do here.
%
% The user should have an opportunity to symmetrize the PSFs w.r.t the
% current sampling grid (rtPSFCenter). They should also be able to
% rotate the data which are normally entered along the y-axis but should be
% entered along the x-axis (I think).


%% Argument checking
if ieNotDefined('rtProgram'), rtProgram = 'zemax'; end
rt.program = rtProgram;
Expand Down Expand Up @@ -148,7 +136,13 @@

% These are full path file names
% [diName,riName,psfNameList] = rtFileNames(baseLensFileName,wave,imgHeight); %#ok<NODEF>
[~,baseName,~] = fileparts(baseLensFileName);
if ismac
% Sometimes people use PCs. So we fix the file string by removing the
% disk drive (e.g., C:) and replacing \ with /.
tmp = strsplit(baseLensFileName,':');
tmp{2} = strrep(tmp{2},'\','/');
end
[~,baseName,~] = fileparts(tmp{2});
[diName,riName,psfNameList] = rtFileNames(baseName,wave,imgHeight); %#ok<NODEF>

%% Load the geometry - needs fixing up.
Expand Down
2 changes: 2 additions & 0 deletions rdt/s_rdtSceneRead.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
% Here is an example remote directory.
rd.crp('/resources/scenes/hyperspectral/stanford_database'); % change remote path

% rd.crp('/resources/scenes/hdr'); % change remote path

% Problems here:
% Currently only returns 30 elements
% 'type' is not right because it says jpg when there are nef and pgm files
Expand Down
2 changes: 1 addition & 1 deletion scene/sceneCrop.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

if ieNotDefined('scene'), error('You must define a scene.'); end

if ieNotDefined('rect'),
if ieNotDefined('rect')
[roiLocs,rect] = vcROISelect(scene);
else
cmin = rect(1); cmax = rect(1)+rect(3);
Expand Down
4 changes: 2 additions & 2 deletions scene/sceneSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@
scene.illuminant = illuminantSet(scene.illuminant,'name',val);
case {'illuminantcomment'}
scene.illuminant.comment = val;
% case {'illuminantspectrum'}
% scene.illuminant.spectrum = val;
case {'illuminantspectrum'}
scene.illuminant.spectrum = val;

case {'rect'}
% scene = sceneSet(scene,'rect',[x y h w]);
Expand Down
35 changes: 0 additions & 35 deletions tutorials/development/t_oiRTGoogle.m

This file was deleted.

2 changes: 1 addition & 1 deletion utility/getMiddleMatrix.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
middleM(:,:,ii) = m(r,c,ii);
end

return;
end

75 changes: 75 additions & 0 deletions utility/ieCropRect.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
function cropRect = ieCropRect(oi,scenesize,fov,newFOV,varargin)
% Calculate a rect to crop a scene from its current fov to a new fov
%
% Synopsis
%
% Inputs
%
% Optional key/value pairs
%
% Returns
%
%
% Only the center for now, though we might add a new center parameter
%
% See also
%

% Examples:
%{
scene = sceneCreate;
oi = oiCreate('ray trace');
sceneSize = sceneGet(scene,'size');
fov = sceneGet(scene,'fov');
newFOV = fov/4;
cropRect = ieCropRect(oi,sceneSize,fov,newFOV);
scene2 = sceneCrop(scene,cropRect);
sceneWindow(scene2);
sceneWindow(scene);
%}

%% Parse input parameters
varargin = ieParamFormat(varargin);

p = inputParser;

p.addRequired('oi',@(x)(isequal(x.type,'opticalimage')));
p.addRequired('scenesize',@isvector);
p.addRequired('fov',@isnumeric);
p.addRequired('newFOV',@isnumeric);

p.addParameter('center',[],@isvector);
p.parse(oi,scenesize,fov,newFOV,varargin{:});

center = p.Results.center;
if isempty(center)
center = floor(scenesize/2);
end

if newFOV > fov
error('New field of view (%f) must not exceed current field of view %f\n',newFOV,fov);
end


%%
% Get the image size and aspect ratio (col/row)
aspectRatio = scenesize(2) / scenesize(1);

%% Calculate the image resolution for half FOV

% Physical width of the scene (meters)
objDistance = oiGet(oi,'optics rt object distance'); % meters

% Calculate width for halfFOV and fullFOV
widthNewFOV = 2 * objDistance * tand(newFOV/2);
widthFOV = 2 * objDistance * tand(fov/2); % Same for the full fov

nColNewFOV = floor(scenesize(2) * widthNewFOV / widthFOV);
nRowNewFOV = floor(nColNewFOV / aspectRatio);

%% Crop image for half FOV from center

start = [floor(center(1) - nRowNewFOV/2), floor(center(2) - nColNewFOV/2)];
cropRect = [start(2) + 1, start(1) + 1, nColNewFOV - 1, nRowNewFOV - 1 ];

end

0 comments on commit ae2a37d

Please sign in to comment.