summaryrefslogtreecommitdiff
path: root/3176/CH10/EX10.23/Ex10_23.sce
blob: 808c93a5adb83a83425cee353952d8a3d058f2b7 (plain)
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
//Ex10_23
// Segmentation by Region Growing
// Version : Scilab 5.4.1
// Operating System : Window-xp, Window-7
//Toolbox: Image Processing Design 8.3.1-1
//Toolbox: SIVP 0.5.3.1-2
//Reference book name : Digital Image Processing
//book author: Rafael C. Gonzalez and Richard E. Woods

clc;
close;
clear;
xdel(winsid())//to close all currently open figure(s).
a=imread("Ex10_23.tif");
a1=im2double(a);
figure,ShowImage(a1,'Gray Image');
title('Original Image','color','blue','fontsize',4);
[M,N]=size(a);

[count cell]=imhist(a);
figure,plot2d3(cell,count);
title('Histogram','color','blue','fontsize',4);

th=254/255;
Thresh_Image=im2bw(a1,th);
figure,ShowImage(Thresh_Image,'Gray Image');
title('Thresholded Image','color','blue','fontsize',4);
for i=1:M
    for j=1:N
        if(Thresh_Image(i,j)) then
            Thresh_Image1(i,j)=1;
        else
            Thresh_Image1(i,j)=0;
        end
    end
end

BlobImage = SearchBlobs(Thresh_Image);  // Connected Compoment Labelling
IsCalculated = CreateFeatureStruct(%f); // Feature struct is generated.
IsCalculated.Centroid = %t; // The bounding box shall be calculated for each blob.
BlobStatistics = AnalyzeBlobs(BlobImage, IsCalculated);
Seed_Image=zeros(M,N);
for i=1:max(BlobImage) // Centroid Calculation
    Seed_Image(BlobStatistics(i).Centroid(1,2),BlobStatistics(i).Centroid(1,1))=1;
end
figure,ShowImage(Seed_Image,'Gray Image');
title('Seed Point Image','color','blue','fontsize',4);

Diff=uint8(255*imsubtract(a1,Thresh_Image1));
figure,ShowImage(Diff,'Gray Image');
title('Seed Point Image','color','blue','fontsize',4);
[count cell]=imhist(Diff);
figure,plot2d3(cell,count);
title('Histogram','color','blue','fontsize',4);

Thresh_Image2=uint8(zeros(M,N))
for i=1:M
    for j=1:N
        if(Diff(i,j)<=68) then
            Thresh_Image2(i,j)=255;
        else if(Diff(i,j)>68 & Diff(i,j)<=165) then
            Thresh_Image2(i,j)=125;
        else
            Thresh_Image2(i,j)=0;
        end
    end
    end
end
figure,ShowImage(uint8(Thresh_Image2),'Gray Image');
title('Seed Point Image','color','blue','fontsize',4);