Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nonlinear Filter for image processing - looking for minimum inside a mask

I have an idea about a filter for images but I do not know how I can realize this without using a double-for-loop in MATLAB.

I have an image, and I want to use a linear filter mask on it, let's say:

[1,1,1,1,1]

This filter mask is moving over the image, pixel by pixel. For each neighbourhood, the pixel I is set to the minimum of the surrounding neighbourhood.

Here is an example:

[ … image data      …]
[ …                 …]
[ …                 …]
[ … 23 68 155 20 53 …]
[ …                 …]

For my example, I want to filter the centering pixel with the value 155. The result would be:

[ … image data      …]
[ …                 …]
[ …                 …]
[ … 23 68 20  20 53 …]
[ …                 …]

The pixel 155 gets replaced with the minimum value in his neighbourhood.

I can do this with a double-for-loop, but it is really slow, too slow to use it for my application.

Would be happy for a good idea how to increase the speed! Thank you

like image 608
beinando Avatar asked Aug 17 '26 13:08

beinando


1 Answers

Your filter idea is called erosion. It is implemented in the Image Processing Toolbox in the function imerode. In your case, you'd apply:

result = imerode(image_data, [1,1,1,1,1]);

The neighborhood can have any shape. Set elements to 0 to exclude them from the neighborhood. For example, for a roundish neighborhood you can use

[0,1,1,1,0
 1,1,1,1,1
 1,1,1,1,1
 1,1,1,1,1
 0,1,1,1,0]
like image 198
Cris Luengo Avatar answered Aug 20 '26 03:08

Cris Luengo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!