function [DJ,DG]=fisher_gopt_DJ(h_,w,m_x1,m_x2,r_xx1,r_xx2,M_h,N_h,dummy)
% fisher_gopt_DJ
%	Calculate d{J_fisher(h)}/dh

h=reshape(h_,N_h,M_h).';

% Calculate feature measures and partially derivated feature measures,
% Note that the derivatives will be matrices corresponding to the
% 2D field h, not the vector h_
[m_1,Dm_1,var_1,Dvar_1]=Dfstats(m_x1,r_xx1,h,w);
[m_2,Dm_2,var_2,Dvar_2]=Dfstats(m_x2,r_xx2,h,w);

% Compute the derivative
DJ=-( 2 * (m_1 - m_2) * (Dm_1 - Dm_2) * (var_1 + var_2)...
  - (m_1 - m_2)^2 * (Dvar_1 + Dvar_2)) ...
  ./ ((var_1 + var_2)^2);

% Convert output back to vector form (as required by the gradient search
% algorithm by Matlab)
DJ=reshape(DJ.',M_h*N_h,1);

DG=-2*h_;
