0

Say we want to check the 4-neighbourhood in matlab, I think we can do the following (correct me if I'm wrong):

I = imread('cameraman.tif');
structured_element = [0,1,0;1,1,1;0,1,0];
o = imdilate(I,structured_element);

Now, I have the following statement that I'm trying to implement (have been trying for a while now):

among all pixels p " that belong to" Supp(F)\Ck
being 4-neighbours of Ck,
select the pixel p that minimizes the distance d(F,Ck"union"{p})
and let Cnew = Ck "union" {p}

I don't want to confuse you with some terms, but will give you values of them on which can be decided what to do.

Supp(F) has the values here.

Ck has the values here

F is an image shown here

Based on that, how can we implement the lines above?

Thanks a lot.

Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • You compressed the question so much to the point that important details were eliminated. "X has values here" is a bad way to present it, what if the values were calculated incorrectly (I didn't even open them, by the way) ? By `Supp` do you mean the support of the function `f` ? Being `f` a binary image, is support meant to include the points in the domain of `f` or only to those where it is stablished to belong to the foreground ? `Ck` is a complete mistery as it stands. Maybe all this were taken from some paper, and so could you include the title of this paper at least ? – mmgp Feb 20 '13 at 21:16
  • Anyway, the obvious way to implement the first two lines is by doing a dilation just like you did. Then consider only the border points on this dilated image and do a flood-fill in a breadth-first manner, when it first hits `f` you can determine which pixel `p` provides the minimal distance (note that multiple pixels might provide it). – mmgp Feb 20 '13 at 21:23
  • @mmgp. Thanks for your reply. For the first line for instance, I got the results for `p`. The point that confuses me is how to check that those `p` values are **4-neighbourhood** of `Ck`, especially that `Ck` is a set of values. But, I understood that what 4-neighbourhood means here is the neighborhood to any point in `Ck`. Can you kindly just demonstrate those two lines by a code? I'm really confused on how to combine them both – Simplicity Feb 20 '13 at 21:33
  • First I would like to know the site/paper from where this was taken from. – mmgp Feb 20 '13 at 21:41
  • @mmgp. Sure, it was taken from here: http://www.sciencedirect.com/science/article/pii/S026288561000123X – Simplicity Feb 20 '13 at 21:52
  • Ok, I have a problem with it. You are showing an image `F` that is binary, doesn't `Supp(F) == Core(F)` then ? I believe you can see how this breaks everything. – mmgp Feb 20 '13 at 22:07
  • @mmgp. The image is grayscale (0-255). And, Supp(F) is those elements with membership degrees ~= 1 and Core(F) are those = 1 – Simplicity Feb 20 '13 at 22:10
  • My problem is not with the definitions in the paper (also, according to the own paper, `Core(F)` is formed by the global maximum, not necessarily at 1). The problem is that your `F` is a binary image, not grayscale. – mmgp Feb 20 '13 at 22:12
  • @mmgp. Forgot to mention. `F` is a result of this algorithm: http://www.mathworks.com/matlabcentral/fileexchange/25532-fuzzy-c-means-segmentation – Simplicity Feb 20 '13 at 22:12
  • @mmgp. When I read the resulted image `F` I get that the pixel values' range [0-255]. This is then grayscale, isn't it? – Simplicity Feb 20 '13 at 22:16
  • @mmgp. Can you kindly contact me through my email? Just want to ask you about some issues here. Appreciate it! This is my email: `abder.rahman.ali@gmail.com`. Looking forward for your email... – Simplicity Feb 21 '13 at 11:21

1 Answers1

4

First, to clarity, you are working with a defuzzification algorithm described in the paper "Defuzzification of spatial fuzzy sets by feature distance minimization". The term Ck is initially built for k = 0 as:

Core(f) = {x is a member of a set X | m(x) >= m(y) for all y in X}

where f is some discrete grayscale 2D image, m(x) is defined as the membership function with range [0, 1], and X is formed by the pairs of points that belong to the domain of f. Then, Supp(f) is formed by those points where m(x) > 0. For a grayscale image f where 0 is black, this means anything that is not black is in the Supp(f).

So, here is an input f (which also represents Supp(f)), Core(f), and Supp(f)\Core(f) respectively. In Matlab terms, Core(f) is given by: core = f; core(f ~= max(max(f))) = 0;

enter image description here enter image description here enter image description here

Now we can solve the problems in the question. First: "... among all pixels p that belong to Supp(F)\Ck being 4-neighbours of Ck ..." can be translated as:

allp = imdilate(core, strel('diamond', 1)) - core;
allp_in_f = (allp/255) .* f;

supposing the input is of type uint8. The second statement discards points that are not in Supp(f) by setting them to 0, but in this example there are no such points. The result of this is step is shown in the following image:

enter image description here

Now: "... select the pixel p that minimizes the distance d(F,Ck union {p}) ...". At this moment, any pixel p in the last image minimizes it, supposing the metric is the L-infinity (Chebyshev, chessboard, ...) but even if we picked L-1 norm, all the pixels except the diagonal ones would satisfy it. Or, another interpretation (if we completely ignore the paper, since it wasn't mentioned in the question): the distance considers the intensities in f, and the method wants the one that minimizes the weighted (intensities) distance. In this case, and also for future iterations (the method is an iterative one, described in the paper), the simplest way is to perform a flood-fill from the boundary obtained in the last image shown. This flood-fill would be done in a breadth-first manner, so the first time a pixel touches f you would backtrack and determine the pixel p that minimized the distance. This method is also known as wave-front propagation.

mmgp
  • 18,901
  • 3
  • 53
  • 80
  • Thanks so much for your nice explanation. For ` Supp(F)\Ck`, I understand that it means the elements in `Supp(F)` but that are not in `Ck`. Is it correct that way? How does your lines of code translate to that? – Simplicity Feb 21 '13 at 11:17
  • I think you mean by: `imdilate(core, strel('diamond', 1))`, the `4-neighbours` of `Ck`? And `-core` that are in in `Ck`? Thanks – Simplicity Feb 21 '13 at 11:28
  • When I used your code, I got the error: `??? Error using ==> times Matrix dimensions must agree.` Why do you think that? For `f`, I used the image – Simplicity Feb 21 '13 at 11:41
  • I really meant what was said, your `imdilate` suggestion doesn't capture what the paper says since it wants the 4-neighbors of `Supp(F)\Ck`. The third image is showing `Supp(F)\Ck`, it is the set difference operation and the code for it isn't shown because I thought it wasn't needed ({1, 2, 3} \ {1, 2, 4} == {3}). I don't know what you did wrong, it works for me. Lastly, note that the distance used in the paper actually considers a set of features. – mmgp Feb 21 '13 at 13:03
  • I realized that `Ck` has to be binary, such that the pixels that belong to the core are for example set to `1`. what change can be made to the code to accommodate this? And, what does the `.*` notation mean? Thanks – Simplicity Feb 22 '13 at 02:52
  • Yes, `Ck` is binary already. Both in the example presented as well in the definition. – mmgp Feb 22 '13 at 02:54