Create Small Neighborhood of image
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yohanes Setiawan
am 3 Feb. 2020
Kommentiert: Vinai Datta Thatiparthi
am 21 Feb. 2020
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.
0 Kommentare
Akzeptierte Antwort
Vinai Datta Thatiparthi
am 7 Feb. 2020
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 Kommentare
Yohanes Setiawan
am 12 Feb. 2020
Bearbeitet: Yohanes Setiawan
am 12 Feb. 2020
Vinai Datta Thatiparthi
am 21 Feb. 2020
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Explore and Edit Images with Image Viewer App finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!