Try imadjdemo. It demostrates essential intensity transformations
An intensity transformation just replaces original intensities by some others according to some transformation table, I_new=f(I). It can be formalized as:for i=1 to image_width for j=1 to image_height I_new(i,j) = f(I(i,j)) end end
Let us make the negative of an image. The transformation table becomes
original value | 0 | 1 | 2 | 3 | ... | 254 | 255 | |
new value | 255 | 254 | 253 | 252 | ... | 1 | 0 |
f=255:-1:0;A naive Matlab implementation may look as
NEG=zeros(size(IM)); % memory allocation tic for i=1:size(IM,2) for j=1:size(IM,1) NEG(j,i)=f(IM(j,i)+1); end end tocYou may wonder why to index IM(j,i)+1. This is because Matlab cannot index from "0" but "1".
The pair
NEG=f(IM+1);Elegant, isn't it? And faster, much faster! You may check it by the tic-toc pair.
Thresholding, sometimes called binarization, replace intensities which
are lower than a predefined threshold
Create a function lut=piecewise(a,b,c,d)
which creates a
transformation table according to the following graph:
Output of the function is the lut vector for desired transformation.