Search, what's on your mind?

Plausible Image Thresholding Matlab Codes

Suppose that the image consists of one or more objects and background, each having distinct gray-level values. The purpose of thresholding is to separate these areas from each other by using the information given by the histogram of the image.

Maintaining significant information of the image

Matlab Code
 clear;  
 % Threshold level parameter alfa:  
 alfa=0.1;% less than 1/3  
 [x,map]=gifread('lena.gif');  
 ix=ind2gray(x,map);  
 I_max=max(max(ix));  
 I_min=min(min(ix));  
 level1=alfa*(I_max-I_min)+I_min;  
 level2=2*level1;  
 level3=3*level1;  
 thix1=max(ix,level1.*ones(size(ix)));  
 thix2=max(ix,level2.*ones(size(ix)));  
 thix3=max(ix,level3.*ones(size(ix)));  
 figure(1);  
 colormap(gray);  
 subplot(2,2,1);  
 imagesc(ix);  
 title('lena');  
 subplot(2,2,2);  
 imagesc(thix1);  
 title('1');  
 subplot(2,2,3);  
 imagesc(thix2);  
 title('2');  
 subplot(2,2,4);  
 imagesc(thix3);  
 title('3');  

Input
lena.gif

Output / Results

1

2

3

Improvement of signal-noise ratio of an image

Matlab Code
 clear;  
 % Threshold level parameter alfa:  
 alfa=0.1;% less than 1/3  
 [x,map]=gifread('lena.gif');  
 ix=ind2gray(x,map);  
 I_max=max(max(ix));  
 I_min=min(min(ix));  
 level1=alfa*(I_max-I_min)+I_min;  
 level2=2*level1;  
 level3=3*level1;  
 thix1=max(ix,level1.*ones(size(ix)));  
 thix2=max(ix,level2.*ones(size(ix)));  
 thix3=max(ix,level3.*ones(size(ix)));  
 figure(1);  
 colormap(gray);  
 subplot(2,2,1);  
 imagesc(ix);  
 title('lena');  
 subplot(2,2,2);  
 imagesc(thix1);  
 title('one');  
 subplot(2,2,3);  
 imagesc(thix2);  
 title('two');  
 subplot(2,2,4);  
 imagesc(thix3);  
 title('three');  

Input
lena.gif

Output / Results

one

two

three

Percentage level Image Thresholding

Matlab Code
 clear;  
 % Threshold level parameter alfa:  
 alfa=0.1;% less than 1/3  
 [x,map]=gifread('lena.gif');  
 ix=ind2gray(x,map);  
 I_max=max(max(ix));  
 I_min=min(min(ix));  
 level1=alfa*(I_max-I_min)+I_min;  
 level2=2*level1;  
 level3=3*level1;  
 thix1=max(ix,level1.*ones(size(ix)));  
 thix2=max(ix,level2.*ones(size(ix)));  
 thix3=max(ix,level3.*ones(size(ix)));  
 figure(1);  
 colormap(gray);  
 subplot(2,2,1);  
 imagesc(ix);  
 title('lena');  
 subplot(2,2,2);  
 imagesc(thix1);  
 title('10%');  
 subplot(2,2,3);  
 imagesc(thix2);  
 title('20%');  
 subplot(2,2,4);  
 imagesc(thix3);  
 title('30%');  

Input
lena.gif

Output / Results

10%

20%

30%

Reduction of the noise effect in an image

Matlab Code
 clear;  
 % Threshold level parameter alfa:  
 alfa=0.1;% less than 1/3  
 [x,map]=gifread('lena.gif');  
 ix=ind2gray(x,map);  
 I_max=max(max(ix));  
 I_min=min(min(ix));  
 level1=alfa*(I_max-I_min)+I_min;  
 level2=2*level1;  
 level3=3*level1;  
 thix1=max(ix,level1.*ones(size(ix)));  
 thix2=max(ix,level2.*ones(size(ix)));  
 thix3=max(ix,level3.*ones(size(ix)));  
 figure(1);  
 colormap(gray);  
 subplot(2,2,1);  
 imagesc(ix);  
 title('lena');  
 subplot(2,2,2);  
 imagesc(thix1);  
 title('noise effect reduced by one alfa');  
 subplot(2,2,3);  
 imagesc(thix2);  
 title('noise effect reduced by two alfa');  
 subplot(2,2,4);  
 imagesc(thix3);  
 title('noise effect reduced by three alfa');  

Input
lena.gif

Output / Results

noise effect reduced by one alfa

noise effect reduced by two alfa

noise effect reduced by there alfa