【发布时间】:2019-04-11 06:16:37
【问题描述】:
我必须根据像素值设置阈值以删除文件夹中的一些图像,并且我需要知道像素值的标准偏差。因此,我需要总结所有平均像素值。
以下是我尝试过的
以下代码演示了 np.mean() 的输出是什么样子的
import os,glob
from PIL import Image
from skimage import io
import numpy as np
from statistics import stdev
path = "/Users/Xin/Desktop/SVM-Image-Classification-master/test"
# Delete images with the low pixel value
for filename in os.listdir(path):
images = Image.open(os.path.join(path,filename))
print(np.mean(images))
#if np.mean(images) < 20:
#os.remove(os.path.join(path, filename))
#print(len(os.listdir(path)))
输出如下,数值在0~255之间,数值越小,图像越黑。
12.685516357421875
14.462142944335938
12.24658203125
9.507644653320312
18.701019287109375
10.004150390625
18.128433227539062
12.625930786132812
以下代码是我试过的
path = "/Users/Xin/Desktop/SVM-Image-Classification-master/test"
# Delete images with the low pixel value
for filename in os.listdir(path):
images = Image.open(os.path.join(path,filename))
L = list[round(np.mean(images),2)]
totalvalue = sum(L)
print(totalvalue)
#if np.mean(images) < 20:
#os.remove(os.path.join(path, filename))
#print(len(os.listdir(path)))
错误提示如下
TypeError: list indices must be integers or slices, not numpy.float64
谁能帮帮我? 非常感谢!
【问题讨论】:
-
是 list() 不是 list[]
-
list[round(np.mean(images),2)]告诉 python 给我列表list的round(np.mean(images),2)th 元素。这没有意义,因为它是一个浮动
标签: python numpy scikit-image