how to find features from '.txt' files?

1 visualización (últimos 30 días)
santhosh kumar buddepu
santhosh kumar buddepu el 26 de Oct. de 2021
Comentada: santhosh kumar buddepu el 26 de Oct. de 2021
initially my data is like this :
Hy_r=h5read('D:\PSNR_survey\Plastic_tiffin_box_eps9\Plastic_tiffin_box_antennaX_Ey_eps9_merged.out','/rxs/rx1/Ey');
after some steps I have used:
imwrite (mat2gray(Gxx_t2), 'NEW IMAGE.png');
[X_raw,map] = imread ('NEW IMAGE.png');
m=mean(X_raw');
m=uint8(m);
X_avg=X_raw-m'; % removal of direct path or clutter removal done
imagesc(X,z_depth,X_avg)
The values X_avg are saved in excel sheet as ' text (tab delimited)'.
now I can recall X_avg directly by using:
y=dlmread('X_avg.txt', '\t', 0, 0);
figure,imagesc(X,z_depth,X_avg)
I need to use dlmread to read the data and i need to use imagesc instead of imread and imshow.
Like this I have created a database of around 40 text files for metal pipe, steel box, plastic box. I want to extract statistical features from all the files for that I have calculated mean, variance, skew, kurtosis for single file.
[pixelCounts GLs] = imhist(X_avg); % GL-gray levels
% Get the number of pixels in the histogram.
numberOfPixels = sum(pixelCounts);
% Get the mean gray lavel.
meanGL = sum(GLs .* pixelCounts) / numberOfPixels
% Get the variance, which is the second central moment.
varianceGL = sum((GLs - meanGL) .^ 2 .* pixelCounts) / (numberOfPixels-1)
% Get the standard deviation.
sd = sqrt(varianceGL);
% Get the skew.
skew = sum((GLs - meanGL) .^ 3 .* pixelCounts) / ((numberOfPixels - 1) * sd^3)
% Get the kurtosis.
kurtosis = sum((GLs - meanGL) .^ 4 .* pixelCounts) / ((numberOfPixels - 1) * sd^4)
How to calculate these features for all files using single code and how to store these features?

Respuesta aceptada

KSSV
KSSV el 26 de Oct. de 2021
Editada: KSSV el 26 de Oct. de 2021
txtFiles = dir('*.txt') ;
N = length(txtFiles) ;
meanGL= zeros(N,1);
varianceGL = zeros(N,1) ;
sd = zeros(N,1) ;
skew = zeros(N,1);
kurtosis = zeros(N,1) ;
for i = 1N
y=dlmread(txtFiles(i).name, '\t', 0, 0);
figure,imagesc(X,z_depth,X_avg)
[pixelCounts GLs] = imhist(X_avg); % GL-gray levels
% Get the number of pixels in the histogram.
numberOfPixels = sum(pixelCounts);
% Get the mean gray lavel.
meanGL(i) = sum(GLs .* pixelCounts) / numberOfPixels
% Get the variance, which is the second central moment.
varianceGL(i) = sum((GLs - meanGL) .^ 2 .* pixelCounts) / (numberOfPixels-1)
% Get the standard deviation.
sd(i) = sqrt(varianceGL);
% Get the skew.
skew(i) = sum((GLs - meanGL) .^ 3 .* pixelCounts) / ((numberOfPixels - 1) * sd^3)
% Get the kurtosis.
kurtosis(i) = sum((GLs - meanGL) .^ 4 .* pixelCounts) / ((numberOfPixels - 1) * sd^4)
end
  5 comentarios
santhosh kumar buddepu
santhosh kumar buddepu el 26 de Oct. de 2021
thank you sir
santhosh kumar buddepu
santhosh kumar buddepu el 26 de Oct. de 2021
clc;
clear; close all;
% Specify the folder where the files live.
myFolder = 'D:\gpr_targets';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '**/*.txt'); % requires to read folders and its subfolders.
theFiles = dir(filePattern);
N = length(theFiles) ;
meanGL= zeros(N,1);
varianceGL = zeros(N,1) ;
sd = zeros(N,1) ;
skew = zeros(N,1);
kurtosis = zeros(N,1) ;
Ex = zeros(N, 4);
for i = 1 : N
baseFileName = theFiles(i).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
A= dlmread(theFiles(i).name, '\t', 0, 0);
[pixelCounts GLs] = imhist(A); % GL-gray levels
% Get the number of pixels in the histogram.
numberOfPixels = sum(pixelCounts);
% Get the mean gray lavel.
meanGL = sum(GLs .* pixelCounts) / numberOfPixels
% Get the variance, which is the second central moment.
varianceGL = sum((GLs - meanGL) .^ 2 .* pixelCounts) / (numberOfPixels-1)
% Get the standard deviation.
sd = sqrt(varianceGL);
% Get the skew.
skew = sum((GLs - meanGL) .^ 3 .* pixelCounts) / ((numberOfPixels - 1) * sd^3)
% Get the kurtosis.
kurtosis = sum((GLs - meanGL) .^ 4 .* pixelCounts) / ((numberOfPixels - 1) * sd^4)
% feature variables
thisFeatureVector = [meanGL varianceGL skew kurtosis];
Ex(i, 1 : length(thisFeatureVector)) = thisFeatureVector;
end
worksheetName = 'Results';
cellReference = sprintf('A%d', i);
xlswrite('D:\gpr_targets\featuresnew1.xls', Ex, worksheetName, cellReference);
I have done like this and I got features but features starts from 48th row and if I will keep xlswrite inside loop upto 48th row same feature is coming. please look into this issue sir.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Descriptive Statistics and Visualization en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by