Steve on Image Processing with MATLAB

Image processing concepts, algorithms, and MATLAB

Image region filling – an updated design

About a year ago, I wrote a blog post criticizing one of my functional designs from the 1990s, roifill. Now I have an update based on the R2015a release of Image Processing Toolbox.

Let me show you an example to refresh your memory about roifill.

I = imread('rice.png');
imshow(I)

You can use roifill to fill in pixels inside a region. (ROI in the function name stands for ''region of interest.'') You can specify the region interactively, using a mouse, or by providing the coordinates of a polygonal boundary, or by providing a binary mask. Here I'll provide the coordinates directly.

x = [47 50 71 83 81 66 53 48];
y = [102 110 110 103 92 92 97 102];

J = roifill(I,x,y);
imshow(J)

As I described in my earlier post, the form of roifill that takes a mask image suffered from a design flaw. Most people would reasonably assume that the mask image would specify the set of pixel values that are to be filled. And that's the way I should have designed it. Unfortunately, though, roifill actually only fills the interior pixels of the mask.

Suppose your fill mask looked like this:

The function roifill only replaces these interior pixels of the mask:

The pixels on the edge of the mask are used to establish boundary conditions for the fill equation. Those pixels stay the same, which is not what most people expect.

So how could we fix this problem? Changing the default behavior of roifill would be a significant incompatibility. But we have learned that optional behaviors often go undiscovered, so most people don't benefit from them.

The Image Processing Toolbox team decided to address the problem by introducing a new function, regionfill, with the desired behavior. The function roifill remains in the product, so existing code that uses it will continue to work. Presumably, anyone currently using roifill with the mask syntax has already worked around its awkward behavior.

At the bottom of the reference page for regionfill, there is a note that this function was introduced in R2015a.

And at the top of the reference page for roifill, there is a note encouraging the use of regionfill.




Published with MATLAB® R2015a

|
  • print
  • send email

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.