i=imread('e:\\2.jpg');j=rgb2gray(i);
imshow(j);imwrite(j,'e:\\2.tif')
A=imread('e:\\2.tif');B= imrotate(A,-90);
imshow(B);imwrite(B,'e:\\2.tif')
i=imread('e:\\2.tif');
j=histeq(i);imshow(j);
figure,subplot(1,2,1),imhist(i);
subplot(1,2,2),imhist(j)
i=imread('e:\\2.tif');
j=edge(i,'canny',[0.04,0.25],1.5);
imshow(j)
clc,clear;
f=imread('e:\\2.bmp');
subplot(121),imshow(f),title('e:\\2.jpeg');
f1=imnoise(f,'gaussian',0.002,0.0008);
%subplot(222),imshow(f1),title('e:\\2.tif');
k1=floor(3/2)+1;
k2=floor(3/2)+1;
X=f1;
[M,N]=size(X);
uint8 Y=zeros(M,N);
funBox=zeros(3,3);
for i=1:M-3
for j=1:N-3
funBox=X(i:i+3,j:j+3);
s=sum(funBox(:));
h=s/9;
Y(i+k1,j+k2)=h;
end;
end;
Y=Y/255;
subplot(122),imshow(Y),title('均值滤波');
clear all;
I=imread('e:\\2.bmp');
%读入预处理图像
imshow(I)
%显示预处理图像
K1=filter2(fspecial('average',3),I)/255;
%进行3*3均值滤波
K2=filter2(fspecial('average',5),I)/255;
%进行5*5均值滤波
K3=filter2(fspecial('average',7),I)/255;
%进行7*7均值滤波
figure,imshow(K1)
figure,imshow(K2)
figure,imshow(K3)
clc; clear all; close all;
% 载入图像
Img = imread('e:\\2.jpg');
if ndims(Img) == 3
I=rgb2gray(Img);
else
I = Img;
end
BW = im2bw(I, graythresh(I)); % 二值化
figure;
subplot(2, 2, 1); imshow(Img);
title('原图像', 'FontWeight', 'Bold');
subplot(2, 2, 2); imshow(Img);
title('网格标记图像', 'FontWeight', 'Bold');
hold on;
[xt, yt] = meshgrid(round(linspace(1, size(I, 1), 10)), ...
round(linspace(1, size(I, 2), 10)));
mesh(yt, xt, zeros(size(xt)), 'FaceColor', ...
'None', 'LineWidth', 3, ...
'EdgeColor', 'r');
subplot(2, 2, 3); imshow(BW);
title('二值图像', 'FontWeight', 'Bold');
[n1, n2] = size(BW);
r = floor(n1/10); % 分成10块,行
c = floor(n2/10); % 分成10块,列
x1 = 1; x2 = r; % 对应行初始化
s = r*c; % 块面积
for i = 1:10
y1 = 1; y2 = c; % 对应列初始化
for j = 1:10
if (y2<=c || y2>=9*c) || (x1==1 || x2==r*10)
% 如果是在四周区域
loc = find(BW(x1:x2, y1:y2)==0);
[p, q] = size(loc);
pr = p/s*100; % 黑色像素所占的比例数
if pr <= 100
BW(x1:x2, y1:y2) = 0;
end
end
y1 = y1+c; % 列跳跃
y2 = y2+c; % 列跳跃
end
x1 = x1+r; % 行跳跃
x2 = x2+r; % 行跳跃
end
[L, num] = bwlabel(BW, 8); % 区域标记
stats = regionprops(L, 'BoundingBox'); % 得到包围矩形框
Bd = cat(1, stats.BoundingBox);
[s1, s2] = size(Bd);
mx = 0;
for k = 1:s1
p = Bd(k, 3)*Bd(k, 4); % 宽*高
if p>mx && (Bd(k, 3)/Bd(k
, 4))<1.8
% 如果满足面积块大,而且宽/高<1.8
mx = p;
j = k;
end
end
subplot(2, 2, 4);imshow(I); hold on;
rectangle('Position', Bd(j, :), ...
'EdgeColor', 'r', 'LineWidth', 3);
title('标记图像', 'FontWeight', 'Bold');
因篇幅问题不能全部显示,请点此查看更多更全内容