Median filter with input pixels within ROI

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Median filter with input pixels within ROI

Michel Teussink
Hi all,

I am looking for a means to replace pixel intensities with that of the median intensity of all pixels within an ROI. As I understood, a median filter (with unlimited radius) will also use pixels outside of the ROI as input, which I cannot use. Of course, I could measure the median within the ROI and use Math-->Set (intensity=median), but I don't know how to do this in a macro.

Any help with this is greatly appreciated!

Best regards,
Michel




Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629.
The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629.


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Median filter with input pixels within ROI

Michael Schmid
Hi Michel,

it is not so trivial, indeed.
Only if you have only uncalibrated images, it is relatively easy:

run("Set Measurements...", "median");
List.setMeasurements();
median=List.getValue("Median");
run("Set...", "value=&median");


Process>Math>Set needs an uncalibrated value, so for calibrated images one has to use the getRawStatistics macro function, which has a few peculiarities. This is what I came up with:

getRawStatistics(nPixels, mean, min, max, std, histogram);
if (bitDepth() == 32) {
 binWidth = (max-min)/histogram.length;
 bin0center = min+binWidth/2;
} else {
 binWidth = 1;
 bin0center = 0;
}
sum=0;
for (i=0; i<histogram.length; i++) {
 sum+=histogram[i];
 if (sum>=nPixels/2) {
   value=bin0center+i*binWidth;
   run("Set...", "value=&value");
   exit;
 }
}

For float images, accuracy of my second macro is not perfect due to rounding (if I did the rounding correctly, it should be good within 1/512 of the range between max and min pixel value).


Michael
________________________________________________________________
On Jan 2, 2013, at 17:58, Michel Teussink wrote:

> Hi all,
>
> I am looking for a means to replace pixel intensities with that of the median intensity of all pixels within an ROI. As I understood, a median filter (with unlimited radius) will also use pixels outside of the ROI as input, which I cannot use. Of course, I could measure the median within the ROI and use Math-->Set (intensity=median), but I don't know how to do this in a macro.
>
> Any help with this is greatly appreciated!
>
> Best regards,
> Michel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html