function [im_res]=hist_eq_im3(im,N)

[h, ind] = comp_hist(im);
[h2, T] = hist_eq3(h, N);

im_res = im;
for i=1:size(im,1),
   for j=1:size(im,2),
     p=im(i,j);
     im_res(i,j) = T(p-ind(1)+1)-1;
   end
end
max_val = length(ind)-1;
im_res = im_res * max_val /max(max(im_res))+ind(1);
return
