Problems with medianFilter in EBImage 4.0.0
1
0
Entering edit mode
Kent Johnson ▴ 10
@kent-johnson-5796
Last seen 9.6 years ago
Hi, I am using medianFilter from EBImage 4.0.0 in R 2.15.2 on Windows 7 and I have found a few problems when median filtering a grayscale image. The first problem is simple to fix - medianFilter() returns its argument unchanged because the line z = as.Image(.Call("medianFilter", x, size, colorMode(x) + 1, cacheSize)) assigns to z which is then not used; changing this to x = as.Image(.Call("medianFilter", x, size, colorMode(x) + 1, cacheSize)) should fix that. The other problem I don't have a fix for - a median value of 0 is returned instead as 1. Here is some code that reproduces the problem (using medianFilter internals to work around the first problem): library(EBImage) d=matrix(runif(10000, 0.1, 0.9), 100) d[50:60, 50:60]=0 # Make a region of constant 0 display(d) # From EBImage::medianFilter x = d*2^16-1 y = as.Image(.Call("medianFilter", x, 3, colorMode(x) + 1, 512)) z = (y-1)/2^16 display(z) # The black region has turned white Thanks, Kent PS I emailed the EMImage maintainer (paug@gene.com) but received no reply. [[alternative HTML version deleted]]
EBImage EBImage • 1.0k views
ADD COMMENT
0
Entering edit mode
Andrzej Oleś ▴ 750
@andrzej-oles-5540
Last seen 3.4 years ago
Heidelberg, Germany
Hi Kent, many thanks for your feedback on EBImage! On Tue, Feb 26, 2013 at 8:06 PM, Kent Johnson <kent3737 at="" gmail.com=""> wrote: > The first problem is simple to fix - medianFilter() returns its argument > unchanged because the line > > z = as.Image(.Call("medianFilter", x, size, colorMode(x) + > 1, cacheSize)) > > assigns to z which is then not used; changing this to > > x = as.Image(.Call("medianFilter", x, size, colorMode(x) + > 1, cacheSize)) > > should fix that. Thanks for pointing this out! This typo has been already corrected before in the devel version of EBImage (http://www.bioconductor.org/packages/devel/bioc/html/EBImage.html). Please update to version >= 4.1.1 to get rid of this bug. > The other problem I don't have a fix for - a median value of 0 is returned > instead as 1. Here is some code that reproduces the problem (using > medianFilter internals to work around the first problem): > > library(EBImage) > > d=matrix(runif(10000, 0.1, 0.9), 100) > d[50:60, 50:60]=0 # Make a region of constant 0 > display(d) > > # From EBImage::medianFilter > x = d*2^16-1 > y = as.Image(.Call("medianFilter", x, 3, colorMode(x) + 1, 512)) > z = (y-1)/2^16 > display(z) # The black region has turned white Thank you for reporting this. The conversions between the [0,1] range and the integer range performed by the 'medianFilter' function are actually wrong. Instead, they should read: x*(2^16-1) # conversion to integer range x/(2^16-1) # conversion back to [0,1] range I've fixed this in the newest devel version. Calling now 'display(medianFilter(d,3))' should give you the expected result. The updated EBImage 4.1.5 should be available from the BioC website within 24h. Best, Andrzej
ADD COMMENT

Login before adding your answer.

Traffic: 996 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6