我在栅栏后面有一些鹿的图像,我试图去除栅栏,以便我们可以直接看到没有栅栏的鹿。到目前为止,我已经对一个体面的质量进行了细分(确定了栅栏的坐标),并试图用附近的颜色替换这些坐标的颜色来模拟移除栅栏。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