finding neighbours around central rows and columns
Afficher commentaires plus anciens
Hi,
I was wondering if some can help me regarding the row-column looping.
I have my row, col positions as [row,col]. e.g. array 300X2
I am trying to find their 8 neighbour values as:
neighbors_id= [matrix_cell_id(row, col),...
matrix_cell_id(row-1, col-1),...
matrix_cell_id(row-1, col),...
matrix_cell_id(row-1, col+1),...
matrix_cell_id(row, col-1),...
matrix_cell_id(row, col+1),...
matrix_cell_id(row+1, col-1),...
matrix_cell_id(row+1, col),...
matrix_cell_id(row+1, col+1)];
however when I run this code I get multiple values (matrix 300*2700) instead of 300row x 9 columns (corresponding to those neighbors) array.
Any clue is more than welcome,
Thanks a lot,
2 commentaires
Sajid Rahim
le 16 Oct 2017
clear all;
[filename pathname]=uigetfile('*.jpg;*.png;*.tif;*.tiff;*.gif;*.bmp;');
inputimage=imread([pathname filename]);
I=inputimage;
% I = imread('5.png') ;
I = rgb2gray(I) ;
[y,x] = find(I) ;
figure imshow(I)
hold on
plot(x,y,'.b') % x
% y
% z=(y+x)/2
% plot(z,'.r')
a=x(1)
b=y(1)
plot(x(1),y(1),'*y')
plot(x(end),y(end),'*y')
% neighbors(1) = (a,b-1);
neighbors(1) = I(a,b-1);
plot(a,b-1,'*r')
neighbors(2) = I(a,b+1); plot(a,b+1,'*r')
neighbors(3) = I(a,b+2);
plot(a,b+2,'*r') neighbors(4) = I(a+1,b);
plot(a+1,b,'*r')
neighbors(5) = I(a+1,b+1);
plot(a+1,b+1,'*r')
neighbors(6) = I(a+2,b+2);
plot(a+2,b+2,'*r')
neighbors(7) = I(a+2,b);
plot(a+2,b,'*r')
neighbors(8) = I(a+2,b+1);
plot(a+2,b+1,'*r')
neighbors(9) = I(a+2,b+2);
plot(a+2,b+2,'*r')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Nearest Neighbors dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!