需要一段matlab代码计算图像灰度均值、灰度方差、灰度熵、灰度能量、灰度峰度、相关度、对比度、熵率
时间: 2023-10-23 12:11:20 浏览: 192
matlab 求图像平均灰度值的 代码
5星 · 资源好评率100%
以下是计算图像灰度均值、灰度方差、灰度熵、灰度能量、灰度峰度、相关度、对比度、熵率的Matlab代码:
% 读取图像
img = imread('lena.png');
% 转换为灰度图像
gray_img = rgb2gray(img);
% 计算灰度均值
gray_mean = mean(mean(gray_img));
% 计算灰度方差
gray_var = var(double(gray_img(:)));
% 计算灰度熵
gray_entropy = entropy(gray_img);
% 计算灰度能量
gray_energy = sum(sum(double(gray_img).^2));
% 计算灰度峰度
gray_kurtosis = kurtosis(double(gray_img(:)));
% 计算相关度
[h, w] = size(gray_img);
x = repmat((1:w), h, 1);
y = repmat((1:h)', 1, w);
gray_corr = sum(sum(double(gray_img) .* (x - mean(x)) .* (y - mean(y)))) / (sum(sum(double(gray_img))) * std(x(:)) * std(y(:)));
% 计算对比度
gray_contrast = std(double(gray_img(:))) * sqrt((2^(size(gray_img, 3))) - 1);
% 计算熵率
gray_entropy_rate = gray_entropy / (size(gray_img, 1) * size(gray_img, 2));
% 输出结果
disp(['灰度均值:', num2str(gray_mean)]);
disp(['灰度方差:', num2str(gray_var)]);
disp(['灰度熵:', num2str(gray_entropy)]);
disp(['灰度能量:', num2str(gray_energy)]);
disp(['灰度峰度:', num2str(gray_kurtosis)]);
disp(['相关度:', num2str(gray_corr)]);
disp(['对比度:', num2str(gray_contrast)]);
disp(['熵率:', num2str(gray_entropy_rate)]);
阅读全文