how to find features from '.txt' files?
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics and Visualization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!