How to use this code?

1 view (last 30 days)
Dinyar
Dinyar on 24 Mar 2012
Commented: Ryan liu on 13 Jun 2020
I have obtained some code for image comparison. A function 'correspondPixels' is called during the process but the code in the .m file is all commented out. There is a correspondPixels.cc file but it has too many errors when I try to mex it so I was hoping the correspondPixels.m file would work. I uncommented it and added 'function' at the start as shown below, however, I get an error when this function is called:
??? Undefined function or variable "match1".
Error in ==> correspondPixels at 30 length(find(match1)) + length(find(match2))
Any help would be much appreciated!
-Dinyar
Code:
function [match1,match2,cost,oc] = correspondPixels(bmap1,bmap2,maxDist,outlierCost)
%
% Compute minimum-cost correspondance between two boundary maps.
%
% The cost of corresponding two pixels is equal to their Euclidean
% distance. Two pixels with dist>maxDist cannot be corresponded,
% with cost equal to outlierCost.
%
% INPUTS
% bmap1 MxN matrix, 1=boundary, 0=non-boundary.
% bmap2 MxN matrix.
% [maxDist=0.01] Maximum distance allowed between matched
% pixels, as a fraction of the image diagonal.
% [outlierCost=100]
% Cost of not matching a pixel, as a multiple
% of maxDist.
%
% OUTPUTS
% match1 MxN integer matrix of correspondances for map1.
% match2 MxN integer matrix of correspondances for map2.
% [cost] The cost of the assignment.
% [oc] The outlier cost in units of pixels.
%
% The output match matrices provide indices of the correspondance, as
% given by sub2ind. Indices of zero denote outliers. The following
% expressions may be useful:
%
length(find(bmap1)) + length(find(bmap2))
%The number of pixels to match.
length(find(match1)) + length(find(match2))
%The number of corresponded pixels.
length(find(bmap1&~match1)) + length(find(bmap2&~match2))
%The number of outliers.
[find(match1) match1(find(match1))]
%Kx2 list of the K assignment edges.
sortrows([match2(find(match2)) find(match2)])
%The same Kx2 list of assignment edges.
cost - oc * (length(find(bmap1&~match1)) + length(find(bmap2&~match2)))
% The assignment cost discluding outliers.
%
% See also csaAssign.
%
% David Martin <dmartin@eecs.berkeley.edu>
% January 2003
  1 Comment
Ryan liu
Ryan liu on 13 Jun 2020
Heyyyyy! Do you resolve this problem? I also met this one when do benchmarks in BSDS500 dataset. Could you please give me some help plz? :P

Sign in to comment.

Answers (1)

Wayne King
Wayne King on 24 Mar 2012
I think we're missing something here because match1 and match2 are supposed to be output arguments of the function you show, but they are used inside of the function before they have any value assigned to them.
length(find(match1)) + length(find(match2))
The above line occurs before match1 and match2 are computed. Because they are not computed inside the function, nor are they input arguments, you get the error you see.
  1 Comment
Dinyar
Dinyar on 24 Mar 2012
Yeah, I see what you mean. To be honest I find the whole block of code perplexing. How can an addition happen when there is no equals sign etc.
I don't really know how mex files work but I had a thought that maybe it was related to why the code initially came completely commented out?

Sign in to comment.

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!