Skip to content

Commit

Permalink
Replaced ieRoi2Locs with ieRect2Locs, which is more correct. Fixed a …
Browse files Browse the repository at this point in the history
…couple of tutorials that (slightly) failed. Upgraded some of the ieROI functions
  • Loading branch information
wandell committed Jan 26, 2020
1 parent b342899 commit e55868b
Show file tree
Hide file tree
Showing 28 changed files with 154 additions and 89 deletions.
2 changes: 1 addition & 1 deletion camera/cameraMTF.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
% h = ieDrawRect(a,rect,[1 0 1],3);
% delete(h)

roiLocs = ieRoi2Locs(rect);
roiLocs = ieRect2Locs(rect);
barImage = vcGetROIData(ip,roiLocs,'results');
c = rect(3)+1;
r = rect(4)+1;
Expand Down
2 changes: 1 addition & 1 deletion gui/chart/chartRectsDraw.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

%% Find corners of the rectangles.

% Should be a function. Used in ieRoi2Locs, also. Possibly other places
% Maybe this should edited to use ieRect2Vertices
cmin = rects(:,1); cmax = rects(:,1)+rects(:,3);
rmin = rects(:,2); rmax = rects(:,2)+rects(:,4);

Expand Down
3 changes: 2 additions & 1 deletion gui/roi/ieLocs2Rect.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
% roiLocs2 = ieLocs2Rect(rect);
% isequal(roiLocs,roiLocs2)
%
% See also: ieGetXYCoords, ieRoi2Locs, vcROISelect, vcLineSelect, vcPointSelect
% See also:
% ieGetXYCoords, ieRect2Locs, vcROISelect, vcLineSelect, vcPointSelect
%
% (c) Imageval Consulting, LLC 2012

Expand Down
26 changes: 26 additions & 0 deletions gui/roi/ieROICreate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function roi = ieRoiCreate(varargin)
% Create an ROI struct
%
% Syntax
% roi = ieRoiCreate(varargin)
%
% Description
% We are starting to create and show more ROIs, storing them in the ip,
% sensor, oi, and scene windows. This is just the initial development of
% that code.
%
% Also, we need to do some more work integrating all of the ROI functions
% in the gui/roi directory. There will be an ieRoiSet/Get/Plot
%
% Inputs
%
% Optional key/value pairs
%
% Returns
% roi - a struct, though maybe it will become an roi class
%
% Wandell, January 25 2020
%
% See also
% vcROISelect; ieROIDraw, ieRect2Locs

61 changes: 44 additions & 17 deletions gui/roi/ieROISelect.m
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
function [roiLocs,rect] = ieROISelect(obj,objFig)
function [roiLocs,rect] = ieROISelect(obj,objFig,varargin)
% Select a region of interest (ROI) from an image and calculate locations
%
% [roiLocs,rect] = ieROISelect(obj,[objFig])
% Syntax
% [roiLocs,rect] = ieROISelect(obj,[objFig],varargin)
%
% Description
% The row and col locations of the region of interest (ROI) are returned
% in the Nx2 matrix, roiLocs.
%
% If requested, the selected rectangle (rect) determining the region of
% interest, [colmin,rowmin,width,height], is also returned.
%
% Example:
% ip = ieGetObject('ip');
% [roiLocs, rect] = ieROISelect(ip);
% iData = ieROISelect(vci,roiLocs,'results');
% Input
% obj - An ISETCam structure (scene, oi, sensor, ip)
%
% See also: ieRoi2Locs
% Optional key/val pairs
%
% Return
% roiLocs
% rect
%
% Copyright ImagEval Consultants, LLC, 2005.
%
% See also:
% ieRoiDraw, ieRect2Locs, ieRoiCreate

% TODO: See proposal for ieOpenWindow below. We should also add
% ieRoiSelect to plan for deprecation of the vcXXX routines.
% Examples:
%{
scene = sceneCreate; sceneWindow(scene);
[~,rect] = ieROISelect(scene);
r = ieROIDraw('scene','shape','rect','shape data',rect);
delete(r);
%}
%{
ip = ieGetObject('ip');
[roiLocs, rect] = ieROISelect(ip);
r = ieROIDraw('ip','shape','rect','shape data',rect);
%}
%{
ip = ieGetObject('ip');
ip = ipSet(ip,'roi',rect);
ipPlot(ip,'roi');
%}

%%
if ieNotDefined('obj'), error('You must define an object (isa,oi,scene ...)'); end
if ieNotDefined('objFig')
objFig = vcGetFigure(obj);
objFig = vcGetFigure(obj);

