Explanation of source code written in Matlab
3 views (last 30 days)
Show older comments
What does the following function accomplish?
Can anyone tell me what the following code is doing and how is it doing that?
Is it some kind of region-growing code?
function range=range_gradient(img4corr, p, sz, range, centroid, var, w, tres)
% support function
max_range=size(range,1);
corr_values=zeros(max_range,1);
gauss=gaussiana(centroid(1)-range(1,1),var,max_range);
gauss=gauss./max(gauss);
% calculate the local correlation and weight with the global one and modify them with gaussian
for i=1:max_range
corr_local=correlazione2d_local(img4corr,centroid,range(i,:),sz,0);
corr_global=correlazione2d_local(img4corr,p,range(i,:),sz,0);
corr_values(i,1)= w(1)*corr_global + w(2)*corr_local;
end;
corr_values=corr_values.*gauss(1:max_range)';
% do a search from the centroid
% corr_values
% centroid
up=0;
do=0;
u_index=centroid(1)-range(1,1);
% u_index
d_index=centroid(1)-range(1,1);
% d_index
while( ~(up && do))
if(~up)
if(corr_values(u_index,1)<=tres||u_index<=1)
up=1;
else
u_index=u_index-1;
end;
end;
if(~do)
if(corr_values(d_index,1)<=tres||d_index>=max_range)
do=1;
else
d_index=d_index+1;
end;
end;
end;
range=zeros(max_range,1);
range(u_index:d_index,1)=1;
2 Comments
Image Analyst
on 4 Oct 2017
Not sure. Can't you ask the author? The code has very few meaningful comments and cryptic variable names so it's hard to follow. Plus, range() is a built-in function name so they should not use that as a variable name.
Answers (1)
Jan
on 4 Oct 2017
As long as the code does not contain meaningful comments and a clear help section, it is doing "something". There is no chance to understand reliably, what this is and how the inputs must be defined to get a proper result. You (or we) can guess a little bit, but this is a waste of time. Do not use this code for a productive code. Rewriting from scratch what you need will be more efficient.
2 Comments
Jan
on 5 Oct 2017
This is no valid Matlab syntax:
while (+ leftFlag rightFlag ~ = 2)
The code from your original post contains too few comments to be explained efficiently and reliably. After we told you this, you post another code (twice), which contains some non-Matlab lines. This does not help to solve the problem.
Again: Either the author can add more comments and explain the purpose of the code. Or an exhaustive explanation of what happens in it might take hours of investigations with the debugger, varied inputs and a comparison of the outputs, of reading papers and books. Whatever you want to do with the code, I'm convinced that it is more efficient to re-write it from scratch.
Sorry for this pessimistic estimation.
See Also
Categories
Find more on Surrogate Optimization 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!