从表示图像的数组中提取环形/扇形区域 [英] Extracting Ring/Sector area from array representing an image

查看:294
本文介绍了从表示图像的数组中提取环形/扇形区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从MATLAB中图像的阵列表示中提取特征. 要素的形状为圆形(环形)和扇形.如下图所示.我花了很多时间寻找执行此操作的内置函数.我设法使用一个看起来很丑陋的循环来进行环提取,但不知道从扇区部分的哪里开始.如何在MATLAB中实现甚至更好的内置函数的任何想法都将非常有帮助.

I am trying to extract features from an array representation of an image in MATLAB. The features have a shape of a circle (ring) and a sector. This is shown in the image below. I have spent quite some time looking for a built-in function which does this. I have managed to do the ring extraction using an ugly looking loop but no idea where to start on the sector part. Any ideas how to implement this or even better a built-in function in MATLAB would be very helpful.

推荐答案

这很简单,不需要for循环,例如,如果您的图像是im:

That's pretty easy, with no for loops needed, see for example in case your image is im:

[x y]=meshgrid(1:size(im,1));

f =@(x0,y0,r_max,r_min,theta1,theta2) ...
                 (x-x0).^2+(y-y0).^2<=r_max^2 & ...
                 (x-x0).^2+(y-y0).^2>=r_min^2 & ...
                  atan2(y-y0,x-x0)>=theta1 & ...
                  atan2(y-y0,x-x0)<=theta2;

f是一个单行匿名函数,它接受所有必需的参数并提供所需扇区的掩码.对于铃声,您可以将theta设置为-pi到pi,或仅将atan部分从f中删除.例如

f is a one liner anonymous function that accepts all needed parameters and gives a mask of the sector needed. For a ring you can set theta to be -pi to pi, or just delete the atan part from f. For example

r_max=40;
r_min=10;
x0=round(size(im,1)/2); %image center
y0=round(size(im,1)/2); %image center
theta1=deg2rad(10);
theta2=deg2rad(70);

imagesc(f(x0,y0,r_max,r_min,theta1,theta2))
set(gca,'YDir','normal')
axis square

这篇关于从表示图像的数组中提取环形/扇形区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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