algorithm - 直径提取的 MATLAB 圆形滑动窗口和像素值

标签 algorithm matlab image-processing sliding-window

我正在尝试实现一种算法,该算法需要一个圆形滑动窗口,该窗口遍历图像的所有像素,并且对于每个窗口,我只需要提取位于圆的不同角度的直径上的像素。

enter image description here

我尝试使用上图更好地解释。假设这是一个圆形滑动窗口的结果,我只想获取位于红线上的像素值(直径倾斜 pi/8)。

到目前为止,我写了这些代码行:

I= imread('lena.png'); 
I = im2double(I);
h = fspecial('disk',5);
h = h > 0;
dir = pi/8;
o_image = blockproc(I, [1 1], @(x) MMF2D(x,h,dir), 'BorderSize', [5 5],...
'TrimBorder', false, 'PadPartialBlocks', true);

和函数MMF2D:

function [ o_pixel ] = MMF2D( i_block, i_window, i_directions)
%MMF2D Summary of this function goes here
%   Detailed explanation goes here

new_block = i_block.data .* i_window;

但是从这里开始,我不知道如何继续获取位于直径上的像素。直径可以倾斜任何角度。非常感谢任何帮助!

最佳答案

这是我要做的:

首先创建 mask (如果需要,可以将其放入函数中),并获取相关像素索引作为角度的函数:

%% create mask and get indices as function of angle
o=5;
m=zeros(2*o+1);
m(o+1,:)=1;
theta=0:15:90; % in degrees, theres no need to go beyond 90 deg becuase of symmetry
for n=1:numel(theta)
   id{n}=find(imrotate(m,theta(n),'nearest','crop'));
end;

我使用元胞数组是因为每个角度可以有不同数量的索引。

然后读取图片

I= imread('http://scipy-lectures.github.io/_images/lena.png'); 

将图像 block 重新排列成列

B = im2col(I,[2*o+1 2*o+1],'sliding');

你想要的只是:

for n=1:numel(theta)
    C{n} =  B(id{n},:);
end

C 中的每个单元格元素代表直径为 2*o+1 且角度为 theta 的像素,每个像素都是预先定义的在图像中。
所以 C{1} 将为您提供 theta=0 的所有像素,C{2}theta=15 等...

关于algorithm - 直径提取的 MATLAB 圆形滑动窗口和像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31297554/

相关文章:

graphics - 在 MATLAB 中创建 'timeline' 样式图形

python - 根据特定标准从图像中选择坐标

在一定范围内找到k个邻居的算法?

algorithm - 多项式时间内数的平方深度

matlab - 白色像素簇提取

matlab - rsync:如何不应用通配符递归排除

image-processing - 颜色配置文件在图形程序中的作用

python - OpenCV Python : cv2. findContours - ValueError:解包的值太多

javascript - 对象/数组比较算法以确定共性/相似性

algorithm - 贪心算法的使用例子?