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.
If the object and the background have clearly uniform gray-level values, the object can easily be detected by splitting the histogram using a suitable threshold value. The threshold is considered as a function of; where i and j are the coordinates of the pixel, xi,j is the intensity value of the pixel, and p(i, j) is a function describing the neighborhood of the pixel (e.g. the average value of the neighboring pixels). The thresholding can be performed by:
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('threshold 1');  
 subplot(2,2,3);  
 imagesc(thix2);  
 title('threshold 2');  
 subplot(2,2,4);  
 imagesc(thix3);  
 title('threshold 3');  

Input
lena.gif
Output / Results
threshold 1                     threshold 2                     threshold 3

1 comment:

Dear member, ask us "what you want?"