Matlab代码:

clc,clear,close all

I=imread(‘pic.png’);
g=rgb2gray(I); %灰度化处理

figure
subplot(221),imshow(I);
title(‘原图’);
subplot(222),imshow(g);
title(‘灰度图’);

[m, n]=size(I);

%水平投影
for x=1:m
S(x)=sum(I(x,:));
end
x=1:m;
subplot(223),plot(x,S(x));
title(‘水平投影’);

%垂直投影
for y=1:n
S(y)=sum(I(1:m,y));
end
y=1:n;
subplot(224),plot(y,S(y));
title(‘垂直投影’);

结果如下:[

](http://www.wjgbaby.com/wp-content/uploads/2017/10/17102301-300x155.jpg)
](http://www.wjgbaby.com/wp-content/uploads/2017/10/17102301-300x155.jpg)