% If the returned figure is empty, the user probably did not set up the
% object window yet. So we add the object to the database and open the
% window
if isempty(objFig)
% We should add ieAddAndSelect()
ieAddObject(obj);
% ieAddObject(obj);
% Should become ieOpenWindow(obj)
switch obj.type
case 'scene'
objFig = sceneWindow;
objFig = sceneWindow(obj);
case 'opticalimage'
objFig = oiWindow;
objFig = oiWindow(obj);
case 'sensor'
objFig = sensorWindow;
objFig = sensorWindow(obj);
case 'vcimage'
objFig = ipWindow;
objFig = ipWindow(obj);
otherwise
error('Unknown obj type %s\n',obj.type);
end
Expand All @@ -61,7 +88,7 @@
end

% Transform the rectangle into ROI locations
roiLocs = ieRoi2Locs(rect);
roiLocs = ieRect2Locs(rect);

return;
end

14 changes: 5 additions & 9 deletions gui/roi/ieRect2Locs.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
% rect = round(getrect(ieSessionGet('ipwindow')));
% roiLocs = ieRect2Locs(rect);
%
% Usually we call the routine vcROISelect directly, which calls this
% Usually we call the routine ieROISelect directly, which calls this
% routine:
% vci = vcGetObject('vcimage');
% [roiLocs roiRect] = vcROISelect(vci);
%
%
% See also: Uh oh, there is a routine ieROI2Locs which looks pretty much
% like this one.
%
% (c) Imageval, 2004
% See also: vcROISelect(), ieLocs2Rect
%
% See also:
% ieROISelect, ieLocs2Rect
%

% The rect entries are (colMin,rowMin,colWidth-1,rowWidth-1)
Expand All @@ -36,4 +32,4 @@
[c,r] = meshgrid(cmin:cmax,rmin:rmax);
roiLocs = [r(:),c(:)];

return;
end
8 changes: 7 additions & 1 deletion gui/roi/ieRoi2Locs.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function roiLocs = ieRoi2Locs(rect)
% Should be called ieRect2Locs
% ****** Deprecated: Call ieRect2Locs *****
%
% roiLocs = ieRoi2Locs(rect)
%
Expand All @@ -23,7 +23,12 @@
% vcROISelect(), ieLocs2Rect
%

warning('Call ieRect2Locs, not ieRoi2Locs. This routine is deprecated.');
roiLocs = ieRect2Locs(rect);

end

%{
% The rect entries are The number of data
% values are colMax - colMin +1 and similarly for the row
cmin = rect(1); cmax = rect(1)+rect(3);
Expand All @@ -33,3 +38,4 @@
roiLocs = [r(:),c(:)];
return;
%}
2 changes: 1 addition & 1 deletion gui/roi/vcGetROIData.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
elseif size(roiLocs,2) == 4
% The user sent a rect. Convert to roiLocs.
% Be alert to the problem of the rect size in comments, above
roiLocs = ieRoi2Locs(roiLocs);
roiLocs = ieRect2Locs(roiLocs);
end

%%
Expand Down
7 changes: 3 additions & 4 deletions gui/roi/vcROISelect.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
% [roiLocs, rect] = vcROISelect(vci);
% iData = vcGetROIData(vci,roiLocs,'results');
%
% See also: ieRoi2Locs
% See also: ieRect2Locs
%
% Copyright ImagEval Consultants, LLC, 2005.

Expand Down Expand Up @@ -61,7 +61,6 @@
end

% Transform the rectangle into ROI locations
roiLocs = ieRoi2Locs(rect);

return;
roiLocs = ieRect2Locs(rect);

end
37 changes: 24 additions & 13 deletions gui/vcGetFigure.m
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
function figNum = vcGetFigure(obj)
% Return the figure number associated with an object.
%
% figNum = vcGetFigure(obj)
% Syntax
% figNum = vcGetFigure(obj)
%
% Possible ISET objects are scene, opticalimage, isa, vcimage. This
% routine allows us to get the figure number when the object type is not
% identified in the main routine, such as getting an ROI for an oi,
% Description
% Get the figure handle to one of the ISETCam windows. Possible ISET
% objects are scene, oi, sensor, ip.
%
% This routine allows us to get the figure number when the object type is
% not identified in the main routine, such as getting an ROI for an oi,
% scene, sensor or other type of window.
%
% There is a separate routine for GraphWins. But I am not sure why.
%
% Examples:
% figNum = vcGetFigure(obj)
% figure(figNum);
% handles = guihandle(figNum);
%
% Copyright ImagEval Consultants, LLC, 2005.
%
% See also
% vcEquivalentObjtype, vcGetObjectType

