Sabtu, 10 Agustus 2019

Analisa Jenis Kucing sebaiknya pakai ViolaJones

hasil Akurasi:
  'OUTPUT'    'PREDIKSI1'    'T/F'    'PREDIKSI2'    'T/F'
     1     7     0     1     1
     1     7     0     1     1
     1     7     0     1     1
     1     7     0     1     1
     1     7     0     1     1
     2     2     1     2     1
     2     2     1     2     1
     2     2     1     2     1
     2     2     1     2     1
     2     2     1     2     1
     3     3     1     3     1
     3     3     1     3     1
     3     3     1     3     1
     3     3     1     3     1
     3     3     1     3     1
     4     4     1     4     1
     4     4     1     4     1
     4     4     1     4     1
     4     4     1     4     1
     4     4     1     4     1
     5     5     1     5     1
     5     5     1     5     1
     5     5     1     5     1
     5     5     1     5     1
     5     5     1     5     1
     6     6     1     6     1
     6     6     1     6     1
     6     6     1     6     1
     6     6     1     6     1
     6     6     1     6     1
     7     7     1     7     1
     7     7     1     7     1
     7     7     1     7     1
     7     7     1     7     1
     7     7     1     7     1

output adalah terget yang harus di capai...
misal 1: kucing Angora, 2 Kucing Bengal, 3 Brits, 4 Exotic, 5 Mainecoon, 6 Persia dan  7 Sphynx

Menggunakan Metode SVM model Grayscale (rgb2gray): hasilnya kurang baik
Menggunakan Metode SVM model R+G/2(Red dan green saja): hasilnya lebih baik bahkan 100% benar
'T/F' =>1=true, 2 false atau tidak sesuai target 



Saat menggunakan Kmeans hasilya kurang baik karena disini menggunakan rumus labeling....

pil1=get(handles.pil1,'Userdata')
pil2=get(handles.pil2,'Userdata')
pil3=get(handles.pil3,'Userdata')
pil4=get(handles.pil4,'Userdata')


data=get(handles.mytable3,'Userdata');
data0=get(handles.mytable4,'Userdata');

if size(data,1)<1
   msgbox('Silakan pilih data latih dahhulu...','Lengkapi Data','help');
    return;
end

ROW=data(:,1)

co=size(data0,2);
mydata=data0(:,2:co);
mydatabaru=[pil1,pil2,pil3,pil4]
F=[mydata;mydatabaru];

K=8;
opts = statset('Display','final');
[prediction, CENTS] = kmeans(F, K, 'Distance','city','Replicates',40, 'Options',opts);

header=["X1","X2","X3","X4"];
c=size(CENTS,1);

T=size(prediction,1);
hsl=prediction(T);
row=linspace(1,c,c);
set(handles.mytable5,'data',CENTS,'ColumnName',header,'RowName',row);
set(handles.mytable5,'Userdata',CENTS);
OUT=cell2mat(ROW(hsl));
set(handles.edknn,'String',num2str(OUT));








+++++++++++++++++++
Perhitungan Normalsiasi SVM menggunalan rumus ini:

load DLATIH.mat;
load DLATIH2.mat;
load ROW.mat;
load ROW2.mat;
load KAT.mat;

kolom={'Contrast' 'Correlation' 'Energy' 'Homogeneity'};
    
set(handles.mytable,'data',DLATIH,'ColumnName',kolom,'RowName',ROW);
set(handles.mytable,'Userdata',DLATIH); 
%%%%%%%%%%%%%%%
set(handles.mytable2,'data',DLATIH2,'ColumnName',kolom,'RowName',ROW);
set(handles.mytable2,'Userdata',DLATIH2); 
%%%%%%%%%%%%%%%
  
   
%%%%%%%%%%%%%%%%%%%%

X =DLATIH;
Y = KAT;

prediction=multisvm(DLATIH,KAT,DLATIH);
prediction2=prediction';

ba=size(prediction2,2);
benar=0;
rekap1=[];
for i=1:ba
    if(KAT(1,i)==prediction2(1,i))
       benar=benar+1; 
       rekap1(1,i)=1;
    else
        rekap1(1,i)=0;
    end
