MATLAB圆直径上提取滑动窗口和像素值直径、像素、窗口、MATLAB

2023-09-11 06:05:35 作者:倚楼醉听雨

我想实现一个算法,需要一个圆形的滑动窗口,即经过图像的所有像素,并为每个窗口,我需要提取躺在直径的圆的不同角度只能像素。

I'm trying to implement an algorithm that needs a circular sliding window, that goes through all the pixels of the image, and for each window I need to extract only pixels that lay on diameters at different angles of the circle.

我试图解释与使用上图中的更好。试想一下,这是一个圆形的滑动窗口的结果,我想只有躺在红线(直径倾斜的PI / 8)的像素值。

I try to explain better with the use of the image above. Imagine that this is the result of a circular sliding window, I want to get only the pixel values that lay on the red line (diameter tilted of pi/8).

到目前为止,我写了这些线路的code:

So far, I wrote these lines of code:

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;

但在这里,我不知道如何继续获取像素躺在直径。直径可倾斜任意角度的。任何帮助是极大AP preciated!

But from here, I don't know how to continue for getting pixels that lay on diameter. The diameter can be tilted of any angle. Any help is greatly appreciated!

推荐答案

这就是我想要做的:

首先创建蒙(你可以把这个变成一个功能,如果你想),并获得相关的像素指标为角度的功能:

First create the mask (you can put this into a function if you want), and get the relevant pixels indices as function of angle:

%% 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 use a cell array because there can be different number of indices per angle.

然后读取图片

I= imread('https://m.xsw88.com/allimgs/daicuo/20230911/3061.png'); 

重新排列图像块成列

Rearrange image blocks into columns

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

你想要的仅仅是:

what you want is just:

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

在C中重新$ P $每个电池单元psents这是一个直径长度 2 * O + 1 以一定的角度 THETA像素这是每定义的,用于图像中的每个像素。 因此, 13 C {1} 会给你所有的像素 THETA = 0 Ç {2} THETA = 15 等等...

each cell element in C represents the pixels that were on a diameter of length 2*o+1 at an angle theta that was per-defined, for each pixel in the image. So C{1} will give you all the pixels for theta=0, and C{2} for theta=15 etc...