简体   繁体   English

在python中从图像中提取任意矩形补丁

[英]Extract arbitrary rectangular patches from image in python

Is there a way to extract a rectangle of my choice from an image, maybe using numpy arrays? 有没有办法从图像中提取我选择的矩形,也许使用numpy数组? Most implementations available seem to be for regular sliding window solutions, but those always include steps, or rectangles of the same aspect ratio, or something like that. 可用的大多数实现似乎都是针对常规的滑动窗口解决方案的,但这些实现总是包含台阶,相同纵横比的矩形或类似的东西。

Is it possible to provide the beginning x and y coordinates and the width and height (or ending x and y coordinates), and extract exactly that rectangle? 是否可以提供开始的x和y坐标以及宽度和高度(或结束的x和y坐标),然后精确提取该矩形? Can this be done using numpy arrays alone? 可以单独使用numpy数组吗? Or is there another way to do this? 还是有其他方法可以做到这一点?

The best way to do this would be slicing ie 最好的方法是切片

rect = np.copy(img[y1:y1+height,x1:x1+width])

where (x1, y1) is the upper left corner of your rectangle. 其中(x1,y1)是矩形的左上角。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM