-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgray_level_slicing
41 lines (38 loc) · 1.65 KB
/
gray_level_slicing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
a = imread('football.jpg'); % Note: "football.jpg" is a Matlab image, for
% better idea of matlab images, "help imdemos" in command window.
% converting the above color image into a gray level image
b = rgb2gray(a);
% calling the image size
[m,n] = size(b);
% analyzing the above gray level image histogram using "imhist"
imshow(b); title('input image in gray level');
figure;
imhist(b);title('histogram of the input image at gray level');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Note: Observe the "white colored stiches" on the "foot ball image" and
% corresponding "pixel intensities" in the histogram, we found that, white
% gray level pixels will be in the range from 240 to 255 therefore by using
% gray level slicing from 240 i.e., if the image intensity is greater than
% or equal to 240 make it equal to 255, else make it equal to 0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% initialing a null two dimentional array "c" with size equal to input imag
% using matlab command "zeros"
c = zeros(m,n);
% initialing the for loop
for i = 1:m
for j = 1:n
% use the condition
if b(i,j) >= 227 % try with defferent intensity levels in the range from 227 to 245 for better understanding
c(i,j) = 255;
else
c(i,j) = 0;
end
end
end
% end of for loop
% here the logic is completed for "gray level" or "Intensity" Slicing
% Now showing the result
% Here you will observe an excellent result and it will be very useful for
% the class room display
figure;
imshow(c);title('gray level sliced image from an intensity level 240 onwards - Rishabh');