我在柵欄後面有一些鹿的圖像,我試圖去除柵欄,以便我們可以直接看到沒有柵欄的鹿。到目前爲止,我已經對一個體面的質量進行了細分(確定了柵欄的座標),並試圖用附近的顏色替換這些座標的顏色來模擬移除柵欄。MATLAB:過濾出圖像的一部分
MATLAB中有一些圖像處理函數可以幫助我輕鬆完成目標嗎?我嘗試了下面的代碼,我試圖找到最近的座標不是圍欄的一部分,但「〜ismember([i_temp,j],[ii,jj])」不起作用,因爲我是試圖比較座標,但相反,它似乎將i_temp和j作爲單獨變量進行比較,即i_temp不在ii或jj中,並且在ii或jj中是j。
%% 5. Locate pixel locations of the segmented image
% Now that the fence has been segmented. Locate the pixel locations of the
% segmented image
[ii,jj] = find(Img_threshold2==1);
n = length(ii); % Get a count of the number of coordinates
Rout = Rin;
Gout = Gin;
Bout = Bin;
%% 6. Recolor the areas of the fence with the nearest color available
for k=1:n
i = ii(k);
j = jj(k);
keepLooping = true;
i_add = 0;
j_add = 0;
i_coord = 0;
j_coord = 0;
% Find the nearest coordinate that is not a part of the fence
while keepLooping
i_add = i_add + 1;
j_add = j_add + 1;
% Check right
i_temp = i + i_add;
if ~ismember([i_temp,j],[ii,jj])
i_coord = i_temp;
j_coord = j;
break
end
% Check left
i_temp = i - i_add;
if ~ismember([i_temp,j],[ii,jj])
i_coord = i_temp;
j_coord = j;
break
end
% I would do check up and down, but the left/right doesn't even work
% since ismember doesn't work as I expected
end
% Replace the color of the fence coordinate to the nearest non-fence
% coordinate determined above
Rout(i,j) = Rin(i_coord,j_coord);
Gout(i,j) = Rin(i_coord,j_coord);
Bout(i,j) = Rin(i_coord,j_coord);
end
EDIT 14年9月20日: 試過bwdist與下面的代碼,其中IIN是輸入圖像和image_threshold2是分段的圍欄。籬笆不是變成最接近的顏色,而是變成綠松石,這是沒有意義的,因爲圖像中沒有綠松石。這是一個展示發生了什麼的截圖。我裁剪了圖像,以便在圖像的一小部分區域進行測試,實際的圖像要大得多,並且有實際的鹿和什麼。截圖:http://gyazo.com/32ab37b8d2d9e137103d330a39d4ecfa
[D,IDX] = bwdist(~Img_threshold2);
% Replace the color of the fence coordinate to the nearest non-fence
% coordinate determined above
Iout = Iin;
Iout(Img_threshold2)=Iout(IDX(Img_threshold2));
你能提供一個你想要處理的圖像的鏈接嗎? – rayryeng 2014-09-19 15:21:40
@Julio Revka,如果提供的答案解決了您的問題,請在左側接受它。 – ASantosRibeiro 2014-09-20 18:37:20