python – 将中心像素值复制到块中的多数值
发布时间:2020-12-20 12:14:34 所属栏目:Python 来源:网络整理
导读:我有一个图像像素预测数组,大小为9085×10852.我想在每个像素周围得到一个10×10的块.如果中心像素值与块中的多数像素值不同,则将中心像素值替换为多数值.任何人都可以帮助我 解决方法 我正在挖掘scikit-image今天寻找其他东西,如果你深入了解scikit-image.f
我有一个图像像素预测数组,大小为9085×10852.我想在每个像素周围得到一个10×10的块.如果中心像素值与块中的多数像素值不同,则将中心像素值替换为多数值.任何人都可以帮助我
解决方法
我正在挖掘scikit-image今天寻找其他东西,如果你深入了解scikit-image.filters然后进一步排名,你会遇到modal()!参见文档
here.
我使用与@Tonechas相同的随机种子来生成可比较的结果: import numpy as np from skimage.morphology import rectangle # for Structuring Elements (e.g. disk,rectangle) from skimage.filters.rank import modal # the puppy we want # Same seed for directly comparable results np.random.seed(329) # Sample array/image arr = np.random.randint(low=0,high=10,size=(6,8),dtype=np.uint8) # Run the filter with a 5x5 rectangular Structuring Element result = modal(arr,rectangle(5,5)) print(result) array([[9,2,4,5],[1,1,5,2],4]],dtype=uint8) 关键词:Python,numpy,scikit,skimage,图像处理,过程图像,中位数,模式,模态,结构元素,形态,过滤器,等级. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |