Matlab的:沿阵列的边界计数非零数的高效的方式 [英] Matlab: Efficient way of counting non-zero numbers along the boundary of an array

查看:191
本文介绍了Matlab的:沿阵列的边界计数非零数的高效的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组,其图像看起来如下图所示。阵列重新颗粒present数目在每个像素/格中的值。我想计算沿周边/边界非零颗粒的分布(的周边/边界是指最远点距离中心分布的) 其中非零颗粒存在 。从该输出,我想获得:

I have an array whose image looks as shown below. The values in the array represent number of particles at each pixel/grid. I want to calculate distribution of non-zero particles along the periphery/boundary (periphery/boundary refers to the distribution of farthest points from center) where non-zero particles exist. As an output from this, I would like to obtain:

1)#沿周/边界非零颗粒,以及

1) # of non-zero particles along the periphery/boundary, and

2)的像素#/网格,其中这些粒子驻留

2) # of pixels/grids where those particles reside

这样做的任何快速/有效的方式?

Any quick/efficient way of doing this?

修改1:快照描述一个边界为例
边界线跟踪非零颗粒。

EDIT 1: Snapshot Describing the Example of a Boundary The boundary line traces the non-zero particles.

推荐答案

与粒子计数的矩阵 M 启动,这将让你在<$ C $口罩C>兆的边界,因为它已被问题定义

Starting with a matrix M of particle counts, this will get you a mask in Mb of the boundary as it has been defined by the question,

% define particle count matrix and find non-zero locations
M = randi(5,10,10)-1
[nr,nc] = size(M);
[pRows,pCols] = find(M);

% identify locations that compose the "boundary" line
boundCoords = [accumarray(pCols,pRows',[nc 1],@min)', ...
               accumarray(pCols,pRows',[nc 1],@max)', ...
               1:nr 1:nr; ...
               1:nc 1:nc, ...
               accumarray(pRows,pCols',[nr 1],@min)', ...
               accumarray(pRows,pCols',[nr 1],@max)'];
boundCoords = unique(boundCoords','rows');
boundCoords(any(boundCoords==0,2),:)=[]; %' remove possible (unlikely) zeros

% create a mask representation of the boundary line
Mb = false(size(M));
Mb(sub2ind(size(Mb),boundCoords(:,1),boundCoords(:,2))) = true

这就是我理解你希望你的边界面具的样子。构成该边界象素的数目是

That is what I understand you want your boundary mask to look like. The number of pixels that make up the boundary is

numBorderPix = sum(Mb(:))

颗粒对这些边界点的数量是那么

The number of particles on those border points is then

numBorderParticles = sum(M(Mb))

注:此解决方案将确保的在边界线上每个点都有一个非零的粒子计数

NOTE: This solution will ensure that each point on the boundary line has a non-zero particle count.

这篇关于Matlab的:沿阵列的边界计数非零数的高效的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