将图像分成具有相同像素数据的多个图像 [英] Dividing a image into multiple images of equal pixel data

查看:125
本文介绍了将图像分成具有相同像素数据的多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个灰度图像 im

如果总计是所有像素值的总和,如何将 im 拆分为5个具有以下属性的图像:

If total is the sum of all pixels' values, how do I split im into 5 images with the following properties:


  • 所有像素值的总和是总计的1/5

  • 缺少要求...

  • ...

我正在使用python。但是,任何其他语言的建议也将受到赞赏。

I am using python. But suggestion in any other language will also be appreciated.

我使用以下代码计算像素数据。

I have used the following code for counting pixel data.

from PIL import Image

im = Image.open('capture.jpg')
im_grey = im.convert('LA') # convert to grayscale
width,height = im.size

total=0
for i in range(0,width):
    for j in range(0,height):
        total += im_grey.getpixel((i,j))[0]

print "The sum of all pixels' values in im is :" 
print total
print "1/5 of that sum is :" 
print total/5

任何建议都应该受到赞赏。

any suggestions should be appreciated.

推荐答案

你原来的问题很难。但是,看看你发表的评论,我认为这是一个简单的问题。您可以从上到下扫描图像,并对像素求和。当总和达到sum_all_pixels / 5时,您就找到了第一个区域。将总和重置为零,然后继续扫描第二个区域。我希望你明白我的意思。

Your original problem is a hard one. But, looking at the comments you made, I think it is a simple problem. You can scan the image from top to bottom, and sum the pixels. When the sum reaches the sum_all_pixels/5, then you have found the first area. Reset the sum to zero, and continue scanning for the second area. I hope you understand what I mean.

这篇关于将图像分成具有相同像素数据的多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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