图像中的邻域半径 [英] neighborhood radius in an image

查看:376
本文介绍了图像中的邻域半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张图片(200x200),想要找到具有预定义半径的特定点的邻域位置。例如,半径为5时,我在一个点周围有25个点。 MATLAB可以做到吗?问题是关于图像的边缘,它并不总是25点,程序应该只找到该半径范围内的点。这些点可以从1(角落)到25(图像中心)变化

I have an image (200x200) and want to find the neighborhood locations in a specific point with a predefined radius. For example, with the radius of 5, I have 25 points around a point. Does MATLAB can do it? The problem is about the edge of image which it does not always 25 points and the program should just find the points that are within that radius. These points can be varied from 1 (corner) to 25 (center of image)

推荐答案

这是一个例子:

%# sample grayscale image
img = imread('cameraman.tif');
[imgH,imgW,~] = size(img);

%# circle params
t = linspace(0, 2*pi, 50);   %# approximate circle with 50 points
r = 80;                      %# radius
c = [100 130];               %# center

%# get circular mask
BW = poly2mask(r*cos(t)+c(1), r*sin(t)+c(2), imgH, imgW);

%# show cropped image
imshow( immultiply(img,BW) )
axis on

这将处理边缘情况就好了。使用POLY2MASK的优点是它以亚像素精度计算掩模(请阅读函数文档中的算法部分),前提是您使用足够的点来近似圆。

This will handle edges cases just fine. The advantage of using POLY2MASK is that it computes the mask with a sub-pixel accuracy (read the algorithm section in the function documentation), provided you are using enough points to approximate the circle.

这篇关于图像中的邻域半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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