将图像划分为块 [英] Divide image to blocks

查看:83
本文介绍了将图像划分为块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处输入图像描述您好,我想将图像(200x200)分成100个相等大小的块,然后我想找到每个块的平均值.关于如何将图像划分为10x10块(10行10列),我已经进行了很多研究,但是无法理解如何实现的概念.谁能帮忙.

enter image description hereHi I want to divide an image (200x200) into 100 blocks of equal sizes and then I want to find average of each block. I have looked around a lot on how to divide the image into 10x10 blocks(10 rows 10 columns) but not able to grasp the concept on how to do so. Can anyone help.

推荐答案

我假设您有numpy,因为您将其作为标签.如果没有枕头"模块,请运行

I'll assume you have numpy, since you have it as a tag. If you don't have the Pillow module, run

pip install Pillow

抓住那个.以下代码会将图像分割成400个10x10的块.

and grab that. The following code will split the image into a 400 blocks of 10x10.

import numpy as np
from PIL import Image

image = Image.open("your_file.jpg", "r")
arr = np.asarray(image)
arr = np.split(arr, 20)
arr = np.array([np.split(x, 20, 1) for x in arr])

然后,要获取第i-j个块,请通过以下方法将其索引到其中:

Then, to grab the i-j'th block, index into it via:

arr[i][j]

这篇关于将图像划分为块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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