title: Lightness order Error (LOE) for images quality assessement - Matlab
body: <p>I was trying to implement the LOE measure proposed in the article "Naturalness Preserved Enhancement Algorithm for Non-Uniform Illumination Images"</p>
  
  <p>The algortithm is the following: 
  Let I be the original image and Ie the enhanced image. The lightness
  <strong>L(x, y)</strong> of  image I is given as the maximum of its three color channels:</p>
  
  <blockquote>
    <p>L(x, y) = max Ic(x, y); c∈{r,g,b}</p>
  </blockquote>
  
  <p>(same for <strong>Le(x,y)</strong>);</p>
  
  <p>Then for each pixel (x, y) we compute <strong>RD(x,y)</strong> defined as: </p>
  
  <blockquote>
    <p>RD(x,y) = Sum (Sum( U(L(x, y), L(i, j ))⊕U(Le(x, y), Le(i, j ))))</p>
    
    <p>where i={1..n}; j={1..m}.</p>
  </blockquote>
  
  <p><strong>m</strong> and <strong>n</strong> are the size of the image and <strong>U(x,y)=1</strong> if (x>=y ) and 0 elsewise.</p>
  
  <p>Finally </p>
  
  <blockquote>
    <p>LOE = sum(sum(RD))/size(I)</p>
  </blockquote>
  
  <p>In order, to keep computation simple the authors downsample the image with a factor <strong>r = 50 /min(m,n)</strong>.</p>
  
  <p>The results I obtained for the attached image equals to  <strong>467.2846</strong> while it should be around <strong>1.17</strong>. 
  I Post my code here: </p>
  
  <pre><code>I = imread('birds.jpg'); % original image
  Ie = imread('birds_output.jpg'); % enhanced image
  
  [N M n] = size (I);
  
  L = max(I,[],3);
  Le = max(Ie,[],3);
  
  r = 50 / min (M,N);
  Md = round(M*r);
  Nd = round(N*r);
  Ld =imresize(L,[Nd Md]);
  Led =imresize(Le,[Nd Md]);
  
  RD = zeros (Nd,Md);
  size (RD)
  
  for y = 1:Md
      for x = 1:Nd
  
          E = xor((Ld(x,y)&gt;=Ld(:,:)),(Led(x,y)&gt;=Led(:,:)));
          RD(x,y) = sum(E(:));
  
      end
  end
  LOE = sum(RD(:))/(Md*Nd);
  </code></pre>
  
  <p>Also, the images I used: </p>
  
  <ul>
  <li><a href="http://i.stack.imgur.com/cDaCs.jpg" rel="nofollow">input image</a> </li>
  <li><a href="http://i.stack.imgur.com/6M8ET.jpg" rel="nofollow">output image</a></li>
  </ul>
  
  <p>Thank you in advance for your help. </p>