热在Matlab中获得每米像素

时间:2019-06-23 12:34:40

标签: matlab image-processing pixel rasterizing

我有一个向量shapefile,它以“米”为单位呈现整个德国的边界。我根据分别代表300米的每个像素将其转换为栅格格式。转换后,我在matlab中使用imfinfo()访问了映像信息。但是结果给我的单位值是“英寸”,此刻我很困惑,不知道如何将英寸转换为米作为像素大小单位。你能给我个主意吗?

`% Code
R6 = shaperead('B6c.shp');
%Nord
XN6 = double(R6(4).X); YN6 = double(R6(4).Y);
XN6min = min(XN6(XN6>0)); XNmax = max(XN6);
YN6min = min(YN6(YN6>0)); YNmax = max(YN6);
%Bayern
XB6 = double(R6(7).X); YB6 = double(R6(7).Y);
XB6min = min(XB6(XB6>0)); XB6max = max(XB6);
YB6min = min(YB6(YB6>0)); YB6max = max(YB6);
%Schleswig-Holstein
XSH6 = double(R6(9).X); YSH6 = double(R6(9).Y);
XSH6min = min(XSH6(XSH6>0)); XSH6max = max(XSH6);
YSH6min = min(YSH6(YSH6>0)); YSH6max = max(YSH6);
%Sachsen
XS6 = double(R6(6).X); YS6 = double(R6(6).Y);
XS6min = min(XS6(XS6>0)); XS6max = max(XS6);
YS6min = min(YS6(YS6>0)); YS6max = max(YS6);
dx = round(XS6max-XN6min);
dy = round(YSH6max-YB6min);
M = round((dx)/300);enter code here N = round((dy)/300);
A6 = zeros(M,N); %initiating image matrix based on 4 limiting States
%transformation from world to pixel coordinates
xpix_bw =(((XBW-XN6min)*M)/dx)'; 
ypix_bw =(((YBW-YB6min)*N)/dy)';
xbw6=round(xpix_bw); xbw6=xbw6(~isnan(xbw6));
ybw6=round(ypix_bw); ybw6=ybw6(~isnan(ybw6));
%line drawing
for i=1:1:length(xbw6)-1
    j=i+1;
    x1=xbw6(i); x2=xbw6(j); y1=ybw6(i); y2=ybw6(j);
    nn=atan2((y2-y1),(x2-x1)); % azimuthal angle
if x2==x1
    l=abs(y2-y1);
else
    l = round((x2-x1)/cos(nn)); % horizontal distance
end
xx=zeros(l,1); %empty column
yy=zeros(l,1); %empty column
% creating line along slope distance
for i=1:1:l
    xx(i)=round(x1+cos(nn)*i); 
    yy(i)=round(y1+sin(nn)*i);
    A6(xx(i)+1,yy(i)+1) = 256;
end
end
imwrite(A6, 'Untitled_0506_300.tif','Resolution', 300);`

0 个答案:

没有答案