Info

This question is closed. Reopen it to edit or answer.

Finding the pixel that minimizes the distance between two sets

2 views (last 30 days)
I have a statement trying to implement but confused on how to do so. This is my issue:
- I have an image where I have set some pixels of interest (region of interest) to the value `1`. So, we can say that we now have a set with the following values `1s` where each `1` here represents a particular location in the image.
> C = [1 1 1 1 1 1 1 1 1 1];
For example, say `img` for simplicity here is the matrix `x` as follows:
x = [2 3 5; 5 4 5; 6 4 3; 6 5 4; 6 54 3; 6 5 3];
`x` will have a degree of membership `y` based on which we set some values to `1`. To clarify, for each pixel for which `y` = `1` we set that pixel to `1`. So, let's say `y` is:
y = [0 1 0; 0 1 1; 1 1 0; 0 0 1; 0 0 1; 1 1 1];
So, `C` contains 10 `1s`. For instance the first `1` represents the location `x(1,2)` and so forth...
- Now, I want to check the `4-neighbourhoods` of the pixels in `C` but that at the same time not in `C`. That is, on the surroundings.
- Now, for those pixels that belong to the surroundings and are four neighbors of `C` I want to select that pixel `p` that *minimizes the distance* between `x` and `C`.
Is it clear now? Do you know how I can go around it?
Thanks.

Answers (1)

Image Analyst
Image Analyst on 23 Feb 2013
You say "for each pixel for which `y` = `1` we set that pixel to `1`" So you'd do
x(y) = 1;
Next you say "Now, for those pixels that belong to the surroundings and are four neighbors of `C`" Well, C does not have any neighborhoods. The way you defined it, it's just a vector of all 1's of various lengths (depending on how many 1's are in y), so C is pretty much useless since it doesn't retain any location information, and I don't even know why you created it. y has everything you need and in a much more useful form.
Then you say "...are four neighbors of `C`..." - No, there are not. There are not four neighbors of C, just two, and for those two there is no indication of what two pixels in x they refer to.
Finally you say " I want to select that pixel `p` that minimizes the distance between `x` and `C`. Is it clear now?" Sorry, but no, it is not clear now. Perhaps if you uploaded an image and said what you wanted to segment out or measure in the image it would help illustrate your situation better.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!