文字图像:
自然图像的:
可见文字图像的直方图像是斜坡状的,而自然图像的下降比较陡
线条多的图像:
matlab脚本
clear all;
clc
close all;
imgpath = 'E:\img\lines3.jpg';
im = imread(imgpath);
[m,n,c] = size(im);
ratio = 500/(min(m,n));
im = imresize(im, ratio);
[m,n,c] = size(im);
if m>n
y = round((m-n)/2);
x = 0;
else
y = 0;
x = round((n-m)/2);
end
w = min(m,n);
%裁剪中间的正方形
im = imcrop(im, [x,y,w,w]);
[m,n,c] = size(im);
figure; imshow(im); title('im crop');
if 1 ~= c
gray = rgb2gray(im);
else
gray = im;
end
gray = double(gray);
f = fspecial('laplacian');
fim=imfilter(gray, f, 'replicate');
figure; imshow(fim,[]); title('fim');
figure; imshow(fim); title('fim'); colormap jet; colorbar;
af = abs(fim);
figure; imshow(af,[]); title('abs fim');
afw = af > 30;
figure; imshow(afw,[]); title('afw');
fs = fim(:);
[x,r] = hist(abs(fs), 50);
%低频的去掉
x(1:3) = [];
r(1:3) = [];
figure; bar(r,x); title('abs(laplace) hist');
xlabel('abs(laplace)');
ylabel('times');
varfs = var(double(fs));
abfs = abs(fs);
mx = max(abfs);
mn = mean(abfs);
disp(sprintf('var:%.2f, max:%.2f, mean:%.2f, %s', varfs, mx, mn, imgpath));