PIL图像的平均值 [英] average of PIL images

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

问题描述



i有一组差异面(人物)的RGB图像为2 dim

numpyarray

...喜欢

threefaces = array([[xa1,xa2,xa3],

[xb1,xb2,xb3],

[xc1,xc2 ,xc3]])

其中xa1,xa2,xa3是元组,每个元组代表一个像素的rgb值

的第一张图片..


i需要创建平均人脸图像并显示它。问题是我需要计算(xa1 + xb1 + xc1)/ 3等等来计算
$ b $的大值b每个像素。我可以做这个计算。我需要将

r,g,b转换为每个像素的单个值吗?

像素的平均值将是浮点数不是吗?我怎样才能从

这个创建一个PIL图像?

任何帮助,指令非常感谢

eric

hi
i have a set of RGB images of diff faces (of people )as a 2 dim
numpyarray
...something like
threefaces=array([[xa1,xa2,xa3],
[xb1,xb2,xb3],
[xc1,xc2,xc3]])
where xa1,xa2,xa3 are tuples each representing rgb values of a pixel
of first image ..

i need to create the average face image and display it.problem is i
need to calculate (xa1+xb1+xc1)/3 etc to calculate avearge value of
each pixel.how can i do this calculation.do i need to convert the
r,g,b in to a single value for each pixel? the average value of a
pixel will be a float isn''t it? how can i create a PIL image from
this?
any help,directive greatly appreciated
eric

推荐答案

vaneric写道:
vaneric wrote:

hi

i有一组差异面的RGB图像(人们)作为2昏暗

numpyarray

..类似

