-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.m
97 lines (68 loc) · 1.96 KB
/
Main.m
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function[porosity,ssa] = Main(im)
%clear;
%clc;
%Input='sample1.jpg';
%im = imread(Input);
%figure,imshow(im);
%figure,imshow(im);
[s1,s2,s3]=size(im);
BW=zeros(s1,s2);
%----------------------------------------------------------------------
% Based on user defined threshold or from any thresholding algorithm
% Thresholding can be done on Grayscale image or YCBCR image(prefered)
% YCBCR image gives better results
%----------------------------------------------------------------------
% Y=rgb2ycbcr(im);
% %figure,imshow(Y);
% t = graythresh(im);
% %display(t);
% t=140;
% for I=1:s1
% for J=1:s2
% if Y(I,J,2)>t
% BW(I,J)=1;
% end
% end
% end
%-------------------------------------------------------
% Thresholding based on RGB values of pixels
%-------------------------------------------------------
%
for I=1:s1
for J=1:s2
if(im(I,J,1)<203 && im(I,J,2)<203 && im(I,J,3)>170)
BW(I,J)=1;
end
end
end
% Denoising after thresholding
str = strel('octagon',3);
c = imopen(BW,str);
f = imclose(c,str);
sample1 = medfilt2(f);
x = logical(sample1);
figure,imshow(sample1);
% Connected Componenets - No of Pores
%C = bwconncomp(sample1);
%display(C);
% Area
%A = regionprops(sample1,'area');
%A=bwarea(sample1);
%display(A);
% n largest pores
%sample2 = bwareafilt(x,5,'largest');
%figure,imshow(sample2);
% Porosity Calculation
porosity=(sum(sum(sample1)/(s1*s2)*100));
%display(porosity);
%-----------------------------------------------------------
%-----------------------------------------------------------
% Edge Detection
F=imerode(sample1,str); % Erode
e = sample1 - F;
figure,imshow(e);
% Creating a Grid for Specific Surface Area
[grid,horiz_lines,vert_lines] = create_grid(e);
%figure,imshowpair(e,grid);
% Calculating Specific Surface Area
[ssa] = specific_area(grid,e,horiz_lines,vert_lines);