Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使用scikit image在python中的图像上裁剪圆的扇区_Python 3.x_Scikit Image - Fatal编程技术网

Python 3.x 如何使用scikit image在python中的图像上裁剪圆的扇区

Python 3.x 如何使用scikit image在python中的图像上裁剪圆的扇区,python-3.x,scikit-image,Python 3.x,Scikit Image,我正在使用Python3.5的scikit映像。我想裁剪一个圆的扇区,并将其另存为一个不同的图像 我只有圆心(cx,cy),半径r,圆周长上的两个坐标(x1,y1),(x2,y2),以及扇形的两条直线的方程 如果它是整个圆,我可以使用圆方程并将图像的其余部分变黑,但由于它是扇形,我面临一个问题。使用skimage.draw中的绘图功能,您可以构造一个圆和一个多边形,并将两者相交以获得一个切片: 你能把你现在的代码包括进来吗?我没有代码,但是你能给我一个大概的想法让我写下来吗。谢谢你“mask=m

我正在使用Python3.5的scikit映像。我想裁剪一个圆的扇区,并将其另存为一个不同的图像

我只有圆心(cx,cy),半径r,圆周长上的两个坐标(x1,y1),(x2,y2),以及扇形的两条直线的方程


如果它是整个圆,我可以使用圆方程并将图像的其余部分变黑,但由于它是扇形,我面临一个问题。

使用skimage.draw中的绘图功能,您可以构造一个圆和一个多边形,并将两者相交以获得一个切片:


你能把你现在的代码包括进来吗?我没有代码,但是你能给我一个大概的想法让我写下来吗。谢谢你“mask=mask\u circle&mask\u poly”只给出了一个三角形,而不是扇区。你是什么意思?这是多边形和圆的交点,这是一个扇形。我想我错在哪里了。现在我有了扇区,但如何将掩码应用于uint8I类型的图像我也屏蔽了图像,但不确定如何将图像的未屏蔽部分保存到单独的文件中。image\u mask=mask\u circle&mask\u poly mk=numpy.logical\u not(image\u mask)image[mk]=0 plt.imshow(image,cmap='gray')plt.show()这也给出了变黑的部分。是否只保存包围遮罩区域的矩形?
import numpy as np
from skimage import data, draw
import matplotlib.pyplot as plt

# Random image
image = np.random.random((200, 200))

# --- coordinate specification

r0, c0 = 100, 70  # circle center (row, column)
R = 100  # circle radius

theta0 = np.deg2rad(20)  # angle #1 for arc
theta1 = np.deg2rad(40)  # angle #2 for arc

# Above, I provide two angles, but you can also just give the two
# coordinates below directly

r1, c1 = r0 - 1.5 * R * np.sin(theta0), c0 + 1.5 * R * np.cos(theta0)  # arc coord #1
r2, c2 = r0 - 1.5 * R * np.sin(theta1), c0 + 1.5 * R * np.cos(theta1)  # arc coord #2

# --- mask calculation

mask_circle = np.zeros(image.shape[:2], dtype=bool)
mask_poly = np.zeros(image.shape[:2], dtype=bool)

rr, cc = draw.circle(r0, c0, R, shape=mask_circle.shape)
mask_circle[rr, cc] = 1

rr, cc = draw.polygon([r0, r1, r2, r0],
                      [c0, c1, c2, c0], shape=mask_poly.shape)
mask_poly[rr, cc] = 1

mask = mask_circle & mask_poly

plt.imshow(mask, cmap='gray')
plt.show()