Reputation: 1715
I have to convert my Matlab function to a standalone application. I build it using the Matlab build tool, that part is ok. However, I get a dimagree error while running my standalone program, even if it works just fine in Matlab; here the code which seems to be wrong :
% INITIALISATIONS
% find connected components
cc = bwconncomp(bw);
% find areas and centroids
stats = regionprops(cc, 'Area','Centroid');
% keep only the particles in the right dimensions
all_areas = cat(1, stats(:).Area);
idx = zeros(size(all_areas));
fprintf('\nSize all_areas : %d %d \n',size(all_areas,1), size(all_areas,2));
fprintf('\nSize idx : %d %d \n',size(idx,1), size(idx,2));
fprintf('\nProgram paused. Press enter to continue.\n');
pause;
idx = all_areas > minArea & all_areas < maxArea;
Error shows up at the last line of the above code. I get :
??? Error using lt
Matrix dimensions must agree.
Error in ==> stats at 46
Error in ==> statPart at 83
MATLAB:dimagree
As you can see, I tried to initialize idx with zeros(), and I output the size of idx and all_areas, they are the same when I run the program. So I'm out of idea now, I really need help here...
[EDIT]
Here is the code I use to handle statPart function inputs :
function [BW2,stat] = statPart(varargin)
i = 1;
while i<=length(varargin),
argok = 1;
if ischar(varargin{i}),
switch varargin{i},
% argument IDs
case 'minArea', i = i+1; minArea = varargin{i};
case 'maxArea', i = i+1; maxArea = varargin{i};
case 'subImgSize', i = i+1; subImgSize = varargin{i};
case 'image', i = i+1; Igray = varargin{i};
otherwise argok = 0;
end
else
argok = 0;
end
if ~argok,
disp(['(statPart) Argument invalide ignore #' num2str(i+1)]);
end
i = i+1;
end
Thank you!
Upvotes: 0
Views: 574
Reputation: 32930
The error message states that he problem arises in lt
(the less-than comparison) of this line:
idx = all_areas > minArea & all_areas < maxArea;
because minArea
and maxArea
are not of the same dimensions all_areas
. They either have to be of size(all_areas)
or scalars, which they are not.
From your check, minArea
and maxArea
are [50 48 48]
, which is the ASCII equivalent of "200". They are received as strings from the command line, and you should use str2num
to convert them into numbers before you handle their values.
I don't understand, however, why they are not equal to your input strings "2" and "20000". How are you parsing your input parameters? That would be a good place to start looking for the problem, but without additional information I won't be able to help you further.
Also, you mention in the comments that disPart
calls statPart
. What is disPart
, and what is its relation to statPart
?
Upvotes: 1