Everythime I try find the area my valours is very wrong.This square has a 10000cm^2 and I don't know how this object has the area ocupped
My code:
close all; clear all; clc; %%
%pasta=('F:\LDSC\Eco\Processamento direto\Versao 3\P3-17032017WW');
pasta=('F:\LDSC\Eco\CAMPOS\2CAMPO\eefd\b\croped');
dire = dir(pasta); % nome do arquivo, DSC* abre todos os arquivos que começam com esse nome
tt = length (dire); % conta quantidade de arquivos semelhantes
w=1;
areareal=zeros(tt-2,100)
c=1;
for i=3:tt arq = fullfile([dire(i).name]); % le 1 arquivo
%Algoritmo pra aplicar o threeshold
y=imread(arq);
%Não esquece de chamar a imagem com o nome e extensão certa. %bw=rgb2gray(y);% FUNÇÃO TRANSFORMA IMAGEM EM CINZA %.90 foi o melhor numero para aplicar o filtro e nao perder qualidade imwrite(y,'foto.JPG') original = imread('foto.JPG'); pt=size(original);%pixelxpixel pixeltotal= pt(1,1)*pt(1,2);
imshow(original);
x = original(:,:,1) < 90;
imshow(x);
[B,L] = bwboundaries(x, 'noholes');
stats = regionprops(L, 'Area');
qtd_x = sum([stats.Area] > 1);
imshow(original);
hold on
for k = 1:length(B)
area = stats(k).Area*10000/(pixeltotal-stats(1).Area); %*0.022469 Valor de pixel calculado
if area > 1 %Valor pra ser lido na AREAREAL
areareal(w,c)=area; c=c+1; end%Aprimoramento do código
%'Abrir Txt com valores de area '
%Imprimir Foto X - Valor de área
if area > 1 boundary = B{k}; plot(boundary(:,2), boundary(:,1), 'black', 'LineWidth', 2); text(boundary(1,2), boundary(1,1), sprintf('%.3f',area),... 'Color', 'black',... 'FontSize', 12,... 'FontWeight', 'bold',... 'BackgroundColor', 'white'); end
end
hold on
% % aqui vai a rotina de préprocessamento
w=w+1; c=1; save
%
end
Best Answer