响应式网站设计多少钱,门户网站建设议题汇报材料,上海品划做网站,微信企业邮箱目录
python 统计相同像素值个数
最大值附近的值 python 统计相同像素值个数 import cv2
import numpy as np
import time
from collections import Counter# 读取图像
image cv2.imread(mask16.jpg)# 将图像转换为灰度图像
gray_image cv2.cvtColor(image, cv2.COLOR_BGR2…目录
python 统计相同像素值个数
最大值附近的值 python 统计相同像素值个数
import cv2
import numpy as np
import time
from collections import Counter# 读取图像
image cv2.imread(mask16.jpg)# 将图像转换为灰度图像
gray_image cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)areagray_image.shape[0]*gray_image.shape[1]
print(shape,gray_image.shape)
# 将灰度图像展平为一维数组
pixels gray_image.flatten()starttime.time()
# 使用 Counter 统计每个像素值的出现次数
pixel_counts Counter(pixels)most_commons pixel_counts.most_common(10)print(time,time.time()-start)
count0
for most_common in most_commons:countmost_common[1]print(most_common,count,count/len(pixels))
print(count,count/len(pixels))
# 打印每个像素值及其出现次数
# for pixel_value, count in pixel_counts.items():
# print(fPixel value {pixel_value}: {count} times) 最大值附近的值
import cv2
import numpy as np
import time
from collections import Counter# 读取图像
image cv2.imread(mask16.jpg)# 将图像转换为灰度图像
gray_image cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)areagray_image.shape[0]*gray_image.shape[1]
print(shape,gray_image.shape)
# 将灰度图像展平为一维数组
pixels gray_image.flatten()starttime.time()
# 使用 Counter 统计每个像素值的出现次数
pixel_counts Counter(pixels)most_commons pixel_counts.most_common(10)print(time,time.time()-start)
count0
max_pixelint(most_commons[0][0])
for ii, most_common in enumerate(most_commons):if abs(max_pixel- int(most_common[0]))5:countmost_common[1]print(most_common,count,count/len(pixels))else:print(ffffff,most_common[0])
print(count,count/len(pixels))