clc,
clear all;
close all;
file_path ='D:\01_picture\';% 图像文件夹路径(注意misc文件夹后有一个斜杠)
img_path_list = dir(strcat(file_path,'*.jpg'));%获取该文件夹中所有jpg格式的图像
img_num = length(img_path_list);%获取图像总数量
if img_num > 0 %有满足条件的图像
for j = 1:img_num %逐一读取图像
image_name = img_path_list(j).name;% 图像名
image =imread(strcat(file_path,image_name));
image_size=size(image);%判断维度,将彩色图片转换为灰度图
dimension=numel(image_size);
if dimension==3
Gina_grey=im2gray(image);
Gina=double(Gina_grey);%数据类型转换
avg(j)=mean2(Gina_grey);%求均值,可以反映亮度
std(j)=std2(Gina_grey);%相对标准差
a(j)=std(j).^2;%方差 ,灰度方差评价法
[r,c,b] = size(image); % Get the size of img
dx = 1;
dy = 1;
for k = 1 : b
band =double( image(:,:,k));
[dzdx,dzdy] = gradient(band,dx,dy);
s = sqrt((dzdx .^ 2 + dzdy .^2) ./ 2);
g(k) = sum(sum(s)) / ((r - 1) * (c - 1));
end
%求平均梯度
outval(j)= mean(g);
%求图片信息熵
[C,L]=size(Gina_grey); %求图像的规格
Img_size=C*L; %图像像素点的总个数
G=256; %图像的灰度级
H_x=0;
nk=zeros(G,1);%产生一个G行1列的全零矩阵
for i=1:C
for p=1:L
Img_level=Gina(i,p)+1; %获取图像的灰度级
nk(Img_level)=nk(Img_level)+1; %统计每个灰度级像素的点数
end
end
for k=1:G %循环
Ps(k)=nk(k)/Img_size; %计算每一个像素点的概率
if Ps(k)~=0; %如果像素点的概率不为零
H_x=-Ps(k)*log2(Ps(k))+H_x; %求熵值的公式
end
end
e(j)=H_x;%所有图像的熵值
end
end
end
MATLAB批量求图片均值、相对标准差、平均梯度、信息熵的代码
最新推荐文章于 2023-04-25 12:00:00 发布