![]() |
测试周围的非零元素
这是以下内容的以下部分:
2) [B]附加问题:[/B] 获得非零邻居的平均值后,我还想测试邻居元素是否等于,小于或大于非零平均值。如果大于或等于“ 1”,否则为“ 0”。 注意:如果邻居的半径在两个或多个中心的范围内,则以最小的中心平均值进行测试。 0 12 9 4 **9** 15 11 19 0 中间的'9'位于12、15和19个中心的半径内,因此取最小值的最小值的平均值为[9.000,9.000,8.000] = 8.000 例如,当半径= 1 m或1个元素远时。 new_x = 0 0 0 0 0 0 0 **9.0000** 9.0000 0 0 4.0000 9.0000 **9.0000** 0 0 **8.3333** **8.0000** 0 0 0 2.0000 4.0000 8.0000 0 0 4.0000 5.0000 8.0000 0 0 0 0 0 0 Test_x = 0 0 0 0 0 0 0 **9.0000** 1 0 0 0 1 **9.0000** 0 0 **8.3333** **8.0000** 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ================================================== ============================== 1)说如果我有一个矩阵,如下所示, X = 0 0 0 0 0 0 0 12 9 0 0 4 9 15 0 0 11 19 0 0 0 2 4 8 0 0 4 5 8 0 0 0 0 0 0 我想找到大于10的周围非零元素的平均值。其余元素仍保持不变,即元素 0),1)]*[x(5) < 10; x(5) >= 10]; new_x = nlfilter(X,[3 3],fcn); [B]编辑:[/B]如果您无权访问“ [URL="http://www.mathworks.com/access/helpdesk/help/toolbox/images/"]图像处理工具箱”[/URL] ,则也可以使用内置的[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/conv2.html"]CONV2[/URL]函数执行此操作,如下所示: kernel = [0 1 0; ... %# Convolution kernel 1 0 1; ... 0 1 0]; sumX = conv2(X,kernel,'same'); %# Compute the sum of neighbors %# for each pixel nX = conv2(double(X > 0),kernel,'same'); %# Compute the number of non-zero %# neighbors for each pixel index = (X >= 10); %# Find logical index of pixels >= 10 new_x = X; %# Initialize new_x new_x(index) = sumX(index)./max(nX(index),1); %# Replace the pixels in index %# with the average of their %# non-zero neighbors 以上处理您的半径= 1种情况。要解决您的radius = 2的情况,您只需要将卷积内核更改为以下内容,然后重新运行上面的代码即可: kernel = [0 0 1 0 0; ... 0 1 1 1 0; ... 1 1 0 1 1; ... 0 1 1 1 0; ... 0 0 1 0 0]; [url=https://stackoverflow.com/questions/3402081]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:15。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.