how to find features from '.txt' files?

조회 수: 1 (최근 30일)
santhosh kumar buddepu
santhosh kumar buddepu 2021년 10월 26일
댓글: santhosh kumar buddepu 2021년 10월 26일
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?

채택된 답변

KSSV
KSSV 2021년 10월 26일
편집: KSSV 2021년 10월 26일
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
santhosh kumar buddepu
santhosh kumar buddepu 2021년 10월 26일
thank you sir
santhosh kumar buddepu
santhosh kumar buddepu 2021년 10월 26일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by