end  
salah=ba-benar;
akurasi1=benar/ba;


prediction=multisvm(DLATIH2,KAT,DLATIH2);
prediction22=prediction';

ba=size(prediction22,2);
benar=0;
rekap2=[];
for i=1:ba
    if(KAT(1,i)==prediction22(1,i))
       benar=benar+1;
       rekap2(1,i)=1;
    else
        rekap2(1,i)=0;
    end
end  
salah=ba-benar;
akurasi2=benar/ba;


GAB=[KAT' prediction2' rekap1'  prediction22' rekap2']
row=linspace(1,ba,ba);
header={'OUTPUT','PREDIKSI1','T/F','PREDIKSI2','T/F'}
set(handles.mytable0,'data',GAB,'ColumnName',header,'RowName',row);
set(handles.mytable0,'Userdata',GAB);


Sedang raget yang hendak dicapai lebihd ari 2 item maka menggunakan rumsu Multisvm sbb:


function [itrfin] = multisvm( T,C,test )
itrind=size(test,1);
itrfin=[];
Cb=C;
Tb=T;
for tempind=1:itrind
    tst=test(tempind,:);
    C=Cb;
    T=Tb;
    u=unique(C);
    N=length(u);
    c4=[];
    c3=[];
    j=1;
    k=1;
    if(N>2)
        itr=1;
        classes=0;
        cond=max(C)-min(C);
        while((classes~=1)&&(itr<=length(u))&& size(C,2)>1 && cond>0)
            c1=(C==u(itr));
            newClass=c1;
            svmStruct = svmtrain(T,newClass,'kernel_function','polynomial');  
            classes = svmclassify(svmStruct,tst);
            
            for i=1:size(newClass,2)
                if newClass(1,i)==0;
                    c3(k,:)=T(i,:);
                    k=k+1;
                end
            end
            T=c3;
            c3=[];
            k=1;
            
            for i=1:size(newClass,2)
                if newClass(1,i)==0;
                    c4(1,j)=C(1,i);
                    j=j+1;
                end
            end
            C=c4;
            c4=[];
            j=1;
            
            cond=max(C)-min(C); 
            if classes~=1
                itr=itr+1;
            end
        end
    end
    
    valt=Cb==u(itr);
    val=Cb(valt==1);
    val=unique(val);
    itrfin(tempind,:)=val;
end

end




Datalatih target:


    'Anggora'
    'Anggora'
    'Anggora'
    'Anggora'
    'Anggora'
    'Bengal'
    'Bengal'
    'Bengal'
    'Bengal'
    'Bengal'
    'Britsh'
    'Britsh'
    'Britsh'
    'Britsh'
    'Britsh'
    'Exotic'
    'Exotic'
    'Exotic'
    'Exotic'
    'Exotic'
    'Mainecoon'
    'Mainecoon'
    'Mainecoon'
    'Mainecoon'
    'Mainecoon'
    'Persia'
    'Persia'
    'Persia'
    'Persia'
    'Persia'
    'Sphynx'
    'Sphynx'
    'Sphynx'
    'Sphynx'
    'Sphynx'

DLATIH =

   1.0e+10 *

    0.1114    1.0030    0.0106    0.0000
    0.1114    1.0030    0.0106    0.0000
    0.1114    1.0030    0.0106    0.0000
    0.0959    1.0573    0.0153    0.0000
    0.1114    1.0030    0.0106    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.1419    3.0747    0.0114    0.0000
    0.0732    1.1291    0.0145    0.0000
    0.1418    1.8808    0.0081    0.0000
    0.0892    1.3324    0.0200    0.0000
    0.1418    0.9196    0.0120    0.0000
    0.1114    0.8824    0.0063    0.0000
    0.1114    0.8824    0.0063    0.0000
    0.1114    0.8824    0.0063    0.0000
    0.1114    0.8824    0.0063    0.0000
    0.1421    1.1542    0.0027    0.0000
    0.1099    1.0015    0.0114    0.0000
    0.1099    1.0015    0.0114    0.0000
    0.1099    1.0015    0.0114    0.0000
    0.1099    1.0015    0.0114    0.0000
    0.1099    1.0015    0.0114    0.0000

>> DLATIH2

DLATIH2 =

   1.0e+10 *

    0.1114    1.0030    0.0106    0.0000
    0.1114    1.0030    0.0106    0.0000
    0.1114    1.0030    0.0106    0.0000
    0.0959    1.0573    0.0153    0.0000
    0.1114    1.0030    0.0106    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.1276    2.5270    0.0104    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0669    0.6027    0.0046    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.0893    0.2997    0.0045    0.0000
    0.1419    3.0747    0.0114    0.0000
    0.0732    1.1291    0.0145    0.0000
    0.1418    1.8808    0.0081    0.0000
    0.0892    1.3324    0.0200    0.0000
    0.1418    0.9196    0.0120    0.0000
    0.1114    0.8824    0.0063    0.0000
    0.1114    0.8824    0.0063    0.0000
    0.1114    0.8824    0.0063    0.0000
    0.1114    0.8824    0.0063    0.0000
    0.1421    1.1542    0.0027    0.0000
    0.1099    1.0015    0.0114    0.0000
    0.1099    1.0015    0.0114    0.0000
    0.1099    1.0015    0.0114    0.0000
    0.1099    1.0015    0.0114    0.0000
    0.1099    1.0015    0.0114    0.0000


Terlihat 0 tetapi sebanarnya nilainya ada......cb di lihat lebih detail:
>> DLATIH2(1,4)

ans =

   1.6878e+04




Kamis, 08 Agustus 2019

Pengolahan Data AUDIO



Cara mendeteksi Suara Audio itu masuk kategori apa yaaaa?

SKhirnya bisa di buktikan bahwa Konsep audio juga semudah konsep Image bahwa mudah juga selama kita bisa menormalsiasikana sinyal audio tsresbut ...
Contoh di atas menunjukkan proses2nya
Dengan menggunakan 2 metode KNN dan SVM didapat akurasi yang baik juga


Namun begitu...SVM lebih baik akurasinyaaaa...tahu kenapaa......jelas karena ia mampu mengenali fitur objek audio dengan sempurna daripada hanya sebatas menghitung jarak menggunakan KNN





dan ini adalah sinyal normalisasi dari Audio musik nya (Gambang dan Tehyan)

Untuk Normalisasi nya rekan2 silakan bisa gunakan MFCC dengan code sbb:


function [ mfcc_test,ww ] = getMFCC( Samples)
% [InputIn,fs]=audioread(path);
% Samples = InputIn;
zz = find(Samples) < max(Samples/3);%Threshold speech regions
Samples(zz) = 0;
zz = find(Samples);
Speech_Region = Samples(zz);  

OverlapSize = 0.5;
MFCCNo = 45;
NoOfWindows = 25;
NoOfFilters = floor(MFCCNo/NoOfWindows+1);

mfcc_test = zeros(1,MFCCNo);
WindowSize = floor((size(Speech_Region,1))/(NoOfWindows+1));
ww = 0;
for ll = 0:OverlapSize:(NoOfWindows-1)/2
    bb = Speech_Region(floor(ll*WindowSize)+1:floor(ll*WindowSize)+WindowSize).*hamming(WindowSize);
    fb = fft(bb);                
    mb = 2595 * log10(1 + fb./700);                
    mfout = dct(log(abs(mb)),NoOfFilters);                    
    mfcc_test(1,ww*NoOfFilters+1:ww*NoOfFilters+NoOfFilters) = mfout;                                                        
    ww = ww + 1;
end          

end












Minggu, 21 Juli 2019

KMEANS EXAMPLE


clc
clear all
close all
%% Generate Points
Sigma = [0.5 0.05; 0.05 0.5];
f1    = mvnrnd([0.5 0]  ,Sigma,100);
f2    = mvnrnd([0.5 0.5],Sigma,100);
f3    = mvnrnd([0.5 1]  ,Sigma,100);
f4    = mvnrnd([0.5 1.5],Sigma,100);
F     = [f1;f2;f3;f4];
%% K-means
K     = 8;                                            % Cluster Numbers
KMI   = 40;                                           % K-means Iteration
CENTS = F( ceil(rand(K,1)*size(F,1)) ,:);             % Cluster Centers
DAL   = zeros(size(F,1),K+2);                         % Distances and Labels
CV    = '+r+b+c+m+k+yorobocomokoysrsbscsmsksy';       % Color Vector
for n = 1:KMI
       
   for i = 1:size(F,1)
      for j = 1:K 
        DAL(i,j) = norm(F(i,:) - CENTS(j,:));     
      end
      [Distance CN] = min(DAL(i,1:K));                % 1:K are Distance from Cluster Centers 1:K
      DAL(i,K+1) = CN;                                % K+1 is Cluster Label
      DAL(i,K+2) = Distance;                          % K+2 is Minimum Distance
   end
   for i = 1:K
      A = (DAL(:,K+1) == i);                          % Cluster K Points
      CENTS(i,:) = mean(F(A,:));                      % New Cluster Centers
      if sum(isnan(CENTS(:))) ~= 0                    % If CENTS(i,:) Is Nan Then Replace It With Random Point
         NC = find(isnan(CENTS(:,1)) == 1);           % Find Nan Centers
         for Ind = 1:size(NC,1)
         CENTS(NC(Ind),:) = F(randi(size(F,1)),:);
         end
      end
   end
 
%% Plot 
clf
figure(1)
hold on
 for i = 1:K
PT = F(DAL(:,K+1) == i,:);                            % Find points of each cluster   
plot(PT(:,1),PT(:,2),CV(2*i-1:2*i),'LineWidth',2);    % Plot points with determined color and shape
plot(CENTS(:,1),CENTS(:,2),'*k','LineWidth',7);       % Plot cluster centers
 end
hold off
grid on
pause(0.1)
end

Rabu, 17 Juli 2019

FFT tes WAV

[y, fs] = audioread('Alarm08.wav');
soundsc(y, fs);
subplot(2, 1, 1);
plot(y, 'b-');
grid on;
drawnow;
message = sprintf('Do you want to Set to FFT mode ?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
  % User said No, so exit.
  return;
end

lengthOfData = length(y);
nextPowerOfTwo = 2 ^ nextpow2(lengthOfData); % next closest power of 2 to the length

plotScaleFactor = 4;
plotRange = nextPowerOfTwo / 2; % Plot is symmetric about n/2
plotRange = floor(plotRange / plotScaleFactor);

yDFT = fft(y, nextPowerOfTwo); % Discrete Fourier Transform of data

h = yDFT(1:plotRange);
abs_h = abs(h);

freqRange = (0:nextPowerOfTwo-1) * (fs / nextPowerOfTwo);  % Frequency range
gfreq = freqRange(1:plotRange);  % Only plotting upto n/2 (as other half is the mirror image)

subplot(2, 1, 2);
plot(abs_h, 'b-');
grid on;
drawnow;
soundsc(abs_h, gfreq);







UJI AUDIO REALTIME

d = daq.getDevices
% index   Vendor    Device ID                            Description                         
% ----- ----------- --------- -----------------------------------------------------------------
% 1     directsound Audio0    DirectSound Primary Sound Capture Driver
% 2     directsound Audio1    DirectSound Microphone (High Definition Audio Device)
% 3     directsound Audio2    DirectSound HP 4120 Microphone (2- HP 4120)
% 4     directsound Audio3    DirectSound Microphone (Plantronics .Audio 400 DSP)
% 5     directsound Audio4    DirectSound Digital Audio (S/PDIF) (High Definition Audio Device)
% 6     directsound Audio5    DirectSound Primary Sound Driver
% 7     directsound Audio6    DirectSound Speakers (Plantronics .Audio 400 DSP)
% 8     directsound Audio7    DirectSound HP 4120 (2- HP 4120)
% 9     directsound Audio8    DirectSound Speakers (High Definition Audio Device):1
% 10    directsound Audio9    DirectSound Speakers (High Definition Audio Device):2

%misalkan di laptop kita terdeteksi no 2:  2     directsound Audio1    DirectSound Microphone (High Definition Audio Device)

dev = d(2)
s = daq.createSession('directsound');
addAudioInputChannel(s, dev.ID, 1:2);
s.IsContinuous = true

load chirp.mat;
sound(y, Fs);

hf = figure;
hp = plot(zeros(1000,1));
T = title('Discrete FFT Plot');
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
grid on;
continuous_fft(y, Fs, hf)


%%REALIMR CONTINUOI
plotFFT = @(src, event) continuous_fft(event.Data, src.Rate, hp);
hl = addlistener(s, 'DataAvailable', plotFFT);


%start
startBackground(s);
figure(hf);


%stop
stop(s);
s.IsContinuous = false;
delete(hl);



%%%%%%%%%%%%%%%%%
function continuous_fft(data, Fs, plotHandle)

lengthOfData = length(data);
nextPowerOfTwo = 2 ^ nextpow2(lengthOfData); % next closest power of 2 to the length

plotScaleFactor = 4;
plotRange = nextPowerOfTwo / 2; % Plot is symmetric about n/2
plotRange = floor(plotRange / plotScaleFactor);

yDFT = fft(data, nextPowerOfTwo); % Discrete Fourier Transform of data

h = yDFT(1:plotRange);
abs_h = abs(h);

freqRange = (0:nextPowerOfTwo-1) * (Fs / nextPowerOfTwo);  % Frequency range
gfreq = freqRange(1:plotRange);  % Only plotting upto n/2 (as other half is the mirror image)

% whos abs_h
% whos gfreq

set(plotHandle, 'ydata', abs_h, 'xdata', gfreq); % Updating the plot
drawnow; % Update the plot

end






Kamis, 07 Februari 2019

Mencari Edge Image


img = false(5); % Use zeros(5) if you prefer
img(3, 2:4) = true; % use 1 instead of true if you prefer
% Get complement of image, with a border round it in case the
% blob is at the boundary
notimg = true(size(img)+2);
notimg(2:end-1, 2:end-1) = ~img;
% Find locations where a non-zero pixel is adjacent to a zero pixel,
% for each cardinal direction in turn
topedges = img & notimg(1:end-2, 2:end-1);
leftedges = img & notimg(2:end-1, 1:end-2);
bottomedges = img & notimg(3:end, 2:end-1);
rightedges = img & notimg(2:end-1, 3:end);
% Sum each set of locations separately, then add to get total perimeter/Keliling:
perim = sum(topedges(:)) + sum(leftedges(:)) + ...
+ sum(bottomedges(:)) + sum(rightedges(:));
% print result
fprintf('Perimeter is %d\n', perim);


img img = 5×5 logical array 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 >> topedges topedges = 5×5 logical array 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 >> rightedges rightedges = 5×5 logical array 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 >> bottomedges bottomedges = 5×5 logical array 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 >> leftedges leftedges = 5×5 logical array 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0

notimg = 7×7 logical array 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


IMPLEMENTASI:


I = imread('daun.jpg');
[N,M,L]=size(I);
for n=1:N
    for m=1:M
        if (I(n,m,1)<225 && I(n,m,2)< 225 && I(n,m,3)<225)
            bw1(n,m,1)=255;%I(n,m,1:3);
        else
            bw1(n,m,1)=0;
        end
    end
end                             % bw1            210x210              352800  double  
BW = imbinarize(bw1);           % BW             210x210               44100  logical   
bw2 = imfill(BW,'holes');
figure, imshow(bw2);
  
s = regionprops(bw2, 'All');
a=s(1,1);
b=s(2,1);

ps=['Luas Area (FilledImage) ' num2str(a.Area) ' px'];
    disp(ps);
ps=['Titik Centroid' num2str(a.Centroid(1)) ',' num2str(a.Centroid(2))];
    disp(ps);
ps=['Panjang  Area ' num2str(a.MajorAxisLength)];
    disp(ps);
ps=['Lebar Area  ' num2str(a.MinorAxisLength)];
    disp(ps);
ps=['Keliling /Perimeter Area  ' num2str(a.Perimeter)];
    disp(ps);
disp('8 Koordinat Terluar ');    
for i = 1:8
    ps=['Posisi ' num2str(i) ' : ' num2str(a.Extrema(i,1)) ',' num2str(a.Extrema(i,2))];
    disp(ps);
end   

Image=a.Image;
FilledImage=a.FilledImage;
M=s.Extrema;
img=~FilledImage;
notimg = true(size(img)+2);
notimg(2:end-1, 2:end-1) = ~img;

hold on
    plot(a.Centroid(1), a.Centroid(2), 'r*')

    for i = 1:8
        plot(M(i,1), M(i,2), 'y*')
    end
   

    hold off



figure(2)
    leftedges =  img & notimg(2:end-1, 3:end);
    bottomedges =    img & notimg(1:end-2, 2:end-1);
    rightedges =   img & notimg(2:end-1, 1:end-2);
    topedges = img & notimg(3:end,   2:end-1);
    perim = sum(topedges(:)) + sum(leftedges(:)) + sum(bottomedges(:)) + sum(rightedges(:));

    subplot(2,2,1);
        imshow(~rightedges);title('rightedges area');
     subplot(2,2,2);
        imshow(~topedges);title('topedges area');
     subplot(2,2,3);
        imshow(~leftedges);title('leftedges area');
     subplot(2,2,4);
        imshow(~bottomedges);title('bottomedges area');

        



Luas Area (FilledImage) 60789 px
Titik Centroid156.8662,168.5555
Panjang  Area 349.4928
Lebar Area  224.3
Keliling /Perimeter Area  988.042
8 Koordinat Terluar 
Posisi 1 : 26.5,2.5
Posisi 2 : 30.5,2.5
Posisi 3 : 287.5,207.5
Posisi 4 : 287.5,208.5
Posisi 5 : 213.5,328.5
Posisi 6 : 210.5,328.5
Posisi 7 : 18.5,6.5
Posisi 8 : 18.5,5.5


Matlab Edge Detection +Crop


 

 rooftops = imread('daun.jpg');
    imshow(rooftops);
    grayImage = rgb2gray(rooftops);
    imshow(grayImage);
    [r c] = size(grayImage);
    switchfactor = grayImage(round(r/2),round(c/2));
    if switchfactor <= 120
        minimumCanny = .0025;
        maximumCanny = .05;
        CFval = .6;
    elseif switchfactor <= 150
        minimumCanny = .005;
        maximumCanny = .075;
        CFval = .575;
    elseif switchfactor <= 180
        minimumCanny = .0075;
        maximumCanny = .1;
        CFval = .55;
    elseif switchfactor <= 210
        minimumCanny = .01;
        maximumCanny = .125; 
        CFval = .525;
    elseif switchfactor <= 240
        minimumCanny = .0125;
        maximumCanny = .15;
        CFval = .5;
    else
        minimumCanny = .015;
        maximumCanny = .2;
    end
    %%Active Contour (Overlaying mask and Contour) Works
    imshow(grayImage);





    hold on
    mask = false(size(grayImage));
    mask(20:end-20,20:end-20) = true;
    visboundaries(mask,'Color','b');
    bw = activecontour(grayImage, mask, 200, 'edge','ContractionBias',CFval);
    visboundaries(bw,'Color','r');
    title('Initial contour (blue) and final contour (red)');
    figure, imshow(bw)



    title('Segmented Image');
    %%Reading the Contour and Specifying the roof
    bwNew = grayImage;
    bwNew(~bw) = 0;
    figure;
    imshow(bwNew);
 E = entropyfilt(bwNew);
    Eim =E;% rescale(E);
    figure
    imshow(Eim)

    BW1 = imbinarize(Eim, .9);
    imshow(BW1);
    gI2 = bwNew;
    gI2(BW1) = 0;
    imshow(gI2)

    BWf1 = edge(gI2,'canny',[minimumCanny, maximumCanny],sqrt(.075));
    BWf2 = edge(bwNew,'canny',[minimumCanny, maximumCanny],sqrt(.075));
    %BWf2 = edge(gI2,'zerocross',1,[20,100]);
    figure;
    imshowpair(BWf1,BWf2,'montage')

    title('Textured                                   Normal');