Ala*_*isy 0 matlab image image-processing
如何计算附加图像中每个笔划的粗细?

我对图像中的所有神经进行了分割,并在图像中标记了每个对象.我想知道如何计算每个神经的厚度?另外,如果任何神经出现充气,我怎样才能突出神经的特定部位呢?
我们非常感谢您在这方面的帮助.
我想指出以下帖子:测量图像中痕迹的平均厚度.基本上,图像中存在单个笔划,目标是确定该笔划的平均厚度.我们只需针对图像中存在的每个笔划重新应用此算法.
基本算法如下(并且非常巧妙):
对于图像中的笔划,将距离变换应用于图像变换的图像,以便所有背景像素变为白色,对象像素变为黑色.因此,我们将距离变换应用于图像的逆.
距离变换找到图像中的点与最接近的非零像素之间的距离.这样,通过将距离变换应用于逆,对于每个笔划点,这将确定从该特定点到笔划上的最近边界点的距离.我们在这方面需要距离变换的原因将在下一步中明确.
在距离变换中共享最大距离的笔划上的点定义笔划的中间.你可以认为这是在中途的行程之间的中点.由于浮点运算,将所有这些距离值收集在该最大距离的某个容差范围内.
找出所有这些距离的平均值或中位数,这决定了笔画一半的宽度....所以如果你想要全厚度,只需将结果乘以2即可.
在继续之前,我将假设您可以访问图像处理工具箱,因为距离变换是在bwdist作为工具箱一部分的函数中实现的.如果你没有这个工具箱,那么很遗憾我写的东西将不起作用.这是该算法需要的唯一依赖(比使用其他imread和im2bw当然).
由于某种原因,当您以RGB格式上传图像时,我不得不将图像转换为二进制,因此我将其转换为单通道二进制图像.因此,您的代码可能如下所示:
%// Read the image from StackOverflow and convert to binary
im = im2bw(imread('http://i.stack.imgur.com/DggWW.jpg'));
%// Find all unique contours and assign them a unique ID. Also determine how many there are
[lbl,N] = bwlabel(im);
%// Initialize an array that determines the thickness of each stroke
thickness = zeros(N,1);
%// Tolerance to collect distances
tol = 1;
%// For each stroke...
for idx = 1 : N
%// Step #1
cntr = lbl == idx; %// Get a mask that segments out that stroke only
d = bwdist(~cntr); %// Find distance transform on inverse
%// Step #2
max_dist = max(d(:)); %// Get the maximum distance from stroke to edge
dists = d(abs(d - max_dist) <= tol); %// Collect those distances within a tolerance
%// Step #3
thickness(idx) = 2*mean(dists); %// Find the average width and multiply by 2 for full width
end
Run Code Online (Sandbox Code Playgroud)
thickness是一个元素数组,它告诉您图像中每个笔划的宽度或粗细.每个元素都i告诉你通过标签指定轮廓的厚度i从bwlabel结果.因此,对于每个元件i在thickness,此记录在划定的行程厚度:
cntr = lbl == i;
Run Code Online (Sandbox Code Playgroud)
使用您的图像,我得到以下结果:
thickness =
3.3555
3.2494
3.1545
3.1773
3.3282
3.2607
3.2710
3.2772
3.2948
3.1607
Run Code Online (Sandbox Code Playgroud)
至于确定神经是否发炎,您需要知道每个中风的真实厚度是多少,并确定是否有增加.我没有这样的信息,所以我将把它留给你作为练习.我们计算了每个笔划的厚度,从那里写出一些代码来检测增加并相应地采取行动.
作为额外的奖励,让我们创建一个新的输出图像,我们找到每个笔划的质心,将该笔划放在此输出图像中,并在笔划的质心处打印出其厚度.像这样的东西:
imshow(im); hold on;
for idx = 1 : N
[y,x]= find(lbl == idx);
cen = mean([x y]);
text(cen(1), cen(2), ['T = ' num2str(thickness(idx))], 'color', 'red');
end
Run Code Online (Sandbox Code Playgroud)
我们得到:
