
Einstein equalized and down-sampled by a factor of two.
|
% LOAD IMAGE
im = imread( 'al.jpg' );
im = double( im );
% COMPUTE NEW LOOKUP TABLE
minim = min( im(:) );
maxim = max( im(:) );
inc = (maxim-minim)/63;
X = [minim : inc : maxim];
N = hist( im(:), X );
T = sum( N );
N2 = cumsum( N ) / T;
X2 = [minim : (maxim-minim)/255 : maxim];
N2 = interp1( X, N2, X2, '*linear' );
lut = N2' * [1 1 1]; % NEW COLORMAP
imagesc( im, [0 255] );
axis image off;
colormap(lut);
%%% LOOK AT ALL THE PIECES
% APPLY NEW LOOKUP TABLE TO IMAGE - DESTRUCTIVELY MODIFY IMAGE
[ydim,xdim] = size(im);
im_eq = 255*interp1( X2, N2, im(:), '*linear' );
im_eq = reshape( im_eq, ydim, xdim );
figure(1);
subplot( 2,3,1 );
imagesc( im, [0 255] ); axis image off; colormap gray;
title( 'Einstein' );
colormap gray;
subplot( 2,3,2 );
hist( im(:), 16 ); axis( [0 256 0 15000] ); axis square;
subplot( 2,3,3 );
plot( N2 ); axis( [0 255 0 1] ); axis square;
title( 'Lookup Table' );
subplot( 2,3,4 );
imagesc( im_eq, [0 255] ); axis image off; colormap gray;
title( 'Einstein Equalized' );
colormap gray;
subplot( 2,3,5 );
hist( im_eq(:), 16 ); axis( [0 256 0 15000] ); axis square;
|