以下python上的裁剪函数如何使用numpy裁剪图像?

2024-09-24 02:17:20 发布

您现在位置:Python中文网/ 问答频道 /正文

在下面的函数imcrop_tosquare。 假设我有一个形状的图像(8,4) 即8行4列。 如果是这样的话。我将得到额外的4岁。 然后extra%2 ==0条件得到满足。在

crop = img[2:-2,:]

2比2代表什么? 我想是从第二排到前一排。 1,2,3,4,5,6,7,8[这将在循环中]所以-1是1,-2是2。 如果把前两行结束,图像会不会损坏?? 我解释错了吗?有谁能指导我理解这一点吗。在

^{pr2}$

Tags: 函数图像cropimg代表条件形状指导
1条回答
网友
1楼 · 发布于 2024-09-24 02:17:20

根据documentation

Negative i and j are interpreted as n + i and n + j where n is the number of elements in the corresponding dimension.

所以如果数组中有8行,crop = img[2:-2,:]将意味着crop = img[2:6,:]

相关问题 更多 >