如何在形状文件或ras中应用图像处理

2024-05-23 22:42:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望使用matlab或python对ArcGIS文件进行一些图像处理。 我的目标是处理形状文件或光栅一样的正常图像。我们可以得到它的任何部分,并用任何图像算法进行处理。然后添加坐标信息以显示在ArcGIS中。 我在网上搜索,发现有一种方法可以做到。我们可以在matlab中使用tif图像。但是对于matlab来说太大了,即使我使用ArcGIS中的一小块区域来剪切tif,也无法处理。请看它的代码和链接。 有没有一种方法可以有效且容易地做到这一点?任何建议都会有帮助。在

谢谢。

clc;close all;clear; %below is using matlab blockproc to read a large file,but I failed to read a tiff % src_filename='F:/1.tif'; % fun = @(block_struct) block_struct.data; % B = blockproc(src_filename,[5 5],fun); % % %----------below is how to do transform the coordinates---------------------------------------------------------------- % code from:http://www.cnblogs.com/denny402/p/4684770.html [pic,R]=geotiffread('F:/lenoir/Lidar2007/1.tif'); [m,n,~]=size(pic); figure(1),imshow(pic) hold on; scatter(n/4,m/4,500,'r.'); [lon,lat]=pix2map(R,m/4,n/4) figure(2),mapshow(pic,R); mapshow(lon,lat,'Marker','.','MarkerEdgeColor','r'); axis off; disp(['(',num2str(m/4),',',num2str(n/4),') -> (',num2str(lon),',',num2str(lat),')']); %R.RasterWidthInWorld x=R.XLimWorld(1)+(3/4)*R.RasterWidthInWorld; y=R.YLimWorld(1)+(1/4)*R.RasterHeightInWorld; figure(3),mapshow(pic,R),axis off; mapshow(x,y,'Marker','*','MarkerEdgeColor','r'); [row,col]=map2pix(R,x,y); figure(4),imshow(pic); hold on; scatter(col,row,100,'r*'); disp(['(',num2str(x),',',num2str(y),') -> (',num2str(row),',',num2str(col),')']);

Tags: 文件to方法图像colrowfigurelon
1条回答
网友
1楼 · 发布于 2024-05-23 22:42:28

关于前面的注释,您可以在下面的代码中找到一段代码,其中显示了基于可从指定页面下载的国家/地区边界文件进行操作的简化示例。在

首先,我在图形中读取,然后提取德国的边界框,绘制它并将其添加到坐标系中。我使用shapewrite创建新的形状,读取新的形状并绘制它。在

在第二部分中,我将德国绘制为多边形,并将其另存为和图像,然后我再次读入其中并使用imshow绘制它。在

这有帮助吗?在

clear all
close all

% https://github.com/jalbertbowden/world-data/blob/master/world-borders/TM_WORLD_BORDERS-0.3/TM_WORLD_BORDERS-0.3.dbf
CountryShape = shaperead('TM_WORLD_BORDERS-0.3.dbf');


countrynames{1}='Germany';
countrynames{2}='United Kingdom';
countrynames{3}='Netherlands';
countrynames{4}='France';
countrynames{5}='Belgium';
countrynames{6}='Denmark';
countrynames{7}='Norway';

figure
for i = 1:size(countrynames,2)
    xboundary = CountryShape(strcmp({CountryShape.NAME},countrynames{i})).X;
    yboundary = CountryShape(strcmp({CountryShape.NAME},countrynames{i})).Y;
    maxx = max(xboundary);
    minx = min(xboundary);
    maxy = max(yboundary);
    miny = min(yboundary);
    outerbox_x = [minx maxx maxx minx minx];
    outerbox_y = [maxy maxy miny miny maxy];

    subplot (4,2,i)
    hold on
    plot(xboundary,yboundary,'k-')
    plot(outerbox_x, outerbox_y,'r-')

    actual_id = find(strcmp({CountryShape.NAME},countrynames{i}));
    CountryShape(actual_id).X = [CountryShape(actual_id).X outerbox_x];
    CountryShape(actual_id).Y = [CountryShape(actual_id).Y outerbox_y];
end    
shapewrite(CountryShape,'newshape');
CountryShape2 = shaperead('newshape.dbf');

id_of_germany = find(strcmp({CountryShape2.NAME},'Germany'));
xboundary2 = CountryShape2(id_of_germany).X;
yboundary2 = CountryShape2(id_of_germany).Y;
subplot (4,2,i+1)
plot(xboundary2,yboundary2,'k-')

figure
fill(xboundary(~isnan(xboundary)),yboundary(~isnan(yboundary)),'r')

IM = getframe(gcf);
imwrite(IM.cdata,'myimage.png');
newIM = imread('myimage.png');
imshow(newIM)

相关问题 更多 >