Selecting that pixel that minimizes the distance

Say I have the following two matrices:
>> x = [1 4 3; 6 4 3; 6 9 3; 2 4 3; 5 4 0; 5 3 1; 6 4 7];
>> y = [0 0 1; 1 1 0; 1 1 0; 0 1 1; 0.2 0.8 0.54; 1 1 1; 0 0 0];
Where you can think of `x` as some image, and `y` as the *degree of membership* of each element of `x` to some region of interest.
Say I set those elements in `x` that have degree of membership = 1 to `1` (*core*) and the other elements to `0` as follows:
x = zeros(size(y));
x(y==1) = 1;
In which case I will have the following output:
0 0 1
1 1 0
1 1 0
0 1 1
0 0 0
1 1 1
0 0 0
Now, for the elements of `0`, I substitute their values with the value of `y` in the corresponding location as follows:
x(x==0)=y(x==0);
Now, I select those pixels that are considered `4-neighbours` of `core` but not in core as follows:
four_neighbourhood_pixels = imdilate(core, strel('diamond', 1)) - core;
My question is: *how can we select a pixel `p` that belongs to `four_neighbourhood_pixels` that minimizes the distance between `x` & `core`*?
Provided that for distance I calculate it as follows:
pdist([x,core],'minkowski');
Provided that `x` in the preceding command will be the matrix after substituting the `zeros` with the degree of membership values `y` i the corresponding location?
So, how can I select that pixel that belongs to ` four_neighbourhood_pixels` that minimizes the distance between `x` with the zeros substituted and `core`?
Thanks.

6 Comments

Not sure I follow everything. Remind me what the original x was used for. It looks like you just ignore it because you reassign x to be all zeros. Is that true?
@Image Analyst. Thanks for your reply. You can assume that `x` is some image. I actually don't ignore `x`, but based on the membership values `y` modify the values of its elements. Does that make sense?
No. If x is an image, then please explain what you are doing to x with this line:
x = zeros(size(y));
@Image Analyst. I used this line in order to set the elements of `x` that have a membership value of `1` to `1` and others to `0`. And, as a second step to set those zero valued elements to the value of their membership since I need the features for measutring the distance, where the membership value here represents the element's feature. For `x` then, not to confuse, let's say it is a simple matrix if you want...
But you totally destroy your original x image when you do that.
@Image Analyst. I'm currently trying this in theory and will see the effect afterwards. But, now just in need to know how to write a matlab code that selects that pixel belonging to the 4-neighbourhood of `core` that minimizes the distance. Any ideas on how this statement an be written? Thanks

Sign in to comment.

Answers (0)

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Asked:

on 23 Feb 2013

Community Treasure Hunt

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

Start Hunting!