%代码如下P=imread('e:\qwe.jpg');%在指定路径下存原图片I=rgb2gray(P);%获得灰度图像a=100;b=100;l=0.5;%栅格大小B=imresize(I,[a/lb/l]);%转化为指定像素大小J=floor(B/255);longitude=0:a;latitude=0:b;%坐标轴控制axes('GridLineStyle','-');set(gca,'ydir','reverse');%set(gca,'xdir','reverse')holdonaxis([0,a,0,b]);set(gca,'xtick',0:10:a,'ytick',0:10:b);set(gca,'xtick',longitude,'ytick',latitude)gridonfori=1:a/l-1forj=1:b/l-1if(J(i,j)==0)y=[i,i,i+1,i+1]*l;x=[j,j+1,j+1,j]*l;h=fill(x,y,'r');holdonendendend