Is there a way to find the neighbourhood pixels, given a cordinate point of the pixel?

I need to find out the neighbourhood pixel values, given a particular coordinate point in an image. the pixel point is user defined.

6 个评论

Is there any way so that the pixel point in one image is matches with the pixel point in another image for minimizing texture variation between two images.8 neighborhood pixel matching technique should be used for it.Those matched pixels will then used to calculate texture variation.I am new to matlab and dont understand how to obtained those matched pixels from two images.please help me any help will be appreciated.
hi image analyst,thank you for the tutorial,i have gone through that and found it a little helpful to me.
actually i need to find out texture variation between background and current image and for that i have to use 8 pixel iterative pyramid search for getting pixel matching between two images that minimize texture variation.
let 3*3 pyramid template is taken from one image and its center pixel i is assumed as [2,2],then nine positions are explored in each iteration and optimal position (which minimizes the texture variation among nine positions)will be one pixel point that matches with ith pixel and that would be considered for further iteration as center point. This is to be repeated for whole image and final obtained center point will be point point and will be matched point in another image. Sorry for the inconvenience caused.
please help me finding out this and then i have to apply formula for texture variation calculation.your help is much appreciated.
Sorry, I haven't worked at that task before, and I don't have any demos. I'd have to delve into it and learn it just as you would.
Ohh,well ok..i am still thankful to you for your help.If anyone find something related to the above problem please let me know it will be much helpful to me thanks.

请先登录,再进行评论。

 采纳的回答

neighbors(1) = img(r-1,c-1); % Upper left. r = row, c = column.
neighbors(2) = img(r-1,c); % Upper middle. r = row, c = column.
neighbors(3) = img(r-1,c+1); % Upper right. r = row, c = column.
neighbors(4) = img(r,c-1); % left. r = row, c = column.
neighbors(5) = img(r,c+1); % right. r = row, c = column.
neighbors(6) = img(r+1,c+1); % Lowerleft. r = row, c = column.
neighbors(7) = img(r+1,c); % lower middle. r = row, c = column.
neighbors(8) = img(r+1,c-1); % Lower left. r = row, c = column.
Order them in whatever order is convenient for you.

7 个评论

Hello; I'm having the same problem. What about if the coordinate are in the edge? If we use, for example, r+1 we got an Error :
matrix index exceed.
How to fix this ?
If you're on the bottom edge of the image, r+1 would go outside the image and that would be an error. You have to handle edge/boundary pixels separately. Such a pixel could have between 3 and 5 pixels, inclusive. You have to take care your indices don't go outside the image.
Hello
Is there any way to automate those neighbors(1) to neighbors(8)?
is there any kind of short way to do this?
This is so rudimentary and increase computation
The only other way I know is
neighbors = img(r-1:r+1, c-1:c+1); % Get 3x3 array.
neighbors(5) = []; % Delete the center pixel itself.
Of course if you just want to process the array somehow, unless you're doing something really unusual, you can just use imfilter(), nlfilter(), or blockproc(). Demoa attached. Using those you don't need to manually scan the image and get the neighbors yourself since it's handled by the function.
You should be able to do it any number of ways. This extracts the pixel and its neighbors:
inpict = randi([0 1],10);
pt = [5 5]; % row, col
imshow(inpict); hold on
plot(pt(2),pt(1),'yx','linewidth',2)
% find the sub-array
s = size(inpict);
idy = max(pt(1)-1,1):min(pt(1)+1,s(1));
idx = max(pt(2)-1,1):min(pt(2)+1,s(2));
nhood = inpict(idy,idx)
nhood = 3×3
0 0 1 0 1 1 1 1 0
Note that the output is truncated if the selected point is on the edge of the image.
It should be asked why this is being done. If this is part of a filter process, then edge handling wouldn't be done inside the loop. If the edge handling is done elsewhere and the neighborhood is guaranteed to be 3x3, then this can be simplified:
% another way
s = size(inpict);
idx = pt.' + [-1 0 1];
nhood = inpict(idx(1,:),idx(2,:))
nhood = 3×3
0 0 1 0 1 1 1 1 0
% or if only the neighbors are needed
nhood = nhood([1:4 6:9])
nhood = 1×8
0 0 1 0 1 1 1 0

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by