Muesli_基于声呐图像寻雷难度的图像复杂度度量——MATLAB代码

clc;clear all;
X = imread("your img path");
X = double(im2gray(X));

[m, n] = size(X);
kernal_size = 3;%3,5,9,25

h_mean = fspecial('average',[kernal_size kernal_size]);
I_mean = conv2(X,h_mean);
temp_mean = I_mean((kernal_size-1)/2+1:m+(kernal_size-1)/2,(kernal_size-1)/2+1:n+(kernal_size-1)/2);
X_std = (X-temp_mean).^2;
h_sum = ones(kernal_size)./(kernal_size^2);
I_std_sum = conv2(X_std,h_sum);
temp_std = I_std_sum((kernal_size-1)/2+1:m+(kernal_size-1)/2,(kernal_size-1)/2+1:n+(kernal_size-1)/2);
L = temp_std ./ (temp_mean.^2);

%L = normimg(L);
figure();
subplot(121)
imshow(X,[]);
colorbar;
subplot(122)
imshow(L,[]);
colorbar;

%利用sobel算子来求
Gx = [-1 0 1; -2 0 2; -1 0 1];
Gy = [1 2 1; 0 0 0; -1 -2 -1];
L_gx = conv2(L,Gx);
L_gy = conv2(L,Gy);
kernal_size_s = 3;
L_Gx = L_gx((kernal_size_s-1)/2+1:m+(kernal_size_s-1)/2,(kernal_size_s-1)/2+1:n+(kernal_size_s-1)/2);
L_Gy = L_gy((kernal_size_s-1)/2+1:m+(kernal_size_s-1)/2,(kernal_size_s-1)/2+1:n+(kernal_size_s-1)/2);
L_Sobel = (L_Gx.^2 + L_Gy.^2).^0.5;
figure();
imshow(L_Sobel ,[]);
colorbar;
Muesli = mean(mean(L_Sobel))

这是根据上一篇文章来写的matlab代码,求间隙度时用的是滤波器原理,没有用到这一篇利用积分图像来快速计算的这一部分。

利用积分图像来快速计算我做了,但是应该是做错了,做出来的图像十分有问题。后面会加以改正。

你可能感兴趣的:(matlab,开发语言,图像处理)