简体   繁体   中英

Why does the scikit median filter produce a blank output image?

I am trying to de-noise the following picture using the median filter of Scikit Image .

在此处输入图像描述

This is a picture with a dimension of 250 X 100 pixels. The pixels are either black or white.

dtype=uint8
shape=(100,250)
max=255
min=0

This is the Python script

import os
from skimage import io
from skimage.filters.rank import median
from skimage.morphology import disk


def median_filter(inputfilename):
    folder_script=os.path.dirname(__file__)
    absolute_filename=os.path.join(folder_script,"./in/",inputfilename)

    original= io.imread(absolute_filename, as_gray=True)
    
    median_filtered=median(original, disk(50))  #5, 10, 20,100

    filename_result="median-filter-output.png"
    file_result=os.path.join(folder_script,"./out/",filename_result)
    io.imsave(file_result,median_filtered)

median_filter(inputfilename="NoisySine.png")

The resulting image is always blank (full white). I am sure I am doing something wrong - but not clear where.

Any suggestions?

Thank you,

Sau

Because your image is almost full white the median of such large disk is also white.

As extreme example, Imagine a disk that has 51% whites pixels and 49% black pixels -> the median will be white. In your case is looks like at least 95% white dominance.

BTW, it is as_grey and not as_gray (update: was like this but not anymore, see @Juan comment below)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM