clc
clear all
close all

visualizacao = true
nimg = 10;
grao = 'P1500' 
pds = [' a';' b';' c';' d';' e';' f';' g';' h';' i';' j';' l';' m';' n';' o';' p'];
spc = [' aa';' bb';' cc';' dd';' ee';' ff';' gg';' hh';' ii';' jj';' ll';' mm';' nn';' oo';' pp'];

if visualizacao == true
    
    figure(1)
    set(1,'Position',[24 51 1232 650])
    set(1,'NumberTitle','off')
    set(1,'Name','Análise Spectral')

    figure(2)
    set(2,'Position',[150 51 1000 650])
    set(2,'NumberTitle','off')
    set(2,'Name','Statistical Measures of Texture')

end

for  amostra= 1:10
    
    fn = ['C:\Imagens Relatório\090309 L AGUA RL P1500']
    
    if amostra <= nimg
         fn = [fn pds(amostra,:) '.jpg'];
    else
        fn = [fn spc(amostra-nimg,:) '.jpg'];
    end
        
    irgb = imread(fn);
    icinz = rgb2gray(irgb);
    th = graythresh(icinz);

    step=1;
    ireduzida=icinz(1:step:size(icinz,1), 1:step:size(icinz,2));
    se = strel('square',10);

    ivalmax = imtophat(ireduzida,se);
    iajust = imadjust(ivalmax,[0 0.5],[]);

    h = imhist(iajust);
    ibin = im2bw(iajust,th);

    rst(amostra,:)= statxture(iajust);
    
    [labeled,numGant] = bwlabel(ibin,4);
    
    if visualizacao == true
        figure(1),
    
        subplot(2,3,1)
        imshow(icinz),
        title('rgb2gray')
    
        figure(1),
        subplot(2,3,2)
        imshow(iajust),
        title('imadjust')
    
        figure(1),
        subplot(2,3,3)
        imshow(ibin),
        title('im2bw')
    
%2011     [srad, sang, S]=specxture(iajust);
%         figure(1),
%         subplot(2,3,4)
%         plot(srad), 
%         title('srad')
%     
%         figure(1),
%         subplot(2,3,5)
%         plot(sang), 
%         title('sang')
%     
%         figure(1),
%         subplot(2,3,6)
%         imshow(S),
%2011     title('Spectrum Image')
    
     end
   pause(1.2)
end

if visualizacao == true
    figure(2),
    subplot(4,2,1)
    bar(rst(:,1)), grid on;
    title('Intesidade Media')
    figure(2),
    subplot(4,2,2)
    bar(rst(:,2)), grid on;
    title('Contraste Medio')
    figure(2),
    subplot(4,2,3)
    bar(rst(:,3)), grid on;
    title('R')
    figure(2),
    subplot(4,2,4)
    bar(rst(:,4)), grid on;
    title('3º Momento')
    figure(2),
    subplot(4,2,5)
    bar(rst(:,5)), grid on;
    title('Uniformidade')
    figure(2),
    subplot(4,2,6)
    bar(rst(:,6)), grid on;
    title('Entropia')
end

% somamedias = sum(mediaGrao);
% 
% mediaponderada = 1*(mediaGrao(1)/somamedias)+2*(mediaGrao(2)/somamedias)+3*(mediaGrao(3)/somamedias)+4*(mediaGrao(4)/somamedias)+5*(mediaGrao(5)/somamedias);

% numtam = 0;
% for i = 1 :8
%     if mediaGrao(i)~= 0
%         numtam = numtam + 1;
%     end
% end


%if visualizacao == true
%     figure(3),plot(mediaGrao, 'm - *'), grid on;
%     title(mean(rst(:,3)));
%     xlabel('raio elemento estruturante (pixels)');
%     ylabel('número Grãos');
%end

%fdsurfft(icinz)

