How to select a pixel and get its surrounding eight neighbors using nearest neighbor?

조회 수: 2 (최근 30일)
How to select a pixel and get its surrounding eight neighbors using nearest neighbor?
The input image is as follows:

답변 (1개)

Image Analyst
Image Analyst 2016년 4월 27일
use ginput to get the coordinate:
[x, y] = ginput(1);
row = round(y);
col = round(x);
neighbors = [grayImage(row-1, col-1);...
grayImage(row-1, col-1);...
grayImage(row-1, col);...
grayImage(row-1, col+1);...
grayImage(row, col-1);...
grayImage(row, col+1);...
grayImage(row+1, col-1);...
grayImage(row+1, col);...
grayImage(row+1, col+1)];
You can put them in whatever order you find convenient.
  댓글 수: 2
Jannie Sy
Jannie Sy 2016년 4월 28일
Thanks ImageAnalyst.
After obtaining its 8 neighbors, how do I subject these to voting? I should test the chosen pixel by assigning to a specific class if that class gets four or more votes. Otherwise, the pixel will maintain its class.
Image Analyst
Image Analyst 2016년 4월 29일
편집: Image Analyst 2016년 4월 29일
I have no idea. Evidently you've read some paper that says you're supposed to get "votes" from neighboring pixels, but we have no knowledge of that paper obviously, or how it determines "votes". You don't even have a classified image at this point - it's just a simple gray scale image, not one with "classes" where each pixel is classified into one class like "road", "house", "ground", "vehicle", "water", or whatever.

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

Community Treasure Hunt

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

Start Hunting!

Translated by