background image

 

Image processing

Laboratory 5 (ad) 

 

Exercise 1 

Try to analyse the histogram of the image mikolaj.jpg. The local maximum in this diagram results 
from pixels of background. Choose the threshold below and above this maximum and compare the 
results with the effect of Otsu algorithm.
 
 
Example 1 
Binarization with 2 thresholds: 

L = imread(

'portret.jpg'

);

 

imshow(zeros(600,800));

 

subplot(1,2,1),imshow(L);

 

subplot(1,2,2),imhist(L);

 

prompt = {

‘Choose the threshold value:’

,

’Choose the tolerance:’

};

 

odp = inputdlg(prompt);

 

prog = str2num(odp{1});

 

tol = str2num(odp{2});

 

L2 = (L<(prog+tol))&(L>(prog-tol));

 

figure;

 

imshow(L2);

 

 

Exercise 2 

Modify the example above this way, that the user could click on the pixel of image and choose the 
threshold  (the  value  of  threshold  is  equal  the  value  of  this  pixel),  and  the  tolerance  should  be 
chosen in the dialog window.   
 
Example 2 
Animation of binarization:: 

L = imread(

'portret.jpg'

);

 

for

 i=1:256

 

    imshow(L>i);

 

    pause(0.01);

 

end

;