Matlab Code for calculating Figure of Merit (FOM) gives the error
<p>I am developing an algorithm to find edges in Coloured Images. To check its performance it needs to calculate the figure of merit. I had the code but it is giving some error.</p>

<p>The following code to calculate the FOM gives error.</p>

<pre><code>Ea=double(R);                     // R is the original Image 
Ed=double(R1);                    // R1 is the Image having Edges

[N,M]=size(Ea); 

if [N,M]~=size(Ed)  
  error('Actual and detected edge image sizes must be same'); 
end; 

a=0.1; % edge shift penalty constant; 

fac=length(find((Ea-Ed)==-1)); % False Alarm Count 

msc=length(find((Ea-Ed)==1));  % Miss Count 

Na=sum(sum(Ea));Nd=sum(sum(Ed)); 

c=1/max(Na,Nd); 

[ia,ja]=find(Ea==1); 

for l=1:Na

  Aes(l)=Ed(ia(l),ja(l)); 

end; 

mi=ia(find(Aes==0)); 

mj=ja(find(Aes==0)); 

F=c*sum(Aes); 

for k=1:length(mi)  
  n1=0;n2=0;m1=0;m2=0;  
  while sum(sum(Ed(mi(k)-n1:mi(k)+n2,mj(k)-m1:mj(k)+m2)))&lt;1 
    if mi(k)-n1&gt;1 n1=n1+1;end;   
    if mi(k)+n2&lt;N n2=n2+1;end;   
    if mj(k)-m1&gt;1 m1=m1+1;end;   
    if mj(k)+m2&lt;M m2=m2+1;end;   
  end; 
  di=max([n1 n2 m1 m2]); 
  F=F+c/(1+a*di^2); 
end; 

F = F*100;
</code></pre>

<p>Error is:</p>

<pre><code>"
Attempted to access ia(21609); index out of bounds because
numel(ia)=21608.

Error in Final (line 95)
  Aes(l)=Ed(ia(l),ja(l));
"
</code></pre>