필터 지우기
필터 지우기

Create Small Neighborhood of image

조회 수: 2 (최근 30일)
Yohanes Setiawan
Yohanes Setiawan 2020년 2월 3일
댓글: Vinai Datta Thatiparthi 2020년 2월 21일
I want to make small neighborhood of every pixel x. The small neighborhood has center x (pixel x be the center) in radius w.
Suppose w=5, so I have 5x5 small neighborhood with pixel x is the center of neighborhood.
How can I make it?
Thank you.

채택된 답변

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2020년 2월 7일
Hello Yohanes,
val = imread(' ... '); % Your input matrix/image
[xCoOrd, yCoOrd] = [ ... ] % Co-Ordinates of the center pixel
nbh = 5; % Neighborhood Size
For a square neighborhood, the variable roi will hold the intensity values of neighboring pixels.
limit = floor(nbh/2);
roi = val(xCoOrd-limit:xCoOrd+limit, yCoOrd-limit:yCoOrd+limit);
Additionally, if you want the positions of the neighbors in subscripts,
rowLen = [xCoOrd - limit: xCoOrd + limit]'; % Range of Rows
colLen = [yCoOrd - limit: yCoOrd + limit]; % Range of Columns
rowIdx = meshgrid(rowLen, 1:nbh)'; % All the X coordinates of neighbors
colIdx = meshgrid(colLen, 1:nbh); % All the Y coordinates of neighbors
Hope this helps!
  댓글 수: 4
Yohanes Setiawan
Yohanes Setiawan 2020년 2월 12일
편집: Yohanes Setiawan 2020년 2월 12일
Halo,
Thank you very much. Your answer is really help me.
For the edge cases, how if I use this:
a=xCoOrd-limit;
b=xCoOrd+limit;
c=yCoOrd-limit;
d=yCoOrd+limit;
[row col]= size(val);
if a<1
a=1;
end
if b>row
b=row;
end
if c<1
c=1;
end
if d>col
d=col;
end
Is that logical correct (especially in the neighborhood concept of image processing) for computing neighbor of a pixel? Or we need the padding as you give me the link for solution?
Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2020년 2월 21일
Hey Yohanes,
Yes, this approach could work as well. Simple if-else statements checking for edge cases, and then assigning the neighbors (the ones that are beyond scope) NaN values.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by