clc
clear all
close all

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

sample_number = ['00.jpg'; '01.jpg'; '02.jpg'; '03.jpg'; '04.jpg'; '05.jpg'; '06.jpg'; '07.jpg'; '08.jpg'; '09.jpg'];

for n= 1:10
    %tipo de amostras
    sample =['Micro P500 Normal ' sample_number(n,:)];
    %directório imagens
    fn = ['C:\Programas\MATLAB71\work\Ensaios Mestrado - 05.05.08\Imagens 2ºparte Trabalho\22.01.09 - Testes\P500\' sample ];
    
    o_img = imread(fn);

    %Pré-Processamento Imagem:
    bw_img = rgb2gray(o_img);

    %limites que definem a zona rectnagular
    %central da imagem com qualidade para
    %ser analizada.
    %- vertical:
    uvb = size(bw_img,1)-151;
    lvb = 150;
    %- horizontal:
    lhb = 350;
    rhb = size(bw_img,2)-351;
    
    step=2;
    scl_img=bw_img(lvb:step:uvb, lhb:step:rhb);
    
    se = strel('square',10);
    scl_img = imtophat(scl_img,se);
    scl_img = imadjust(scl_img,[0 0.5],[]);

    th = graythresh(scl_img);
    bin_img = im2bw(scl_img,th);
    %Final Pré-Processamento.

    %Cálculo Spectral Imagens
    [srad(n,:), sang(n,:), S]=specxture(scl_img);
    
    %Apresentação Resultados
%     figure(1),
%     
%     subplot(2,3,1)
%     imshow(bw_img),
%     title('rgb2gray')
%     
%     figure(1),
%     subplot(2,3,2)
%     imshow(scl_img),
%     title('imadjust')
%     
%     figure(1),
%     subplot(2,3,3)
%     imshow(bin_img),
%     title('im2bw')
%   
%     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),
%     title('Spectrum Image')
% 
end

figure(2),
x= 1:1:224;
plot(x,srad(1,:),x,srad(2,:),x,srad(3,:),x,srad(4,:),x,srad(5,:),x,srad(6,:),x,srad(7,:),x,srad(7,:),x,srad(8,:),x,srad(9,:),x,srad(10,:));

figure(3),
x= 1:1:180;

plot(x,sang(1,:),x,sang(2,:),x,sang(3,:),x,sang(4,:),x,sang(5,:),x,sang(6,:),x,sang(7,:),x,sang(7,:),x,sang(8,:),x,sang(9,:),x,sang(10,:));
