将中心像素值复制到块中的多数值 [英] Copy the center pixel value to the majority value in the block

查看:72
本文介绍了将中心像素值复制到块中的多数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像像素预测数组,其大小为9085x10852.我想在每个像素周围得到一个10x10的块.如果中心像素值与块中的多数像素值不同,则将中央像素值替换为多数值.谁能帮助我

I have a image pixel prediction array that is of size 9085x10852. I want to get a 10x10 block around each pixel. if the center pixel value is different from the majority pixel values in the block, then replace the center pixel value with the majority value. Can anyone help me please

推荐答案

我今天在挖掘scikit-image,寻找其他东西,如果您深入研究scikit-image.filters,然后再深入研究rank,您就会来跨modal()!请参见文档此处.

I was digging around in scikit-image looking for something else today and if you dig down into scikit-image.filters and then even further into rank, you come across modal()! See documentation here.

我使用了与@Tonechas相同的随机种子来产生可比较的结果:

I used the same random seed as @Tonechas to generate comparable results:

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, 0, 0, 0, 2, 4, 5],
       [1, 1, 0, 0, 0, 2, 5, 2],
       [1, 1, 0, 5, 5, 5, 5, 5],
       [1, 1, 1, 5, 5, 5, 4, 5],
       [1, 1, 1, 1, 5, 5, 4, 5],
       [1, 1, 5, 5, 5, 5, 4, 4]], dtype=uint8)

关键字:Python,numpy,scikit,skimage,图像处理,过程图像,中值,众数,众数,模态,结构元素,形态,过滤器,过滤器,等级.

Keywords: Python, numpy, scikit, skimage, image processing, process images, median, mode, modal, structuring element, morphology, filter, filters, rank.

这篇关于将中心像素值复制到块中的多数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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