[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Processing Large Memory arrays in Octave under WinXP 32bit
From: |
David Grundberg |
Subject: |
Re: Processing Large Memory arrays in Octave under WinXP 32bit |
Date: |
Fri, 12 Feb 2010 14:07:17 +0100 |
User-agent: |
Thunderbird 2.0.0.23 (X11/20090812) |
Journeaux, Ian wrote:
I am new to Octave (and MatLab for that matter) and I am trying to
evaluate if I can use Octave for a project on a WinXP Pro 32-bit
system. I seem to be running out of memory when I try to run a m-file.
To simplify the troubleshooting I reduced the problem down to
a(3000,3000) = 0;
b=imrotate(a,5);
this gives an error: memory exhausted. I have 2.6Gb for physical memory.
Do I have any options? It would be easier for me to stay with the XP
32bit platform but XP 64-bit or Unix are possibilities.
*/Ian Journeaux/*
I'm doing custom image transformations on 3888x2592 gray-level (and RGB)
images, so I've similar concerns.
The problem isn't about indexing size (so 64-bit wouldn't help), but
with the imrotate call being too memory intensive.
I've written some routines for custom transformations, maybe you find
them useful. I think they might be a little less memory intensive.
Attaching them here. They are not particularly complete or well tested.
Regards,
David
## Copyright (C) 2010 David Grundberg
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this file; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} address@hidden =} imtransform (@var{x},
@var{tform}, @var{interp}, @var{property}, @var{value}, @dots{})
##
## Transform @var{x} according the transformation @var{tform}.
##
## @var{x} is a gray-level image. @var{tform} is a transformation as
## returned by @code{maketform}.
##
## @var{interp} determines what interpolation technique is used. Valid
## choices are, from lowest quality to highest, "nearest", "bilinear"
## and "bicubic". If left out, the default is "bilinear".
##
## The mandatory properties are:
##
## @table @code
##
## @item XData
##
## A vector of length 2. Only codomain (target) X coordinates from
## @var{xdata(1)} to @var{xdata(2)} will be computed.
##
## @item YData
##
## A vector of length 2. Only codomain (target) Y coordinates from
## @var{ydata(1)} to @var{ydata(2)} will be computed.
##
## @end table
##
## @seealso maketform, imread
##
## @end deftypefn
## Image transformation
## Author: David Grundberg <address@hidden>
function y = imtransform (varargin)
if (nargin < 2)
print_usage ();
endif
[x, tform, interp, xdata, ydata] = check_input(varargin);
% find codomain coordinates that we want
[xx, yy] = meshgrid (xdata(1):xdata(2), ydata(1):ydata(2));
codomain = [xx(:), yy(:)];
clear xx yy
% inverse operation, find domain coordinates
domain = tform.inverse_fcn (codomain, tform);
assert (size_equal (codomain, domain));
clear codomain
switch (interp)
case "bilinear"
interp = "linear";
case "bicubic"
interp = "cubic";
endswitch
y = interp2 (x, domain(:, 1), domain(:, 2), interp, nan);
clear domain
y = reshape (y, ydata(2) - ydata(1) + 1, xdata(2) - xdata(1) + 1);
# % nearest neighbor
# domain = round (domain);
# % limit domain to legal values
# valid = (domain(:, 2) >= 1 & domain(:, 2) <= size(x, 1) &
# domain(:, 1) >= 1 & domain(:, 1) <= size(x, 2));
# t = x(sub2ind(size(x), domain(valid, 2), domain(valid, 1)));
# y = nan (ydata(2) - ydata(1) + 1, xdata(2) - xdata(1) + 1);
# y(sub2ind(size(y),
# codomain(valid, 2) - ydata(1) + 1,
# codomain(valid, 1) - xdata(1) + 1)) = t;
endfunction
function [x, tform, interp, xdata, ydata] = check_input(args)
## Defaults
interp = "bilinear";
## xdata and ydata would need to be approximated.
## xdata = [1, size(x, 2)];
## ydata = [1, size(x, 1)];
xdata = [];
ydata = [];
x = args{1};
tform = args{2};
args = args(3:end);
interp_choices = {"nearest", "bilinear", "bicubic"};
if (! isempty (args) && ischar (args{1}) &&
strmatch (lower (args{1}), interp_choices, "exact"))
interp = args{1};
args = args(2:end);
endif
properties = {"xdata", "ydata"};
while (! isempty(args))
if (length (args) < 2 || ! ischar (args{1}))
error ("imtransform: Expecting property/value pairs at end of argument
list.");
endif
word = lower (args{1});
matches = strmatch (word, properties);
if (length (matches) > 1)
error ("imtransform: Ambigious property %s", args {1});
endif
switch (word)
case "xdata"
xdata = args{2};
case "ydata"
ydata = args{2};
case interp_choices
error ("imtransform: %s must appear before other properties", args {1});
otherwise
error ("imtransform: Unknown property %s", args {1});
endswitch
args = args (3:end);
endwhile
if (! isvector (xdata) || length (xdata) != 2)
error ("imtransform: XData must be specified as a vector.");
endif
if (! isvector (ydata) || length (ydata) != 2)
error ("imtransform: YData must be specified as a vector.");
endif
endfunction
## Copyright (C) 2010 David Grundberg
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this file; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} address@hidden =} maketform ("custom",
@var{ndims_in}, @var{ndims_out}, @var{forward_fcn}, @var{inverse_fcn},
@var{tdata})
## @seealso maketform
## @end deftypefn
## Transformation constructor
## Author: David Grundberg <address@hidden>
function tform = maketform (tformtype, varargin)
if (nargin < 1)
print_usage ();
endif
switch (tformtype)
case "custom"
if (nargin != 6)
print_usage ();
endif
if (! integer (varargin{1}) || ! integer (varargin{2}))
error ("maketform: ndims arguments must be scalar integers");
endif
if (! isa (varargin{3}, 'function_handle') ||
! isa (varargin{4}, 'function_handle'))
error ("maketform: function arguments must be function handles");
endif
tform = struct ("ndims_in", varargin{1},
"ndims_out", varargin{2},
"forward_fcn", varargin{3},
"inverse_fcn", varargin{4},
"tdata", varargin{5});
case {"affine", "projective", "composite", "box"}
error ("maketform: %s transforms not implemented", tformtype);
otherwise
print_usage ();
endswitch
endfunction
function ok = integer (value)
ok = isscalar (value) && floor(value) == value;
endfunction
## Copyright (C) 2010 David Grundberg
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this file; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
function B = testtform
tform = maketform ('custom', 2, 2, @t, @it, []);
A = ones (2592, 3888, 3);
B = zeros (2592, 3888, 3, 'uint8');
B(:,:,1) = imtransform (A(:,:,1), tform, 'YData', [1 2592], 'XData', [1
3888]);
B(:,:,2) = imtransform (A(:,:,2), tform, 'YData', [1 2592], 'XData', [1
3888]);
B(:,:,3) = imtransform (A(:,:,3), tform, 'YData', [1 2592], 'XData', [1
3888]);
end
function y = t(x, tform)
angle = 5 / 180 * pi;
y = x * [cos(angle), sin(angle); -sin(angle), cos(angle)];
end
function y = it(x, tform)
angle = -5 / 180 * pi;
y = x * [cos(angle), sin(angle); -sin(angle), cos(angle)];
end