threefaces = array([[xa1,xa2,xa3],

[xb1,xb2,xb3],

[xc1,xc2,xc3]]

其中xa1,xa2,xa3是每个代表的元组一个像素的rgb值

的第一张图片..


i需要创建平均脸部图像并显示它。问题是我

需要计算(xa1 + xb1 + xc1)/ 3等来计算每个像素的每个像素的价值。我可以做这个计算。
hi
i have a set of RGB images of diff faces (of people )as a 2 dim
numpyarray
..something like
threefaces=array([[xa1,xa2,xa3],
[xb1,xb2,xb3],
[xc1,xc2,xc3]])
where xa1,xa2,xa3 are tuples each representing rgb values of a pixel
of first image ..

i need to create the average face image and display it.problem is i
need to calculate (xa1+xb1+xc1)/3 etc to calculate avearge value of
each pixel.how can i do this calculation.



threefaces.mean(axis = 0)

threefaces.mean(axis=0)


我需要转换

r,g,b为每个像素的单个值?
do i need to convert the
r,g,b in to a single value for each pixel?



这取决于您尝试解决的问题。如果您的问题可以接受单色图像,那么最好将所有图像转换为单色来进行平均。至少是第一次切割。平均颜色

图像很棘手;你真的不应该在RGB色彩空间中这样做。你可以选择一些

的颜色空间;不同的问题需要

不同的颜色空间。

It depends on the problem that you are trying to solve. If monochrome images are
acceptable for your problem, then it is probably best to convert all your images
to monochrome to do the averaging. At least for a first cut. Averaging color
images is tricky; you really shouldn''t do it in the RGB colorspace. There are a
couple of colorspaces which you could choose; different problems require
different colorspaces.




像素的平均值将是浮动isn'是吗?
the average value of a
pixel will be a float isn''t it?



是。

Yes.


如何从

创建PIL图像这个?
how can i create a PIL image from
this?



#将浮点数据转换为字节。

avgface = avgface.astype(numpy.uint8)

#从numpy数据创建PIL图像。

img = Image.fromstring(''L'',(width,height),avgface.tostring())


-

Robert Kern


我开始相信整个世界都是一个谜,一个无害的由于我们疯狂地试图将它解释为一个潜在的真相而感到可怕,因为这很可怕。

- Umberto Eco

# Cast the floating point data to bytes.
avgface = avgface.astype(numpy.uint8)

# Create the PIL image from the numpy data.
img = Image.fromstring(''L'', (width, height), avgface.tostring())

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco


vaneric写道:
vaneric wrote:

hi

i有一个一组RGB图像的差异面(人)作为2昏暗

numpyarray

..类似

threefaces = array([[ xa1,xa2,xa3],

[xb1,xb2,xb3],

[xc1,xc2,xc3]])

其中xa1 ,xa2,xa3是元组,每个元组代表一个像素的rgb值

。第一张图片..


i需要创建平均脸部图像并显示它。问题是我需要计算
(xa1 + xb1 + xc1) / 3等计算

每个像素的平均值。我可以做这个计算。我需要将

r,g,b转换为单个值每个像素?

像素的平均值将是浮点数不是吗?我怎样才能从

这个创建一个PIL图像?

任何帮助,指令非常感谢

eric
hi
i have a set of RGB images of diff faces (of people )as a 2 dim
numpyarray
..something like
threefaces=array([[xa1,xa2,xa3],
[xb1,xb2,xb3],
[xc1,xc2,xc3]])
where xa1,xa2,xa3 are tuples each representing rgb values of a pixel
of first image ..

i need to create the average face image and display it.problem is i
need to calculate (xa1+xb1+xc1)/3 etc to calculate avearge value of
each pixel.how can i do this calculation.do i need to convert the
r,g,b in to a single value for each pixel? the average value of a
pixel will be a float isn''t it? how can i create a PIL image from
this?
any help,directive greatly appreciated
eric



看一下ImageChops.difference。我用它计算了一个

差值如下:


diff = ImageChops.difference(im1,im2)

totaldiff = sum(ImageStat.Stat(diff)._ getmedian())

也许至少这会指向正确的方向。


-Larry Bates

Take a look at ImageChops.difference. I''ve used it to calculate a
difference value as follows:

diff=ImageChops.difference(im1, im2)
totaldiff=sum(ImageStat.Stat(diff)._getmedian())

Maybe at least this will point you in the right direction.

-Larry Bates


2月18日,10:18 * am,vaneric< vaneric ... @ gmail.comwrote:
On Feb 18, 10:18*am, vaneric <vaneric...@gmail.comwrote:



i有一组差异人脸的RGB图像(人物)为2 dim

numpyarray

..类似

threefaces = array([[xa1,xa2,xa3],

* * * * [xb1,xb2,xb3],
* * * * [xc1,xc2,xc3]])

其中xa1,xa2,xa3是*元组,每个元组代表一个像素的rgb值

第一张图片..


i需要创建平均脸部图像并显示它。问题是我需要计算
(xa1 + xb1 + xc1)/ 3 *等计算每个像素的平均价值。我可以做这个计算ation.do我需要将

r,g,b转换成每个像素的单个值吗?

像素的平均值将是浮点数不是吗?我怎样才能从

这个创建一个PIL图像?

任何帮助,指令非常感谢

eric
hi
i have a set of RGB images of diff faces (of people )as a 2 dim
numpyarray
..something like
threefaces=array([[xa1,xa2,xa3],
* * * *[xb1,xb2,xb3],
* * * *[xc1,xc2,xc3]])
where xa1,xa2,xa3 are *tuples each representing rgb values of a pixel
of first image ..

i need to create the average face image and display it.problem is i
need to calculate (xa1+xb1+xc1)/3 *etc to calculate avearge value of
each pixel.how can i do this calculation.do i need to convert the
r,g,b in to a single value for each pixel? the average value of a
pixel will be a float isn''t it? how can i create a PIL image from
this?
any help,directive greatly appreciated
eric



导入数字


arr = Numeric.array([

[1,2,3],

[4,5,6],

[7,8,9],

[10,11,12]

] )


col1 = arr [0:,0]

print col1


sum = 0
count = 0
对于col1中的num,


sum + = num

count + = 1


avg =(总和* 1.0)/计数#convert一个浮点数到浮点数

结果

打印平均值

打印圆形(平均)

打印int(圆形(平均))

打印arr [0]


尺寸= len(arr [0])

for i in range(size):

col = arr [0:,i]

sum = 0

count = 0

for col in col:

sum + = num

count + = 1


result =(sum * 1.0)/ count

打印结果,

result = i nt(圆(结果))

打印结果


- 输出: -

[1 4 7 10]

5.5

$

6

[1 2 3]

5.5 6

6.5 7

7.5 8

import Numeric

arr = Numeric.array([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]
])

col1 = arr[0:,0]
print col1

sum = 0
count = 0
for num in col1:
sum += num
count += 1

avg = (sum * 1.0)/count #convert one term to a float to get float
result
print avg
print round(avg)
print int(round(avg))
print arr[0]

size = len(arr[0])
for i in range(size):
col = arr[0:, i]
sum = 0
count = 0

for num in col:
sum += num
count += 1

result = (sum * 1.0) /count
print result,
result = int(round(result))
print result

--output:--
[ 1 4 7 10]
5.5
6.0
6
[1 2 3]
5.5 6
6.5 7
7.5 8


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

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