热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

从python中的圆圈中获取数据-Takedatafromacircleinpython

Iamlookingintohowtheintensityofaringchangesdependingonangle.Hereisanexampleofani

I am looking into how the intensity of a ring changes depending on angle. Here is an example of an image:

我正在研究环的强度如何根据角度而变化。以下是图片示例:

enter image description here

What I would like to do is take a circle of values from within the center of that doughnut and plot them vs angle. What I'm currently doing is using scipy.ndimage.interpolation.rotate and taking slices radially through the ring, and extracting the maximum of the two peaks and plotting those vs angle.

我想做的是从该甜甜圈的中心取一圈值并绘制它们与角度的关系。我目前正在做的是使用scipy.ndimage.interpolation.rotate并通过环径向切片,并提取两个峰的最大值并绘制那些与角度的关系。

    crop = np.ones((width,width)) #this is my image
    slices = np.arange(0,width,1)
    stack = np.zeros((2*width,len(slices)))
    angles = np.linspace(0,2*np.pi,len(crop2))

    for j in range(len(slices2)): # take slices
           stack[:,j] = rotate(crop,slices[j],reshape=False)[:,width]

However I don't think this is doing what I'm actually looking for. I'm mostly struggling with how to extract the data I want. I have also tried applying a mask which looks like this;

但是我不认为这是我正在寻找的。我主要是如何提取我想要的数据。我也试过应用一个看起来像这样的面具;

enter image description here

to the image, but then I don't know how to get the values within that mask in the correct order (ie. in order of increasing angle 0 - 2pi)

到图像,但后来我不知道如何以正确的顺序获取该掩码内的值(即按照增加角度0 - 2pi的顺序)

Any other ideas would be of great help!

任何其他想法都会有很大的帮助!

1 个解决方案

#1


3  

I made a different input image to help verifying correctness:

我制作了一个不同的输入图像来帮助验证正确性:

import numpy as np
import scipy as sp
import scipy.interpolate
import matplotlib.pyplot as plt

# Mock up an image.
W = 100
x = np.arange(W)
y = np.arange(W)
xx,yy = np.meshgrid(x,y)

image = xx//5*5 + yy//5*5
image = image / np.max(image)  # scale into [0,1]

plt.imshow(image, interpolation='nearest', cmap='gray')
plt.show()

Alternate input image

To sample values from circular paths in the image, we first build an interpolator because we want to access arbitrary locations. We also vectorize it to be faster.
Then, we generate the coordinates of N points on the circle's circumference using the parametric definition of the circle x(t) = sin(t), y(t) = cos(t).
N should be at least twice the circumference (Nyquist–Shannon sampling theorem).

要从图像中的圆形路径中采样值,我们首先构建插值器,因为我们想要访问任意位置。我们还将它矢量化为更快。然后,我们使用圆x(t)= sin(t),y(t)= cos(t)的参数定义在圆周上生成N个点的坐标。 N应该至少是圆周的两倍(奈奎斯特 - 香农采样定理)。

interp = sp.interpolate.interp2d(x, y, image)
vinterp = np.vectorize(interp)

for r in (15, 30, 45):    # radii for circles around image's center
    xcenter = len(x)/2
    ycenter = len(y)/2
    arclen = 2*np.pi*r
    angle = np.linspace(0, 2*np.pi, arclen*2, endpoint=False)
    value = vinterp(xcenter + r*np.sin(angle),
                    ycenter + r*np.cos(angle))
    plt.plot(angle, value, label='r={}'.format(r))

plt.legend()
plt.show()

Circles sampled from center.


推荐阅读
author-avatar
fover黄瓜小妞1
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有