% Examples:
%{
scene = sceneCreate; sceneWindow(scene);
figNum = vcGetFigure(scene)
figure(figNum);
handles = guihandles(figNum);
%}

% global vcSESSION;

%%
objType = vcGetObjectType(obj);

% Forces the objType string to one of original names below.
objType = vcEquivalentObjtype(objType);

hdl = [];
% hdl = [];
switch lower(objType)
case 'scene'
figNum = ieSessionGet('scenewindow');
Expand All @@ -37,4 +48,4 @@
error('Unknown object type.');
end

return;
end
2 changes: 1 addition & 1 deletion imgproc/vcimageVSNR.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

% Select the ROI from the vcimage window
if ieNotDefined('rect'), [roiLocs,rect] = vcROISelect(vci);
else roiLocs = ieRoi2Locs(rect);
else, roiLocs = ieRect2Locs(rect);
end
% a = get(ipWindow,'CurrentAxes'); hold(a,'on'); ieDrawRect(a,rect)
% Convert the data to an XYZ image
Expand Down
4 changes: 2 additions & 2 deletions metrics/ISO/ISO12233.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
%The whole thing and cpd assuming a 1m viewing distance
rectMTF = [xmin ymin width height];
c = rectMTF(3)+1; r = rectMTF(4)+1;
roiMTFLocs = ieRoi2Locs(rectMTF);
roiMTFLocs = ieRect2Locs(rectMTF);
barImage = vcGetROIData(vciBlurred,roiMTFLocs,'results');
barImage = reshape(barImage,r,c,3);
wgts = [ 0.3 0.6 0.1];
Expand Down Expand Up @@ -98,7 +98,7 @@
% The barImage is really the image processor (ip)
ip = barImage;
rect = ISOFindSlantedBar(ip);
roiLocs = ieRoi2Locs(rect);
roiLocs = ieRect2Locs(rect);
barImage = vcGetROIData(ip,roiLocs,'results');
col = rect(3)+1;
row = rect(4)+1;
Expand Down
5 changes: 2 additions & 3 deletions scene/macbeth/macbethROIs.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
rect(3) = delta;
rect(4) = delta;

patchLocs = ieRoi2Locs(rect);

return;
patchLocs = ieRect2Locs(rect);

end
4 changes: 2 additions & 2 deletions scene/reflectance/chartROI.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
% Copyright ImagEval Consultants, LLC, 2014
%
% See also:
% chartPatchData, chartRectangles,ieRoi2Locs
% chartPatchData, chartRectangles,ieRect2Locs

%%
if ieNotDefined('currentLoc'), error('current location in chart is required'); end
Expand All @@ -35,7 +35,7 @@
rect(4) = delta;

%% Convert the rect into the positions
patchLocs = ieRoi2Locs(rect);
patchLocs = ieRect2Locs(rect);

end

2 changes: 1 addition & 1 deletion scene/reflectance/chartRectangles.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

%% The rectangles

% You can use ieRoi2Locs to return the locations within the rects
% You can use ieRect2Locs to return the locations within the rects
nPatches = size(mLocs,2);
rects = zeros(nPatches,4);
for ii=1:nPatches
Expand Down
2 changes: 1 addition & 1 deletion scene/sceneGet.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
% We should also implement:
% r = sceneGet(scene,'mean reflectance',roiRect);
%
% radiance = vcGetROIData(scene,ieRoi2Locs(rect),'photons');
% radiance = vcGetROIData(scene,ieRect2Locs(rect),'photons');
% illuminantSPD = sceneGet(scene,'illuminant photons');
% reflectance = radiance*diag(1./illuminantSPD);
% reflectance = mean(reflectance);
Expand Down
2 changes: 1 addition & 1 deletion scene/sceneSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
if isempty(varargin), error('ROI required')
else, roi = varargin{1};
end
if size(roi,2) == 4, roiLocs = ieRoi2Locs(roi);
if size(roi,2) == 4, roiLocs = ieRect2Locs(roi);
else, roiLocs = roi;
end

Expand Down
2 changes: 1 addition & 1 deletion scripts/metrics/s_metricsMTFPixelSize.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
% ipWindow;

rect = round(masterRect/pSize(ii));
roiLocs = ieRoi2Locs(rect);
roiLocs = ieRect2Locs(rect);

barImage = vcGetROIData(ip,roiLocs,'results');
c = rect(3)+1;
Expand Down
Loading

0 comments on commit e55868b

Please sign in to comment.