Passing individual varargin arguments from one function to another
Show older comments
I'd like to make a wrapper around regionprops and am having trouble passing the arguments along.
This isn't a problem specific to regionprops but is more about trying to wrap a function that has varargin for input and retaining the flexibility.
regionprops has varargin for input: regionprops(varargin) One possible input is a labeled matrix.
I'd like to write a wrapper where I can modify that label matrix and then pass everything along to regionprops - essentially substituting my new matrix for varargin{1} but keeping everything else the same.
The rationale is that if the biggest label is really big but there are a lot of missing labels, regionprops is really slow.
If the labeled objects are not connected (mine aren't) then I can make it much faster by relabeling the objects with 1:#objects, calling regionprops on this labeled matrix, and then reconstructing the statistics for the original labels. I can do this by adding a few lines in a copy of the regionprops function itself, but I'd prefer to leave it alone and just wrap it.
But the problem is:
-----
rps=myWrapper(L,'Area','FilledImage','Centroid');
function modifiedStatsOut=myWrapper(varargin)
...
varargin{1}=modifiedLabelMatrix;
statsOut=regionprops(varargin);
-----
this fails because instead of varargin being a 1x4 cell as it is when passed into myWrapper, it is a 1x1 cell when it gets into regionprops
Thanks for any help, Scott
Accepted Answer
More Answers (1)
David Young
on 1 Feb 2015
You need
statsOut=regionprops(varargin{:});
which passes the contents of varargin as a comma-separated list.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!