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

时间:2015-10-27 16:15:55

标签: python matlab arcgis

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

谢谢。

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),')']);

1 个答案:

答案 0 :(得分:1)

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

首先,我读取的形状比我提取德国的边界框,绘制它并将其添加到坐标。我使用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)