2016-05-12 60 views
0

我目前正在使用MATLAB從空中/衛星圖像中檢測道路/高速公路。我已經編寫了關於道路及其周圍環境強度差異的概念的代碼。但是效率並不是很高,因爲它也在探測非道路實體。除此之外,我還將檢測這些道路上的車輛,並嘗試計算道路的寬度。你能幫我改進我現在的方法或提出一種新的方法嗎?從航拍圖像中檢測道路和車輛

在此先感謝! :)

我附上我的MATLAB代碼進行審查。

clc 
clear all 
close all 

a=rgb2gray(imread('freeway24.tif')); 

a2=mean(a); 
t=min(a2); 

b=lt(a,t); 
[row_b, column_b]=size(b); 

for i=1:row_b 
for j=1:column_b 
    if b(i,j)~=1 
     b(i,j)=0; 
    else 
     b(i,j)=255; 
    end 
end 
end 

bw0=bwareaopen(b,50); 
bw1=bwmorph(bw0,'clean'); 
bw2=bwmorph(bw1,'majority'); 
bw3=bwmorph(bw2,'fill'); 
bw4=imfill(bw3,'holes'); 

[row_final,column_final]=size(bw4); 
bw_final=zeros(); 
for i=1:row_final 
for j=1:column_final 
    if bw4(i,j)==1 
     bw_final(i,j)=a(i,j); 
    else 
     bw_final(i,j)=0; 
    end 
end 
end 

subplot(1,2,1); 
imshow(a); 
title('Original Image'); 
subplot(1,2,2); 
imshow(bw_final); 
title('After detection'); 

注意:由於我沒有10個聲望點,我無法發佈輸入圖像。我在這裏上傳了圖片的鏈接。 https://drive.google.com/open?id=0B0MIQKh4Irk8MVlXYnhIcmpxTG8

回答

0

我建議你多學習有關計算機視覺,尤其是這些功能的MATLAB:imcloseimerodeimdilatebwareaopen。 幫助你的代碼如下。您只需在最後的imshow之前添加它。

% Calculate disk of radius 2 pixels, 4 pixels diameter 
se = strel('disk', 2); 
% Connect the white pixels that are less than 4 pixels apart 
bw_final = imclose(bw_final, se); 
% Connect the black pixels that are less than 4 pixels apart 
bw_final = ~imclose(~bw_final, se); 

% Calculate 2% of the image pixels 
num2Percent = round(numel(bw_final)/50); 
% Remove white area smaller than 2% 
bw_final = bwareaopen(bw_final, num2Percent); 
% Remove black area smaller than 2% 
bw_final = ~bwareaopen(~bw_final, num2Percent); 
+1

肯定會讀到這些!感謝幫助的人!但是,這消除了高速公路上的車輛。我需要將個別車輛檢測爲斑點,以便我可以檢測它們的寬度。有什麼建議麼? –

+0

哦,我以爲你想把車輛拆下來,對不起。只需刪除代碼行「刪除小於2%的白色區域」。如果有幫助,請標記爲答案和upvote :) – DomDev

+0

工作正常!非常感謝!是的,會豎起大拇指! –