【发布时间】:2020-04-03 18:02:15
【问题描述】:
我想在 MATLAB 中在每个过滤器窗口的中心像素处执行 Census 变换,如下所示:
如果图片没有出现,另外一个链接:https://i.ibb.co/9Y6LfSL/Shared-Screenshot.jpg
我对代码的初步尝试是:
function output =census(img,census_size)
img_gray = rgb2gray(img);
[y,x]=size(img_gray);
borders = floor(census_size/2); % limit to exclude image borders when filtering
for(iy = 1+borders : y-borders)
for(ix = 1+borders : x-borders)
f=img_gray(iy-borders:iy+borders,ix-borders:ix+borders);
iix=ix-borders;
iiy=iy-borders;
% shift=bitsll(img_out(iiy,iix),1);
img_out(iiy,iix)= % Must be Implemented with census
end
end
%normalised_image = img_out ./ max(max(img_out)) ;
output=img_out;
imshow(normalised_image);
end
第二个 for 循环中的 iix 和 iiy 代表我当前的中心像素位置。 f 是我当前的过滤器窗口。
除了与窗口的其他像素进行比较操作外,我需要将每个比较结果设置为逻辑 1/0,并将总结果(我猜是通过移位)扩展为 8 位数据,然后将此二进制数转换为一个十进制数。我如何在 MATLAB 中以实用的方式做到这一点? 我在 Python 中检查过这个:https://stackoverflow.com/a/38269363/12173333
但无法在 MATLAB 中进行相似性分析。
【问题讨论】:
-
天真的方法是在你的 2 个循环中添加另外 2 个循环,用于我们像素的邻居。试试看,然后你就可以开始思考实用/快速的方法了
-
我想我可以做到,我可以通过将中心像素与相邻像素进行比较来形成新的逻辑窗口。我现在正在考虑如何通过从最低行开始左移、省略中心像素并设置中心像素的值来扩展我的二进制结果。例如,如果我的逻辑数组是 [ 1 0 0; 0 中心 1 ; 1 1 0] 我的中心应该等于 uint8(0 1 1 1 0 0 0 1)
标签: matlab image-processing binary filtering